Skip to content

Commit f0c66cd

Browse files
authored
[Docs] Improve telemetry docs (#1681)
1 parent 3040bfa commit f0c66cd

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

docs/advanced/resilience-context.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ finally
102102
}
103103
```
104104
<!-- endSnippet -->
105+
106+
> [!NOTE]
107+
> The `OperationKey` values are reported in [telemetry](telemetry.md#metrics). Beware of using very large or unbounded combinations for the operation key. See [best practices](https://learn.microsoft.com/dotnet/core/diagnostics/metrics-instrumentation#best-practices-3) for more details.

docs/advanced/telemetry.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ Every telemetry event has the following tags:
8282
- `pipeline.name`: Optional, comes from `ResiliencePipelineBuilder.Name`.
8383
- `pipeline.instance`: Optional, comes from `ResiliencePipelineBuilder.InstanceName`.
8484
- `strategy.name`: Optional, comes from `RetryStrategyOptions.Name`.
85+
- `operation.key`: Optional, comes from `ResilienceContext.OperationKey`.
8586

8687
The sample below demonstrates how to assign these tags:
8788

88-
<!-- snippet: telemetry-coordinates -->
89+
<!-- snippet: telemetry-tags -->
8990
```cs
9091
var builder = new ResiliencePipelineBuilder();
9192
builder.Name = "my-name";
@@ -96,9 +97,25 @@ builder.AddRetry(new RetryStrategyOptions
9697
// The default value is "Retry"
9798
Name = "my-retry-name"
9899
});
100+
101+
ResiliencePipeline pipeline = builder.Build();
102+
103+
// Create resilience context with operation key
104+
ResilienceContext resilienceContext = ResilienceContextPool.Shared.Get("my-operation-key");
105+
106+
// Execute the pipeline with the context
107+
pipeline.Execute(
108+
context =>
109+
{
110+
// Your code comes here
111+
},
112+
resilienceContext);
99113
```
100114
<!-- endSnippet -->
101115

116+
> [!NOTE]
117+
> Beware of using very large or unbounded combinations of tag values for the tags above. See [best practices](https://learn.microsoft.com/dotnet/core/diagnostics/metrics-instrumentation#best-practices-3) for more details.
118+
102119
These values are subsequently reflected in the following metering instruments exposed by Polly:
103120

104121
### Instrument: `resilience.polly.strategy.events`

src/Snippets/Docs/Telemetry.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class Telemetry
99
{
1010
public static void TelemetryCoordinates()
1111
{
12-
#region telemetry-coordinates
12+
#region telemetry-tags
1313

1414
var builder = new ResiliencePipelineBuilder();
1515
builder.Name = "my-name";
@@ -21,6 +21,19 @@ public static void TelemetryCoordinates()
2121
Name = "my-retry-name"
2222
});
2323

24+
ResiliencePipeline pipeline = builder.Build();
25+
26+
// Create resilience context with operation key
27+
ResilienceContext resilienceContext = ResilienceContextPool.Shared.Get("my-operation-key");
28+
29+
// Execute the pipeline with the context
30+
pipeline.Execute(
31+
context =>
32+
{
33+
// Your code comes here
34+
},
35+
resilienceContext);
36+
2437
#endregion
2538
}
2639

0 commit comments

Comments
 (0)