Skip to content

Commit

Permalink
[Docs] Improve telemetry docs (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk authored Oct 6, 2023
1 parent 3040bfa commit f0c66cd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/advanced/resilience-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ finally
}
```
<!-- endSnippet -->

> [!NOTE]
> 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.
19 changes: 18 additions & 1 deletion docs/advanced/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ Every telemetry event has the following tags:
- `pipeline.name`: Optional, comes from `ResiliencePipelineBuilder.Name`.
- `pipeline.instance`: Optional, comes from `ResiliencePipelineBuilder.InstanceName`.
- `strategy.name`: Optional, comes from `RetryStrategyOptions.Name`.
- `operation.key`: Optional, comes from `ResilienceContext.OperationKey`.

The sample below demonstrates how to assign these tags:

<!-- snippet: telemetry-coordinates -->
<!-- snippet: telemetry-tags -->
```cs
var builder = new ResiliencePipelineBuilder();
builder.Name = "my-name";
Expand All @@ -96,9 +97,25 @@ builder.AddRetry(new RetryStrategyOptions
// The default value is "Retry"
Name = "my-retry-name"
});

ResiliencePipeline pipeline = builder.Build();

// Create resilience context with operation key
ResilienceContext resilienceContext = ResilienceContextPool.Shared.Get("my-operation-key");

// Execute the pipeline with the context
pipeline.Execute(
context =>
{
// Your code comes here
},
resilienceContext);
```
<!-- endSnippet -->

> [!NOTE]
> 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.
These values are subsequently reflected in the following metering instruments exposed by Polly:

### Instrument: `resilience.polly.strategy.events`
Expand Down
15 changes: 14 additions & 1 deletion src/Snippets/Docs/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class Telemetry
{
public static void TelemetryCoordinates()
{
#region telemetry-coordinates
#region telemetry-tags

var builder = new ResiliencePipelineBuilder();
builder.Name = "my-name";
Expand All @@ -21,6 +21,19 @@ public static void TelemetryCoordinates()
Name = "my-retry-name"
});

ResiliencePipeline pipeline = builder.Build();

// Create resilience context with operation key
ResilienceContext resilienceContext = ResilienceContextPool.Shared.Get("my-operation-key");

// Execute the pipeline with the context
pipeline.Execute(
context =>
{
// Your code comes here
},
resilienceContext);

#endregion
}

Expand Down

0 comments on commit f0c66cd

Please sign in to comment.