Skip to main content
Starting with version 8, Polly provides telemetry for all built-in standard and chaos resilience strategies.

Installation

To enable telemetry in Polly, add the Polly.Extensions package to your project:

Basic Usage

Afterwards, you can use the ConfigureTelemetry(...) extension method on the ResiliencePipelineBuilder:
The MyTelemetryListener and MyMeteringEnricher is implemented as:
Alternatively, you can use the AddResiliencePipeline(...) extension method which automatically enables telemetry for defined pipeline:

Metrics

The metrics are emitted under the Polly 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 from ResiliencePipelineBuilder.Name.
  • pipeline.instance: comes from ResiliencePipelineBuilder.InstanceName.
  • strategy.name: comes from RetryStrategyOptions.Name.
  • operation.key: comes from ResilienceContext.OperationKey.
The sample below demonstrates how to assign these tags:
Beware of using very large or unbounded combinations of tag values for the tags above. See best practices for more details.
These values are subsequently reflected in the following metering instruments exposed by Polly:

Instrument: resilience.polly.strategy.events

  • Type: Counter
  • Numerical type: int
  • Description: Emitted upon the occurrence of a resilience event.

Tags

Event Names

The event.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 Retry and Hedging resilience strategies.

Tags

Instrument: resilience.polly.pipeline.duration

  • Type: Histogram
  • Unit: milliseconds
  • Numerical type: double
  • Description: Measures the duration of resilience pipelines.

Tags

Metering Enrichment

Polly API lets you add extra tags to any resilience event created by resilience strategies. To do this, derive from the MeteringEnricher class and add your custom enricher to the TelemetryOptions.MeteringEnrichers list. The custom enricher:
Registering the custom enricher:

Logs

Logs are registered under the Polly logger name. Here are some examples of the logs:

Emitting Telemetry Events

Each resilience strategy can generate telemetry data through the ResilienceStrategyTelemetry 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 the SeverityProvider delegate that allows changing the default severity of resilience events:
There are telemetry events which are specific to strategies. Like the above overrides are specific to Retry (and partially to Hedging).
If you want to define X severity for the ExecutionAttempt event of Retry and Y severity for the ExecutionAttempt event of Hedging then use the args.Source.StrategyName information as well inside the switch expression.
There are also pipeline specific telemetry events:
  • PipelineExecuting: by default reported at Debug level
  • PipelineExecuted: by default reported at Information level
In general the suggestion is to use SeverityProvider to override strategy specific telemetry events’ severity.
If you want to suppress the specific event completely then use ResilienceEventSeverity.None.