diff --git a/docs/advanced/telemetry.md b/docs/advanced/telemetry.md index 29a4c0ee023..50e5369cd8d 100644 --- a/docs/advanced/telemetry.md +++ b/docs/advanced/telemetry.md @@ -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: @@ -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. @@ -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* @@ -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* @@ -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 diff --git a/src/Polly.Extensions/Telemetry/ResilienceTelemetryTags.cs b/src/Polly.Extensions/Telemetry/ResilienceTelemetryTags.cs index 9e627d9597f..17f5d8c3260 100644 --- a/src/Polly.Extensions/Telemetry/ResilienceTelemetryTags.cs +++ b/src/Polly.Extensions/Telemetry/ResilienceTelemetryTags.cs @@ -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"; } diff --git a/src/Polly.Extensions/Telemetry/TelemetryListenerImpl.cs b/src/Polly.Extensions/Telemetry/TelemetryListenerImpl.cs index 16b38f0f7d7..1484a54e6fd 100644 --- a/src/Polly.Extensions/Telemetry/TelemetryListenerImpl.cs +++ b/src/Polly.Extensions/Telemetry/TelemetryListenerImpl.cs @@ -21,16 +21,16 @@ public TelemetryListenerImpl(TelemetryOptions options) _listeners = options.TelemetryListeners.ToList(); Counter = Meter.CreateCounter( - "resilience-events", + "polly.resilience_events", description: "Tracks the number of resilience events that occurred in resilience strategies."); AttemptDuration = Meter.CreateHistogram( - "execution-attempt-duration", + "polly.execution_attempt_duration", unit: "ms", description: "Tracks the duration of execution attempts."); ExecutionDuration = Meter.CreateHistogram( - "pipeline-execution-duration", + "polly.pipeline_execution_duration", unit: "ms", description: "The execution duration of resilience pipelines."); } diff --git a/src/Snippets/Docs/ResilienceContextUsage.cs b/src/Snippets/Docs/ResilienceContextUsage.cs index f89130a0881..966c7498b90 100644 --- a/src/Snippets/Docs/ResilienceContextUsage.cs +++ b/src/Snippets/Docs/ResilienceContextUsage.cs @@ -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); diff --git a/test/Polly.Core.Tests/ResiliencePipelineBuilderTests.cs b/test/Polly.Core.Tests/ResiliencePipelineBuilderTests.cs index db0d9799558..db3ed78c984 100644 --- a/test/Polly.Core.Tests/ResiliencePipelineBuilderTests.cs +++ b/test/Polly.Core.Tests/ResiliencePipelineBuilderTests.cs @@ -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(); diff --git a/test/Polly.Core.Tests/StrategyBuilderContextTests.cs b/test/Polly.Core.Tests/StrategyBuilderContextTests.cs index d8af13aac3c..40c557d0255 100644 --- a/test/Polly.Core.Tests/StrategyBuilderContextTests.cs +++ b/test/Polly.Core.Tests/StrategyBuilderContextTests.cs @@ -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()), 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"); } } diff --git a/test/Polly.Core.Tests/Telemetry/ResilienceStrategyTelemetryTests.cs b/test/Polly.Core.Tests/Telemetry/ResilienceStrategyTelemetryTests.cs index c1605aeb856..fb2d56f1154 100644 --- a/test/Polly.Core.Tests/Telemetry/ResilienceStrategyTelemetryTests.cs +++ b/test/Polly.Core.Tests/Telemetry/ResilienceStrategyTelemetryTests.cs @@ -13,7 +13,7 @@ public ResilienceStrategyTelemetryTests() _source = new ResilienceTelemetrySource( "builder", "instance", - "strategy-name"); + "strategy_name"); _sut = TestUtilities.CreateResilienceTelemetry(args => _args.Add(args)); } @@ -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(); args.Outcome.Should().BeNull(); args.Context.Should().NotBeNull(); @@ -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(); @@ -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(); args.Outcome.Should().NotBeNull(); args.Outcome!.Value.Result.Should().Be(99); diff --git a/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs b/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs index d2895657e18..e149792fbf1 100644 --- a/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs +++ b/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs @@ -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 diff --git a/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs b/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs index d134ff2e854..cb6893f07f1 100644 --- a/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs +++ b/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs @@ -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 diff --git a/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs b/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs index 21cf65deec5..b354345bceb 100644 --- a/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs @@ -48,11 +48,11 @@ public void WriteEvent_LoggingWithOutcome_Ok(bool noOutcome) if (noOutcome) { - messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: ''"); + messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: ''"); } else { - messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: '200'"); + messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: '200'"); } } @@ -75,11 +75,11 @@ public void WriteEvent_LoggingWithException_Ok(bool noOutcome) if (noOutcome) { - messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: ''"); + messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: ''"); } else { - messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: 'Dummy message.'"); + messages[0].Message.Should().Be("Resilience event occurred. EventName: 'my-event', Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: 'Dummy message.'"); } } @@ -113,9 +113,9 @@ public void WriteEvent_EnsureSeverityRespected(ResilienceEventSeverity severity, messages[0].LogLevel.Should().Be(logLevel); - var events = GetEvents("resilience-events"); + var events = GetEvents("polly.resilience_events"); events.Should().HaveCount(1); - var ev = events[0]["event-severity"].Should().Be(severity.ToString()); + var ev = events[0]["event_severity"].Should().Be(severity.ToString()); } [Fact] @@ -128,7 +128,7 @@ public void WriteExecutionAttempt_LoggingWithException_Ok() var messages = _logger.GetRecords(new EventId(3, "ExecutionAttempt")).ToList(); messages.Should().HaveCount(1); - messages[0].Message.Should().Be("Execution attempt. Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: 'Dummy message.', Handled: 'True', Attempt: '4', Execution Time: '123'"); + messages[0].Message.Should().Be("Execution attempt. Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: 'Dummy message.', Handled: 'True', Attempt: '4', Execution Time: '123'"); } [InlineData(true, true)] @@ -148,11 +148,11 @@ public void WriteExecutionAttempt_LoggingWithOutcome_Ok(bool noOutcome, bool han if (noOutcome) { string resultString = string.Empty; - messages[0].Message.Should().Be($"Execution attempt. Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: '{resultString}', Handled: '{handled}', Attempt: '4', Execution Time: '123'"); + messages[0].Message.Should().Be($"Execution attempt. Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: '{resultString}', Handled: '{handled}', Attempt: '4', Execution Time: '123'"); } else { - messages[0].Message.Should().Be($"Execution attempt. Source: 'my-pipeline/pipeline-instance/my-strategy', Operation Key: 'op-key', Result: '200', Handled: '{handled}', Attempt: '4', Execution Time: '123'"); + messages[0].Message.Should().Be($"Execution attempt. Source: 'my-pipeline/pipeline_instance/my-strategy', Operation Key: 'op-key', Result: '200', Handled: '{handled}', Attempt: '4', Execution Time: '123'"); } messages[0].LogLevel.Should().Be(LogLevel.Warning); @@ -187,7 +187,7 @@ public void WriteEvent_MeteringWithoutEnrichers_Ok(bool noOutcome, bool exceptio }; ReportEvent(telemetry, outcome, context: ResilienceContextPool.Shared.Get("op-key").WithResultType()); - var events = GetEvents("resilience-events"); + var events = GetEvents("polly.resilience_events"); events.Should().HaveCount(1); var ev = events[0]; @@ -200,20 +200,20 @@ public void WriteEvent_MeteringWithoutEnrichers_Ok(bool noOutcome, bool exceptio ev.Count.Should().Be(6); } - ev["event-name"].Should().Be("my-event"); - ev["event-severity"].Should().Be("Warning"); - ev["pipeline-name"].Should().Be("my-pipeline"); - ev["pipeline-instance"].Should().Be("pipeline-instance"); - ev["operation-key"].Should().Be("op-key"); - ev["strategy-name"].Should().Be("my-strategy"); + ev["event_name"].Should().Be("my-event"); + ev["event_severity"].Should().Be("Warning"); + ev["pipeline_name"].Should().Be("my-pipeline"); + ev["pipeline_instance"].Should().Be("pipeline_instance"); + ev["operation_key"].Should().Be("op-key"); + ev["strategy_name"].Should().Be("my-strategy"); if (outcome?.Exception is not null) { - ev["exception-name"].Should().Be("System.InvalidOperationException"); + ev["exception_name"].Should().Be("System.InvalidOperationException"); } else { - ev.Should().NotContainKey("exception-name"); + ev.Should().NotContainKey("exception_name"); } } @@ -235,7 +235,7 @@ public void WriteExecutionAttemptEvent_Metering_Ok(bool noOutcome, bool exceptio }; ReportEvent(telemetry, outcome, context: ResilienceContextPool.Shared.Get("op-key").WithResultType(), arg: attemptArg); - var events = GetEvents("execution-attempt-duration"); + var events = GetEvents("polly.execution_attempt_duration"); events.Should().HaveCount(1); var ev = events[0]; @@ -248,25 +248,25 @@ public void WriteExecutionAttemptEvent_Metering_Ok(bool noOutcome, bool exceptio ev.Count.Should().Be(8); } - ev["event-name"].Should().Be("my-event"); - ev["event-severity"].Should().Be("Warning"); - ev["pipeline-name"].Should().Be("my-pipeline"); - ev["pipeline-instance"].Should().Be("pipeline-instance"); - ev["operation-key"].Should().Be("op-key"); - ev["pipeline-name"].Should().Be("my-pipeline"); - ev["attempt-number"].Should().Be(5); - ev["attempt-handled"].Should().Be(true); + ev["event_name"].Should().Be("my-event"); + ev["event_severity"].Should().Be("Warning"); + ev["pipeline_name"].Should().Be("my-pipeline"); + ev["pipeline_instance"].Should().Be("pipeline_instance"); + ev["operation_key"].Should().Be("op-key"); + ev["pipeline_name"].Should().Be("my-pipeline"); + ev["attempt_number"].Should().Be(5); + ev["attempt_handled"].Should().Be(true); if (outcome?.Exception is not null) { - ev["exception-name"].Should().Be("System.InvalidOperationException"); + ev["exception_name"].Should().Be("System.InvalidOperationException"); } else { - ev.Should().NotContainKey("exception-name"); + ev.Should().NotContainKey("exception_name"); } - _events.Single(v => v.Name == "execution-attempt-duration").Measurement.Should().Be(50000); + _events.Single(v => v.Name == "polly.execution_attempt_duration").Measurement.Should().Be(50000); } [Fact] @@ -278,7 +278,7 @@ public void WriteExecutionAttemptEvent_ShouldBeSkipped() var attemptArg = new ExecutionAttemptArguments(5, TimeSpan.FromSeconds(50), true); ReportEvent(telemetry, Outcome.FromResult(true), context: ResilienceContextPool.Shared.Get("op-key").WithResultType(), arg: attemptArg); - var events = GetEvents("execution-attempt-duration"); + var events = GetEvents("polly.execution_attempt_duration"); events.Should().HaveCount(0); } @@ -309,7 +309,7 @@ public void WriteEvent_MeteringWithEnrichers_Ok(int count) ReportEvent(telemetry, Outcome.FromResult(true)); - var events = GetEvents("resilience-events"); + var events = GetEvents("polly.resilience_events"); var ev = events[0]; ev.Count.Should().Be(DefaultDimensions + count + 1); ev["other"].Should().Be("other-value"); @@ -326,7 +326,7 @@ public void WriteEvent_MeteringWithoutBuilderInstance_Ok() using var metering = TestUtilities.EnablePollyMetering(_events); var telemetry = Create(); ReportEvent(telemetry, null, instanceName: null); - var events = GetEvents("resilience-events")[0].Should().NotContainKey("pipeline-instance"); + var events = GetEvents("polly.resilience_events")[0].Should().NotContainKey("pipeline_instance"); } [InlineData(true)] @@ -362,10 +362,10 @@ public void PipelineExecution_Logged(bool exception) var messages = _logger.GetRecords(new EventId(1, "StrategyExecuting")).ToList(); messages.Should().HaveCount(1); - messages[0].Message.Should().Be("Resilience pipeline executing. Source: 'my-pipeline/pipeline-instance', Operation Key: 'op-key'"); + messages[0].Message.Should().Be("Resilience pipeline executing. Source: 'my-pipeline/pipeline_instance', Operation Key: 'op-key'"); messages = _logger.GetRecords(new EventId(2, "StrategyExecuted")).ToList(); messages.Should().HaveCount(1); - messages[0].Message.Should().Match($"Resilience pipeline executed. Source: 'my-pipeline/pipeline-instance', Operation Key: 'op-key', Result: '{result}', Execution Time: 10000ms"); + messages[0].Message.Should().Match($"Resilience pipeline executed. Source: 'my-pipeline/pipeline_instance', Operation Key: 'op-key', Result: '{result}', Execution Time: 10000ms"); messages[0].LogLevel.Should().Be(LogLevel.Debug); } @@ -378,7 +378,7 @@ public void PipelineExecution_VoidResult_Ok() var messages = _logger.GetRecords(new EventId(1, "StrategyExecuting")).ToList(); messages.Should().HaveCount(1); - messages[0].Message.Should().Be("Resilience pipeline executing. Source: 'my-pipeline/pipeline-instance', Operation Key: 'op-key'"); + messages[0].Message.Should().Be("Resilience pipeline executing. Source: 'my-pipeline/pipeline_instance', Operation Key: 'op-key'"); } [Fact] @@ -390,7 +390,7 @@ public void PipelineExecution_NoOutcome_Logged() ReportEvent(telemetry, outcome: null, arg: new PipelineExecutedArguments(TimeSpan.FromSeconds(10)), context: context); var messages = _logger.GetRecords(new EventId(2, "StrategyExecuted")).ToList(); - messages[0].Message.Should().Match($"Resilience pipeline executed. Source: 'my-pipeline/pipeline-instance', Operation Key: 'op-key', Result: '', Execution Time: 10000ms"); + messages[0].Message.Should().Match($"Resilience pipeline executed. Source: 'my-pipeline/pipeline_instance', Operation Key: 'op-key', Result: '', Execution Time: 10000ms"); } [InlineData(false)] @@ -419,24 +419,24 @@ public void PipelineExecution_Metered(bool exception) ReportEvent(telemetry, outcome: outcome, arg: new PipelineExecutedArguments(TimeSpan.FromSeconds(10)), context: context); - var ev = _events.Single(v => v.Name == "pipeline-execution-duration").Tags; + var ev = _events.Single(v => v.Name == "polly.pipeline_execution_duration").Tags; ev.Count.Should().Be(exception ? 8 : 7); - ev["pipeline-instance"].Should().Be("pipeline-instance"); - ev["operation-key"].Should().Be("op-key"); - ev["pipeline-name"].Should().Be("my-pipeline"); - ev["event-name"].Should().Be("my-event"); - ev["event-severity"].Should().Be("Warning"); - ev["pipeline-name"].Should().Be("my-pipeline"); + ev["pipeline_instance"].Should().Be("pipeline_instance"); + ev["operation_key"].Should().Be("op-key"); + ev["pipeline_name"].Should().Be("my-pipeline"); + ev["event_name"].Should().Be("my-event"); + ev["event_severity"].Should().Be("Warning"); + ev["pipeline_name"].Should().Be("my-pipeline"); ev["custom-tag"].Should().Be("custom-tag-value"); if (exception) { - ev["exception-name"].Should().Be("System.InvalidOperationException"); + ev["exception_name"].Should().Be("System.InvalidOperationException"); } else { - ev.Should().NotContainKey("exception-name"); + ev.Should().NotContainKey("exception_name"); } } @@ -449,7 +449,7 @@ public void PipelineExecuted_ShouldBeSkipped() var attemptArg = new PipelineExecutedArguments(TimeSpan.FromSeconds(50)); ReportEvent(telemetry, Outcome.FromResult(true), context: ResilienceContextPool.Shared.Get("op-key").WithResultType(), arg: attemptArg); - var events = GetEvents("pipeline-execution-duration"); + var events = GetEvents("polly.pipeline_execution_duration"); events.Should().HaveCount(0); } @@ -481,7 +481,7 @@ private TelemetryListenerImpl Create(IEnumerable? enrichers = private static void ReportEvent( TelemetryListenerImpl telemetry, Outcome? outcome, - string? instanceName = "pipeline-instance", + string? instanceName = "pipeline_instance", ResilienceContext? context = null, TestArguments? arg = null, ResilienceEventSeverity severity = ResilienceEventSeverity.Warning) => ReportEvent(telemetry, outcome, instanceName, context, arg!, severity); @@ -489,7 +489,7 @@ private static void ReportEvent( private static void ReportEvent( TelemetryListenerImpl telemetry, Outcome? outcome, - string? instanceName = "pipeline-instance", + string? instanceName = "pipeline_instance", ResilienceContext? context = null, TArgs arg = default!, ResilienceEventSeverity severity = ResilienceEventSeverity.Warning) diff --git a/test/Polly.TestUtils/TestUtilities.cs b/test/Polly.TestUtils/TestUtilities.cs index 53bb9ccb680..a24bdd88176 100644 --- a/test/Polly.TestUtils/TestUtilities.cs +++ b/test/Polly.TestUtils/TestUtilities.cs @@ -38,7 +38,7 @@ public static async Task AssertWithTimeoutAsync(Func assertion, TimeSpan t } public static ResilienceStrategyTelemetry CreateResilienceTelemetry(TelemetryListener listener, ResilienceTelemetrySource? source = null) - => new(source ?? new ResilienceTelemetrySource("dummy-builder", "dummy-instance", "strategy-name"), listener); + => new(source ?? new ResilienceTelemetrySource("dummy-builder", "dummy-instance", "strategy_name"), listener); public static ResilienceStrategyTelemetry CreateResilienceTelemetry(Action> callback, ResilienceTelemetrySource? source = null) => CreateResilienceTelemetry(new FakeTelemetryListener(callback), source);