Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Unify strategy descriptions and add Telemetry sections #2060

Merged
merged 30 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26f75ea
Unify Timeout, Retry
peter-csala Apr 15, 2024
40bf86f
Merge branch 'App-vNext:main' into unify-strategy-descriptions
peter-csala Apr 15, 2024
547553e
Add runtime to the wordlist
peter-csala Apr 15, 2024
950a84c
Fix heading
peter-csala Apr 15, 2024
fa7b6ba
Apply suggestions from code review
peter-csala Apr 15, 2024
8f6cbc5
Apply suggestions
peter-csala Apr 15, 2024
4c46442
Unify Fallback
peter-csala Apr 16, 2024
ac1a2bb
Unify Hedging
peter-csala Apr 16, 2024
44b9937
Fix linting issue related to italic usage
peter-csala Apr 16, 2024
fe6f713
Unify Rate limiter
peter-csala Apr 17, 2024
5ffd9c8
Apply suggestions from code review
peter-csala Apr 17, 2024
1a2452a
Use note instead of important
peter-csala Apr 17, 2024
661b8d5
Unify Circuit Breaker
peter-csala Apr 17, 2024
67e8331
Fix table formatting
peter-csala Apr 17, 2024
1b2d1d5
Apply suggestions from code review
peter-csala Apr 17, 2024
a046c8f
Fix table format
peter-csala Apr 17, 2024
94ee246
Add telemetry section to timeout
peter-csala Apr 18, 2024
3b9cab6
Remove unused variable
peter-csala Apr 18, 2024
e64edad
Add telemetry section to retry
peter-csala Apr 18, 2024
ccae18c
Update docs/strategies/timeout.md
peter-csala Apr 18, 2024
6a9a59f
Add telemetry section to fallback
peter-csala Apr 18, 2024
1a40202
Update docs/strategies/retry.md
peter-csala Apr 18, 2024
d81f3e4
Fix note section for fallback telemetry
peter-csala Apr 18, 2024
552a0e2
Add telemetry to rate limiter
peter-csala Apr 19, 2024
d6e1334
Add telemetry section to hedging
peter-csala Apr 19, 2024
eed98a8
Remove extra whitespace
peter-csala Apr 19, 2024
20fe470
Add telemetry section to circuit breaker
peter-csala Apr 19, 2024
6f10f8d
Fix cb telemetry events' severity
peter-csala Apr 19, 2024
fc494c3
Apply suggestions from code review
peter-csala Apr 22, 2024
899a5c4
Apply suggested changes
peter-csala Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/strategies/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,65 @@ new ResiliencePipelineBuilder<HttpResponseMessage>().AddRetry(optionsExtractDela
| `DelayGenerator` | `null` | This optional delegate allows you to **dynamically** calculate the retry delay by utilizing information that is only available at runtime (like the attempt number). |
| `OnRetry` | `null` | If provided then it will be invoked before the strategy delays the next attempt. |

## Telemetry

The retry strategy reports the following telemetry events:

| Event Name | Event Severity | When? |
|---------------------|---------------------------|-------------------------------------------------------|
| `Execution Attempt` | `Information` / `Warning` | Just before the strategy calculates the next delay |
| `OnRetry` | `Warning` | Just before the strategy calls the `OnRetry` delegate |

Here are some sample events:

### Unhandled case

If the retry strategy does not perform any retries then the reported telemetry events' severity will be `Information`:

```none
Execution attempt. Source: 'MyApplication/MyTestPipeline/MyRetryStrategy', Operation Key: 'MyRetryableOperation', Result: '1', Handled: 'False', Attempt: '0', Execution Time: '110.952'

Execution attempt. Source: 'MyApplication/MyTestPipeline/MyRetryStrategy', Operation Key: 'MyRetryableOperation', Result: 'Failed', Handled: 'False', Attempt: '0', Execution Time: '5.2194'
System.Exception: Failed
at Program.<>c.<Main>b__0_1(ResilienceContext ctx)
...
at Polly.ResiliencePipeline.<>c.<<ExecuteAsync>b__1_0>d.MoveNext() in /_/src/Polly.Core/ResiliencePipeline.Async.cs:line 67
```

### Handled case

If the retry strategy performs some retries then the reported telemetry events' severity will be `Warning`:

```none
Execution attempt. Source: 'MyApplication/MyTestPipeline/MyRetryStrategy', Operation Key: 'MyRetryableOperation', Result: 'Failed', Handled: 'True', Attempt: '0', Execution Time: '5.0397'
System.Exception: Failed
at Program.<>c.<Main>b__0_1(ResilienceContext ctx)
...
at Polly.ResiliencePipeline.<>c.<<ExecuteAsync>b__1_0>d.MoveNext() in /_/src/Polly.Core/ResiliencePipeline.Async.cs:line 67

Resilience event occurred. EventName: 'OnRetry', Source: 'MyApplication/MyTestPipeline/MyRetryStrategy', Operation Key: 'MyRetryableOperation', Result: 'Failed'
System.Exception: Failed
at Program.<>c.<Main>b__0_1(ResilienceContext ctx)
...
at Polly.ResiliencePipeline.<>c.<<ExecuteAsync>b__1_0>d.MoveNext() in /_/src/Polly.Core/ResiliencePipeline.Async.cs:line 67


Execution attempt. Source: 'MyApplication/MyTestPipeline/MyRetryStrategy', Operation Key: 'MyRetryableOperation', Result: 'Failed', Handled: 'True', Attempt: '1', Execution Time: '0.1159'
System.Exception: Failed
at Program.<>c.<Main>b__0_1(ResilienceContext ctx)
...
at Polly.ResiliencePipeline.<>c.<<ExecuteAsync>b__1_0>d.MoveNext() in /_/src/Polly.Core/ResiliencePipeline.Async.cs:line 67
```

> [!NOTE]
> Please note that the `OnRetry` telemetry event will be reported **only if** the retry strategy performs any retry attempts.
>
> On the other hand the `Execution attempt` event will be **always** reported regardless whether the strategy has to perform any retries.
>
> Also remember that the `Attempt: '0'` means the original attempt.

For further information please check out the [telemetry page](../advanced/telemetry.html).

## Calculation of the next delay

If the `ShouldHandle` predicate returns `true` and the next attempt number is not greater than `MaxRetryAttempts` then the retry strategy calculates the next delay.
Expand Down
2 changes: 1 addition & 1 deletion docs/strategies/timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Resilience event occurred. EventName: 'OnTimeout', Source: 'MyApplication/MyTest
> [!NOTE]
> Please note that the `OnTimeout` telemetry event will be reported **only if** the timeout strategy cancels the provided callback execution.
>
> So, if the callback either finishes on time or throws an exception then there will be no telemetry log.
> So, if the callback either finishes on time or throws an exception then there will be no telemetry emitted.
>
> Also remember that the `Result` will be **always** empty for the `OnTimeout` telemetry event.

Expand Down