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

[sdk-metrics] Turn exemplars on by default in prerelease builds #5545

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static OpenTelemetry.Logs.LoggerProviderBuilderExtensions.SetResourceBuilder(thi
static OpenTelemetry.Logs.LoggerProviderExtensions.AddProcessor(this OpenTelemetry.Logs.LoggerProvider! provider, OpenTelemetry.BaseProcessor<OpenTelemetry.Logs.LogRecord!>! processor) -> OpenTelemetry.Logs.LoggerProvider!
static OpenTelemetry.Logs.LoggerProviderExtensions.ForceFlush(this OpenTelemetry.Logs.LoggerProvider! provider, int timeoutMilliseconds = -1) -> bool
static OpenTelemetry.Logs.LoggerProviderExtensions.Shutdown(this OpenTelemetry.Logs.LoggerProvider! provider, int timeoutMilliseconds = -1) -> bool
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.SetExemplarFilter(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, OpenTelemetry.Metrics.ExemplarFilterType exemplarFilter = OpenTelemetry.Metrics.ExemplarFilterType.TraceBased) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.SetExemplarFilter(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, OpenTelemetry.Metrics.ExemplarFilterType exemplarFilter) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.OpenTelemetryBuilderSdkExtensions.WithLogging(this OpenTelemetry.IOpenTelemetryBuilder! builder) -> OpenTelemetry.IOpenTelemetryBuilder!
static OpenTelemetry.OpenTelemetryBuilderSdkExtensions.WithLogging(this OpenTelemetry.IOpenTelemetryBuilder! builder, System.Action<OpenTelemetry.Logs.LoggerProviderBuilder!>! configure) -> OpenTelemetry.IOpenTelemetryBuilder!
static OpenTelemetry.OpenTelemetryBuilderSdkExtensions.WithLogging(this OpenTelemetry.IOpenTelemetryBuilder! builder, System.Action<OpenTelemetry.Logs.LoggerProviderBuilder!>? configureBuilder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions!>? configureOptions) -> OpenTelemetry.IOpenTelemetryBuilder!
Expand Down
7 changes: 7 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
which could have led to a measurement being dropped.
([#5546](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5546))

* **Experimental (pre-release builds only):** `Exemplar`s are now enabled
automatically with the default filter type set to `TraceBased`. `Exemplar`s
will be sampled for measurements recorded under an active trace. The default
filter can be changed by calling the `SetExemplarFilter` extension on
`MeterProviderBuilder`. Use `AlwaysOff` to disable `Exemplar`s.
([#5545](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5545))

## 1.8.1

Released 2024-Apr-17
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry/Metrics/AggregatorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ internal sealed class AggregatorStore
internal readonly Func<ExemplarReservoir?>? ExemplarReservoirFactory;
internal long DroppedMeasurements = 0;

#if EXPOSE_EXPERIMENTAL_FEATURES
private const ExemplarFilterType DefaultExemplarFilter = ExemplarFilterType.TraceBased;
#else
private const ExemplarFilterType DefaultExemplarFilter = ExemplarFilterType.AlwaysOff;
#endif
private static readonly string MetricPointCapHitFixMessage = "Consider opting in for the experimental SDK feature to emit all the throttled metrics under the overflow attribute by setting env variable OTEL_DOTNET_EXPERIMENTAL_METRICS_EMIT_OVERFLOW_ATTRIBUTE = true. You could also modify instrumentation to reduce the number of unique key/value pair combinations. Or use Views to drop unwanted tags. Or use MeterProviderBuilder.SetMaxMetricPointsPerMetricStream to set higher limit.";
private static readonly Comparison<KeyValuePair<string, object?>> DimensionComparisonDelegate = (x, y) => x.Key.CompareTo(y.Key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ public static MeterProvider Build(this MeterProviderBuilder meterProviderBuilder
/// Sets the <see cref="ExemplarFilterType"/> to be used for this provider
/// which controls how measurements will be offered to exemplar reservoirs.
/// Default provider configuration: <see
/// cref="ExemplarFilterType.AlwaysOff"/>.
/// cref="ExemplarFilterType.TraceBased"/>.
/// </summary>
/// <remarks>
/// <inheritdoc cref="Exemplar"
/// path="/remarks/para[@experimental-warning='true']"/>
/// <para>Note: Use <see cref="ExemplarFilterType.TraceBased"/> or <see
/// cref="ExemplarFilterType.AlwaysOn"/> to enable exemplars.</para>
/// <para>Note: Use <see cref="ExemplarFilterType.AlwaysOff"/> to disable
/// exemplars.</para>
/// <para>Specification: <see
/// href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#exemplarfilter"/>.</para>
/// </remarks>
Expand All @@ -347,7 +347,7 @@ public static MeterProvider Build(this MeterProviderBuilder meterProviderBuilder
#endif
static MeterProviderBuilder SetExemplarFilter(
this MeterProviderBuilder meterProviderBuilder,
ExemplarFilterType exemplarFilter = ExemplarFilterType.TraceBased)
ExemplarFilterType exemplarFilter)
{
meterProviderBuilder.ConfigureBuilder((sp, builder) =>
{
Expand Down
24 changes: 17 additions & 7 deletions test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,20 +643,30 @@ static void ValidateSecondPhase(
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void TestTraceBasedExemplarFilter(bool enableTracing)
[InlineData(true, false)]
[InlineData(false, false)]
[InlineData(true, true)]
[InlineData(false, true)]
public void TestTraceBasedExemplarFilter(bool enableTracing, bool setExemplarFilter)
{
var exportedItems = new List<Metric>();

using var meter = new Meter($"{Utils.GetCurrentMethodName()}");

var counter = meter.CreateCounter<long>("testCounter");

using var container = this.BuildMeterProvider(out var meterProvider, builder => builder
.AddMeter(meter.Name)
.SetExemplarFilter(ExemplarFilterType.TraceBased)
.AddInMemoryExporter(exportedItems));
using var container = this.BuildMeterProvider(out var meterProvider, builder =>
{
builder
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems);

if (!IsExemplarApiExposed() || setExemplarFilter)
{
// Note: TraceBased is the SDK default for prerelease builds only
builder.SetExemplarFilter(ExemplarFilterType.TraceBased);
}
});

if (enableTracing)
{
Expand Down