Starting with version 8, Polly provides telemetry for all built-in standard and chaos resilience strategies.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/App-vNext/Polly/llms.txt
Use this file to discover all available pages before exploring further.
Installation
To enable telemetry in Polly, add thePolly.Extensions package to your project:
Basic Usage
Afterwards, you can use theConfigureTelemetry(...) extension method on the ResiliencePipelineBuilder:
MyTelemetryListener and MyMeteringEnricher is implemented as:
AddResiliencePipeline(...) extension method which automatically enables telemetry for defined pipeline:
Metrics
The metrics are emitted under thePolly meter name. The subsequent sections provide insights into the metrics produced by Polly. Please note that any custom enriched tags are not depicted in the following tables.
Every telemetry event has the following optional tags:
pipeline.name: comes fromResiliencePipelineBuilder.Name.pipeline.instance: comes fromResiliencePipelineBuilder.InstanceName.strategy.name: comes fromRetryStrategyOptions.Name.operation.key: comes fromResilienceContext.OperationKey.
Instrument: resilience.polly.strategy.events
- Type: Counter
- Numerical type: int
- Description: Emitted upon the occurrence of a resilience event.
Tags
| Name | Description |
|---|---|
event.name | The name of the emitted event. |
event.severity | The severity of the event (Debug, Information, Warning, Error, Critical). |
pipeline.name | The name of the pipeline corresponding to the resilience pipeline. |
pipeline.instance | The instance name of the pipeline corresponding to the resilience pipeline. |
strategy.name | The name of the strategy generating this event. |
operation.key | The operation key associated with the call site. |
exception.type | The full name of the exception assigned to the execution result (System.InvalidOperationException). |
Event Names
Theevent.name tag is reported by individual resilience strategies. The built-in strategies report the following events:
OnRetry
Retry strategy events
OnFallback
Fallback strategy events
OnHedging
Hedging strategy events
OnTimeout
Timeout strategy events
Circuit Breaker
OnCircuitClosed, OnCircuitOpened, OnCircuitHalfOpened
OnRateLimiterRejected
Rate limiter strategy events
Instrument: resilience.polly.strategy.attempt.duration
- Type: Histogram
- Unit: milliseconds
- Numerical type: double
- Description: Tracks the duration of execution attempts, produced by
RetryandHedgingresilience strategies.
Tags
| Name | Description |
|---|---|
event.name | The name of the emitted event. Currently, the event name is always ExecutionAttempt. |
event.severity | The severity of the event (Debug, Information, Warning, Error, Critical). |
pipeline.name | The name of the pipeline corresponding to the resilience pipeline. |
pipeline.instance | The instance name of the pipeline corresponding to the resilience pipeline. |
strategy.name | The name of the strategy generating this event. |
operation.key | The operation key associated with the call site. |
exception.type | The full name of the exception assigned to the execution result (System.InvalidOperationException). |
attempt.number | The execution attempt number, starting at 0 (0, 1, 2, etc.). |
attempt.handled | Indicates if the execution outcome was handled. A handled outcome indicates execution failure and the need for retry (true, false). |
Instrument: resilience.polly.pipeline.duration
- Type: Histogram
- Unit: milliseconds
- Numerical type: double
- Description: Measures the duration of resilience pipelines.
Tags
| Name | Description |
|---|---|
pipeline.name | The name of the pipeline corresponding to the resilience pipeline. |
pipeline.instance | The instance name of the pipeline corresponding to the resilience pipeline. |
operation.key | The operation key associated with the call site. |
exception.type | The full name of the exception assigned to the execution result (System.InvalidOperationException). |
Metering Enrichment
Polly API lets you add extra tags to any resilience event created by resilience strategies. To do this, derive from theMeteringEnricher class and add your custom enricher to the TelemetryOptions.MeteringEnrichers list.
The custom enricher:
Logs
Logs are registered under thePolly logger name. Here are some examples of the logs:
Emitting Telemetry Events
Each resilience strategy can generate telemetry data through theResilienceStrategyTelemetry API. Polly encapsulates event details as TelemetryEventArguments and emits them via TelemetryListener.
To leverage this telemetry data, users should assign a TelemetryListener instance to ResiliencePipelineBuilder.TelemetryListener and then consume the TelemetryEventArguments.
For common scenarios, it is expected that users would make use of Polly.Extensions. This extension enables telemetry configuration through the ResiliencePipelineBuilder.ConfigureTelemetry(...) method, which processes TelemetryEventArguments to generate logs and metrics.
Customizing Event Severity
To customize the severity of telemetry events, set theSeverityProvider delegate that allows changing the default severity of resilience events:
PipelineExecuting: by default reported atDebuglevelPipelineExecuted: by default reported atInformationlevel
SeverityProvider to override strategy specific telemetry events’ severity.