Skip to content

Commit d72ae6c

Browse files
authored
Introduce TelemetryListener (#1486)
1 parent 4a8c59a commit d72ae6c

File tree

65 files changed

+753
-824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+753
-824
lines changed

bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs

+16-11
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,7 @@ private ResiliencePipeline Build(ResiliencePipelineBuilder builder)
4747

4848
if (Enrichment)
4949
{
50-
options.Enrichers.Add(context =>
51-
{
52-
// The Microsoft.Extensions.Resilience library will add around 6 additional tags
53-
// https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Resilience
54-
context.Tags.Add(new("dummy1", "dummy"));
55-
context.Tags.Add(new("dummy2", "dummy"));
56-
context.Tags.Add(new("dummy3", "dummy"));
57-
context.Tags.Add(new("dummy4", "dummy"));
58-
context.Tags.Add(new("dummy5", "dummy"));
59-
context.Tags.Add(new("dummy6", "dummy"));
60-
});
50+
options.MeteringEnrichers.Add(new CustomEnricher());
6151
}
6252

6353
builder.ConfigureTelemetry(options);
@@ -66,6 +56,21 @@ private ResiliencePipeline Build(ResiliencePipelineBuilder builder)
6656
return builder.Build();
6757
}
6858

59+
private class CustomEnricher : MeteringEnricher
60+
{
61+
public override void Enrich<TResult, TArgs>(in EnrichmentContext<TResult, TArgs> context)
62+
{
63+
// The Microsoft.Extensions.Resilience library will add around 6 additional tags
64+
// https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Resilience
65+
context.Tags.Add(new("dummy1", "dummy"));
66+
context.Tags.Add(new("dummy2", "dummy"));
67+
context.Tags.Add(new("dummy3", "dummy"));
68+
context.Tags.Add(new("dummy4", "dummy"));
69+
context.Tags.Add(new("dummy5", "dummy"));
70+
context.Tags.Add(new("dummy6", "dummy"));
71+
}
72+
}
73+
6974
private class TelemetryEventStrategy : ResilienceStrategy
7075
{
7176
private readonly ResilienceStrategyTelemetry _telemetry;

src/Polly.Core/CircuitBreaker/OnCircuitClosedArguments.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
namespace Polly.CircuitBreaker;
22

3+
#pragma warning disable CA1815 // Override equals and operator equals on value types
4+
35
/// <summary>
46
/// Arguments used by <see cref="CircuitBreakerStrategyOptions{TResult}.OnClosed"/> event.
57
/// </summary>
6-
public sealed class OnCircuitClosedArguments
8+
/// <remarks>
9+
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
10+
/// </remarks>
11+
public readonly struct OnCircuitClosedArguments
712
{
813
/// <summary>
9-
/// Initializes a new instance of the <see cref="OnCircuitClosedArguments"/> class.
14+
/// Initializes a new instance of the <see cref="OnCircuitClosedArguments"/> struct.
1015
/// </summary>
1116
/// <param name="isManual">Indicates whether the circuit was closed manually by using <see cref="CircuitBreakerManualControl"/>.</param>
1217
public OnCircuitClosedArguments(bool isManual) => IsManual = isManual;

src/Polly.Core/CircuitBreaker/OnCircuitHalfOpenedArguments.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
namespace Polly.CircuitBreaker;
22

3+
#pragma warning disable CA1815 // Override equals and operator equals on value types
4+
35
/// <summary>
46
/// Arguments used by <see cref="CircuitBreakerStrategyOptions{TResult}.OnHalfOpened"/> event.
57
/// </summary>
6-
public sealed class OnCircuitHalfOpenedArguments
8+
/// <remarks>
9+
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
10+
/// </remarks>
11+
public readonly struct OnCircuitHalfOpenedArguments
712
{
813
/// <summary>
9-
/// Initializes a new instance of the <see cref="OnCircuitHalfOpenedArguments"/> class.
14+
/// Initializes a new instance of the <see cref="OnCircuitHalfOpenedArguments"/> struct.
1015
/// </summary>
1116
/// <param name="context">The context instance.</param>
1217
public OnCircuitHalfOpenedArguments(ResilienceContext context) => Context = context;

src/Polly.Core/CircuitBreaker/OnCircuitOpenedArguments.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
namespace Polly.CircuitBreaker;
22

3+
#pragma warning disable CA1815 // Override equals and operator equals on value types
4+
35
/// <summary>
46
/// Arguments used by <see cref="CircuitBreakerStrategyOptions{TResult}.OnOpened"/> event.
57
/// </summary>
6-
public sealed class OnCircuitOpenedArguments
8+
/// <remarks>
9+
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
10+
/// </remarks>
11+
public readonly struct OnCircuitOpenedArguments
712
{
813
/// <summary>
9-
/// Initializes a new instance of the <see cref="OnCircuitOpenedArguments"/> class.
14+
/// Initializes a new instance of the <see cref="OnCircuitOpenedArguments"/> struct.
1015
/// </summary>
1116
/// <param name="breakDuration">The duration of break.</param>
1217
/// <param name="isManual">Indicates whether the circuit was opened manually by using <see cref="CircuitBreakerManualControl"/>.</param>

src/Polly.Core/Fallback/FallbackResilienceStrategy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected internal override async ValueTask<Outcome<T>> ExecuteCore<TState>(Func
2626
return outcome;
2727
}
2828

29-
var onFallbackArgs = new OutcomeArguments<T, OnFallbackArguments>(context, outcome, new OnFallbackArguments());
29+
var onFallbackArgs = new OutcomeArguments<T, OnFallbackArguments>(context, outcome, default);
3030

3131
_telemetry.Report(new(ResilienceEventSeverity.Warning, FallbackConstants.OnFallback), onFallbackArgs);
3232

src/Polly.Core/Fallback/OnFallbackArguments.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ namespace Polly.Fallback;
33
/// <summary>
44
/// Represents arguments used in fallback handling scenarios.
55
/// </summary>
6-
public sealed class OnFallbackArguments
6+
/// <remarks>
7+
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
8+
/// </remarks>
9+
public readonly struct OnFallbackArguments
710
{
811
}

src/Polly.Core/Hedging/OnHedgingArguments.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
namespace Polly.Hedging;
22

3+
#pragma warning disable CA1815 // Override equals and operator equals on value types
4+
35
/// <summary>
46
/// Represents arguments used by the on-hedging event.
57
/// </summary>
6-
public sealed class OnHedgingArguments
8+
/// <remarks>
9+
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
10+
/// </remarks>
11+
public readonly struct OnHedgingArguments
712
{
813
/// <summary>
9-
/// Initializes a new instance of the <see cref="OnHedgingArguments"/> class.
14+
/// Initializes a new instance of the <see cref="OnHedgingArguments"/> struct.
1015
/// </summary>
1116
/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
1217
/// <param name="hasOutcome">Indicates whether outcome is available.</param>

0 commit comments

Comments
 (0)