Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Attempt count to PolicyResult [general: expand info on Policy execution available in PolicyResult]

See original GitHub issue

We are using ExecuteAndCapture in our application, the policy is defined in configuration but executed elsewhere. I’d like to log whether a retry has happened (and how many) but all I have is PolicyResult to work from.

In one part of the app, we define a function which builds a policy:

config.BuildExceptionPolicy(() => Policy.Handle<IOxception>().RetryAsync(2));

And execute it in another:

var policy = step.BuildExceptionPolicy();
return policy.ExecuteAndCaptureAsync(async () => { ... } );

If the outcome is Failure, I log the final exception but along side that I’d like to log the number of attempts that were taken.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

reisenbergercommented, Jan 7, 2016

Hi @TrevorPilley.

Because of the way the Polly execute methods are generalised, capturing the number of attempts into the PolicyResult is not that straightforward. .ExecuteAndCaptureAsync(...) is agnostic to (and has no knowledge of) whether what is being run underneath is a retry policy, circuit-breaker policy without retries (or indeed some new kind of action-transforming policy in the future).

An approach in the meantime could be something like :

int attempts = 0;
var policy = step.BuildExceptionPolicy();
var result = policy.ExecuteAndCaptureAsync(async () => { 
   //  ... 
} );

@joelhulen : I suggest we leave this issue open for a while so that others can comment if they would also like additional execution metadata inPolicyResult.

rvvincellicommented, Dec 8, 2020

I think the proper way to do this now is with a context.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Polly timeout policy clarification
When I analyze the policy result how do I understand if the timeout ... its timing-out CancellationToken into ct, during policy execution.
Read more >
A YANG Data Model for Routing Policy RFC 9067
A YANG Data Model for Routing Policy (RFC 9067, October 2021)
Read more >
K35932460: Troubleshooting | BIG-IP APM operations guide
Go to System > Logs > Configuration > Options > Access Policy. In Access Policy Logging, for Access Policy,SSO, Portal Access, and VDI,...
Read more >
Pega Platform 8.7.4 Patch Resolved Issues
When attempting to migrate the rules schema to RULES85 and temp data schema DATA85, the upgrade was becoming stuck in a loop while...
Read more >
Aruba ClearPass Policy Manager User Guide
Adding a Static Host List as an Authentication Source ... The ClearPass Policy Manager 6.6 User Guide provides a general overview of ClearPass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found