Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce TelemetryListener #1486

Merged
merged 7 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,7 @@ private ResiliencePipeline Build(ResiliencePipelineBuilder builder)

if (Enrichment)
{
options.Enrichers.Add(context =>
{
// The Microsoft.Extensions.Resilience library will add around 6 additional tags
// https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Resilience
context.Tags.Add(new("dummy1", "dummy"));
context.Tags.Add(new("dummy2", "dummy"));
context.Tags.Add(new("dummy3", "dummy"));
context.Tags.Add(new("dummy4", "dummy"));
context.Tags.Add(new("dummy5", "dummy"));
context.Tags.Add(new("dummy6", "dummy"));
});
options.MeteringEnrichers.Add(new CustomEnricher());
}

builder.ConfigureTelemetry(options);
Expand All @@ -66,6 +56,21 @@ private ResiliencePipeline Build(ResiliencePipelineBuilder builder)
return builder.Build();
}

private class CustomEnricher : MeteringEnricher
{
public override void Enrich<TResult, TArgs>(in EnrichmentContext<TResult, TArgs> context)
{
// The Microsoft.Extensions.Resilience library will add around 6 additional tags
// https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Resilience
context.Tags.Add(new("dummy1", "dummy"));
context.Tags.Add(new("dummy2", "dummy"));
context.Tags.Add(new("dummy3", "dummy"));
context.Tags.Add(new("dummy4", "dummy"));
context.Tags.Add(new("dummy5", "dummy"));
context.Tags.Add(new("dummy6", "dummy"));
}
}

private class TelemetryEventStrategy : ResilienceStrategy
{
private readonly ResilienceStrategyTelemetry _telemetry;
Expand Down
9 changes: 7 additions & 2 deletions src/Polly.Core/CircuitBreaker/OnCircuitClosedArguments.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace Polly.CircuitBreaker;

#pragma warning disable CA1815 // Override equals and operator equals on value types

/// <summary>
/// Arguments used by <see cref="CircuitBreakerStrategyOptions{TResult}.OnClosed"/> event.
/// </summary>
public sealed class OnCircuitClosedArguments
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
/// </remarks>
public readonly struct OnCircuitClosedArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="OnCircuitClosedArguments"/> class.
/// Initializes a new instance of the <see cref="OnCircuitClosedArguments"/> struct.
/// </summary>
/// <param name="isManual">Indicates whether the circuit was closed manually by using <see cref="CircuitBreakerManualControl"/>.</param>
public OnCircuitClosedArguments(bool isManual) => IsManual = isManual;
Expand Down
9 changes: 7 additions & 2 deletions src/Polly.Core/CircuitBreaker/OnCircuitHalfOpenedArguments.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace Polly.CircuitBreaker;

#pragma warning disable CA1815 // Override equals and operator equals on value types

/// <summary>
/// Arguments used by <see cref="CircuitBreakerStrategyOptions{TResult}.OnHalfOpened"/> event.
/// </summary>
public sealed class OnCircuitHalfOpenedArguments
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
/// </remarks>
public readonly struct OnCircuitHalfOpenedArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="OnCircuitHalfOpenedArguments"/> class.
/// Initializes a new instance of the <see cref="OnCircuitHalfOpenedArguments"/> struct.
/// </summary>
/// <param name="context">The context instance.</param>
public OnCircuitHalfOpenedArguments(ResilienceContext context) => Context = context;
Expand Down
9 changes: 7 additions & 2 deletions src/Polly.Core/CircuitBreaker/OnCircuitOpenedArguments.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace Polly.CircuitBreaker;

#pragma warning disable CA1815 // Override equals and operator equals on value types

/// <summary>
/// Arguments used by <see cref="CircuitBreakerStrategyOptions{TResult}.OnOpened"/> event.
/// </summary>
public sealed class OnCircuitOpenedArguments
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
/// </remarks>
public readonly struct OnCircuitOpenedArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="OnCircuitOpenedArguments"/> class.
/// Initializes a new instance of the <see cref="OnCircuitOpenedArguments"/> struct.
/// </summary>
/// <param name="breakDuration">The duration of break.</param>
/// <param name="isManual">Indicates whether the circuit was opened manually by using <see cref="CircuitBreakerManualControl"/>.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Fallback/FallbackResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected internal override async ValueTask<Outcome<T>> ExecuteCore<TState>(Func
return outcome;
}

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

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

Expand Down
5 changes: 4 additions & 1 deletion src/Polly.Core/Fallback/OnFallbackArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ namespace Polly.Fallback;
/// <summary>
/// Represents arguments used in fallback handling scenarios.
/// </summary>
public sealed class OnFallbackArguments
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
/// </remarks>
public readonly struct OnFallbackArguments
{
}
9 changes: 7 additions & 2 deletions src/Polly.Core/Hedging/OnHedgingArguments.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace Polly.Hedging;

#pragma warning disable CA1815 // Override equals and operator equals on value types

/// <summary>
/// Represents arguments used by the on-hedging event.
/// </summary>
public sealed class OnHedgingArguments
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility.
/// </remarks>
public readonly struct OnHedgingArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="OnHedgingArguments"/> class.
/// Initializes a new instance of the <see cref="OnHedgingArguments"/> struct.
/// </summary>
/// <param name="attemptNumber">The zero-based hedging attempt number.</param>
/// <param name="hasOutcome">Indicates whether outcome is available.</param>
Expand Down
Loading