Skip to content

Commit

Permalink
Allign the telemetry tags with official guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Sep 13, 2023
1 parent 6e69ec3 commit baf39f5
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 105 deletions.
54 changes: 27 additions & 27 deletions docs/advanced/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ The metrics are emitted under the `Polly` meter name. The subsequent sections pr

Every telemetry event has the following dimensions:

- `pipeline-name`: Optional, comes from `ResiliencePipelineBuilder.Name`.
- `pipeline-instance`: Optional, comes from `ResiliencePipelineBuilder.InstanceName`.
- `strategy-name`: Optional, comes from `RetryStrategyOptions.Name`.
- `pipeline_name`: Optional, comes from `ResiliencePipelineBuilder.Name`.
- `pipeline_instance`: Optional, comes from `ResiliencePipelineBuilder.InstanceName`.
- `strategy_name`: Optional, comes from `RetryStrategyOptions.Name`.

The sample below demonstrates how to assign these dimensions:

Expand All @@ -101,7 +101,7 @@ builder.AddRetry(new RetryStrategyOptions

These values are subsequently reflected in the metrics below:

### resilience-events
### Instrument: `polly.resilience_events`

- Type: *Counter*
- Description: Emitted upon the occurrence of a resilience event.
Expand All @@ -110,15 +110,15 @@ Dimensions:

|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-name`| The full name of the exception assigned to the execution result (`System.InvalidOperationException`). |
|`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_name`| The full name of the exception assigned to the execution result (`System.InvalidOperationException`). |

### execution-attempt-duration
### Instrument: `polly.execution_attempt_duration`

- Type: *Histogram*
- Unit: *milliseconds*
Expand All @@ -128,17 +128,17 @@ Dimensions:

|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-name`| 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`). |

### pipeline-execution-duration
|`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_name`| 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: polly.pipeline_execution_duration

- Type: *Histogram*
- Unit: *milliseconds*
Expand All @@ -148,10 +148,10 @@ Dimensions:

|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-name`| The full name of the exception assigned to the execution result (`System.InvalidOperationException`). |
|`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_name`| The full name of the exception assigned to the execution result (`System.InvalidOperationException`). |

## Logs

Expand Down
18 changes: 9 additions & 9 deletions src/Polly.Extensions/Telemetry/ResilienceTelemetryTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ namespace Polly.Telemetry;

internal class ResilienceTelemetryTags
{
public const string EventName = "event-name";
public const string EventName = "event_name";

public const string EventSeverity = "event-severity";
public const string EventSeverity = "event_severity";

public const string PipelineName = "pipeline-name";
public const string PipelineName = "pipeline_name";

public const string PipelineInstance = "pipeline-instance";
public const string PipelineInstance = "pipeline_instance";

public const string StrategyName = "strategy-name";
public const string StrategyName = "strategy_name";

public const string OperationKey = "operation-key";
public const string OperationKey = "operation_key";

public const string ExceptionName = "exception-name";
public const string ExceptionName = "exception_name";

public const string AttemptNumber = "attempt-number";
public const string AttemptNumber = "attempt_number";

public const string AttemptHandled = "attempt-handled";
public const string AttemptHandled = "attempt_handled";
}
6 changes: 3 additions & 3 deletions src/Polly.Extensions/Telemetry/TelemetryListenerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public TelemetryListenerImpl(TelemetryOptions options)
_listeners = options.TelemetryListeners.ToList();

Counter = Meter.CreateCounter<int>(
"resilience-events",
"polly.resilience_events",
description: "Tracks the number of resilience events that occurred in resilience strategies.");

AttemptDuration = Meter.CreateHistogram<double>(
"execution-attempt-duration",
"polly.execution_attempt_duration",
unit: "ms",
description: "Tracks the duration of execution attempts.");

ExecutionDuration = Meter.CreateHistogram<double>(
"pipeline-execution-duration",
"polly.pipeline_execution_duration",
unit: "ms",
description: "The execution duration of resilience pipelines.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Snippets/Docs/ResilienceContextUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public static async Task Pooling()
try
{
// Retrieve a context with a specific operation key
context = ResilienceContextPool.Shared.Get("my-operation-key", cancellationToken);
context = ResilienceContextPool.Shared.Get("my-operation_key", cancellationToken);

// Retrieve a context with multiple properties
context = ResilienceContextPool.Shared.Get(
operationKey: "my-operation-key",
operationKey: "my-operation_key",
continueOnCapturedContext: true,
cancellationToken: cancellationToken);

Expand Down
8 changes: 4 additions & 4 deletions test/Polly.Core.Tests/ResiliencePipelineBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,27 +326,27 @@ public void Build_EnsureCorrectContext()
context =>
{
context.Telemetry.TelemetrySource.PipelineName.Should().Be("builder-name");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy-name");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy_name");
context.Telemetry.Should().NotBeNull();
context.TimeProvider.Should().Be(builder.TimeProvider);
verified1 = true;
return new TestResilienceStrategy();
},
new TestResilienceStrategyOptions { Name = "strategy-name" });
new TestResilienceStrategyOptions { Name = "strategy_name" });

builder.AddStrategy(
context =>
{
context.Telemetry.TelemetrySource.PipelineName.Should().Be("builder-name");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy-name-2");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy_name-2");
context.Telemetry.Should().NotBeNull();
context.TimeProvider.Should().Be(builder.TimeProvider);
verified2 = true;
return new TestResilienceStrategy();
},
new TestResilienceStrategyOptions { Name = "strategy-name-2" });
new TestResilienceStrategyOptions { Name = "strategy_name-2" });

// act
builder.Build();
Expand Down
6 changes: 3 additions & 3 deletions test/Polly.Core.Tests/StrategyBuilderContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public void Ctor_EnsureDefaults()
{
var timeProvider = new FakeTimeProvider();
var context = new StrategyBuilderContext(
new ResilienceStrategyTelemetry(new ResilienceTelemetrySource("builder-name", "instance", "strategy-name"),
new ResilienceStrategyTelemetry(new ResilienceTelemetrySource("builder-name", "instance", "strategy_name"),
Substitute.For<TelemetryListener>()), timeProvider);

context.Telemetry.TelemetrySource.PipelineName.Should().Be("builder-name");
context.Telemetry.TelemetrySource.PipelineInstanceName.Should().Be("instance");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy-name");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy_name");
context.TimeProvider.Should().Be(timeProvider);
context.Telemetry.Should().NotBeNull();

context.Telemetry.TelemetrySource.PipelineName.Should().Be("builder-name");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy-name");
context.Telemetry.TelemetrySource.StrategyName.Should().Be("strategy_name");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ResilienceStrategyTelemetryTests()
_source = new ResilienceTelemetrySource(
"builder",
"instance",
"strategy-name");
"strategy_name");

_sut = TestUtilities.CreateResilienceTelemetry(args => _args.Add(args));
}
Expand All @@ -35,7 +35,7 @@ public void Report_NoOutcome_OK()
args.Event.EventName.Should().Be("dummy-event");
args.Event.Severity.Should().Be(ResilienceEventSeverity.Warning);
args.Outcome.Should().BeNull();
args.Source.StrategyName.Should().Be("strategy-name");
args.Source.StrategyName.Should().Be("strategy_name");
args.Arguments.Should().BeOfType<TestArguments>();
args.Outcome.Should().BeNull();
args.Context.Should().NotBeNull();
Expand All @@ -44,7 +44,7 @@ public void Report_NoOutcome_OK()
[Fact]
public void ResiliencePipelineTelemetry_NoDiagnosticSource_Ok()
{
var source = new ResilienceTelemetrySource("builder", "instance", "strategy-name");
var source = new ResilienceTelemetrySource("builder", "instance", "strategy_name");
var sut = new ResilienceStrategyTelemetry(source, null);
var context = ResilienceContextPool.Shared.Get();

Expand All @@ -62,7 +62,7 @@ public void Report_Outcome_OK()
var args = _args.Single();
args.Event.EventName.Should().Be("dummy-event");
args.Event.Severity.Should().Be(ResilienceEventSeverity.Warning);
args.Source.StrategyName.Should().Be("strategy-name");
args.Source.StrategyName.Should().Be("strategy_name");
args.Arguments.Should().BeOfType<TestArguments>();
args.Outcome.Should().NotBeNull();
args.Outcome!.Value.Result.Should().Be(99);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void AddResiliencePipeline_CustomInstanceName_EnsureReported(bool usingBu
// arrange
using var loggerFactory = new FakeLoggerFactory();

var context = ResilienceContextPool.Shared.Get("my-operation-key");
var context = ResilienceContextPool.Shared.Get("my-operation_key");
var services = new ServiceCollection();
var listener = new FakeTelemetryListener();
var registry = services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void StrategiesPerEndpoint_1365()

pipeline1.Execute(() => { });
events.Should().HaveCount(5);
events[0].Tags["pipeline-name"].Should().Be("endpoint-pipeline");
events[0].Tags["pipeline-instance"].Should().Be("Endpoint 1/Resource 1");
events[0].Tags["pipeline_name"].Should().Be("endpoint-pipeline");
events[0].Tags["pipeline_instance"].Should().Be("Endpoint 1/Resource 1");
}

public class EndpointOptions
Expand Down
Loading

0 comments on commit baf39f5

Please sign in to comment.