-
Notifications
You must be signed in to change notification settings - Fork 862
[sdk-metrics] Add experimental envvar for setting ExemplarFilter for histograms #5611
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
Changes from 2 commits
70acc57
60e6191
cbf3ef1
9d9fa2b
5aafc2f
b97bc0d
50f3edd
a088d08
85857de
63b947e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -372,6 +372,9 @@ OpenTelemetry SDK comes with the following `ExemplarFilters` (defined on | |||||
| The `SetExemplarFilter` extension method on `MeterProviderBuilder` can be used | ||||||
| to set the desired `ExemplarFilterType` and enable `Exemplar` collection: | ||||||
|
|
||||||
| > [!NOTE] | ||||||
| > The `SetExemplarFilter` API was added in the `1.9.0` release. | ||||||
cijothomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ```csharp | ||||||
| using OpenTelemetry; | ||||||
| using OpenTelemetry.Metrics; | ||||||
|
|
@@ -382,6 +385,24 @@ using var meterProvider = Sdk.CreateMeterProviderBuilder() | |||||
| .Build(); | ||||||
| ``` | ||||||
|
|
||||||
| It is also possible to configure the `ExemplarFilter` by using following | ||||||
| environmental variables: | ||||||
|
|
||||||
| > [!NOTE] | ||||||
| > Programmatically calling `SetExemplarFilter` will override any defaults set | ||||||
| using environment variables or configuration. | ||||||
|
|
||||||
| | Environment variable | Description | Notes | | ||||||
| | -------------------------- | -------------------------------------------------- |-------| | ||||||
| | `OTEL_METRICS_EXEMPLAR_FILTER` | Sets the default `ExemplarFilter` to use for all metrics. | Added in `1.9.0` | | ||||||
| | `OTEL_DOTNET_EXPERIMENTAL_METRICS_EXEMPLAR_FILTER_HISTOGRAMS` | Sets the default `ExemplarFilter` to use for histogram metrics. If not set than `OTEL_METRICS_EXEMPLAR_FILTER` also applies to histograms. | Experimental key (may be removed or changed in the future). Added in `1.9.0` | | ||||||
vishweshbankwar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| | `OTEL_DOTNET_EXPERIMENTAL_METRICS_EXEMPLAR_FILTER_HISTOGRAMS` | Sets the default `ExemplarFilter` to use for histogram metrics. If not set than `OTEL_METRICS_EXEMPLAR_FILTER` also applies to histograms. | Experimental key (may be removed or changed in the future). Added in `1.9.0` | | |
| | `OTEL_DOTNET_EXPERIMENTAL_METRICS_EXEMPLAR_FILTER_HISTOGRAMS` | Sets the default `ExemplarFilter` to use for histogram metrics. If not set, then `OTEL_METRICS_EXEMPLAR_FILTER` also applies to histograms. | Experimental key (may be removed or changed in the future). Added in `1.9.0` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this a bit for @vishweshbankwar's comment above.
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ internal sealed class MeterProviderSdk : MeterProvider | |
| internal const string EmitOverFlowAttributeConfigKey = "OTEL_DOTNET_EXPERIMENTAL_METRICS_EMIT_OVERFLOW_ATTRIBUTE"; | ||
| internal const string ReclaimUnusedMetricPointsConfigKey = "OTEL_DOTNET_EXPERIMENTAL_METRICS_RECLAIM_UNUSED_METRIC_POINTS"; | ||
| internal const string ExemplarFilterConfigKey = "OTEL_METRICS_EXEMPLAR_FILTER"; | ||
| internal const string ExemplarFilterHistogramsConfigKey = "OTEL_DOTNET_EXPERIMENTAL_METRICS_EXEMPLAR_FILTER_HISTOGRAMS"; | ||
|
|
||
| internal readonly IServiceProvider ServiceProvider; | ||
| internal readonly IDisposable? OwnedServiceProvider; | ||
|
|
@@ -24,6 +25,7 @@ internal sealed class MeterProviderSdk : MeterProvider | |
| internal bool EmitOverflowAttribute; | ||
| internal bool ReclaimUnusedMetricPoints; | ||
| internal ExemplarFilterType? ExemplarFilter; | ||
| internal ExemplarFilterType? ExemplarFilterForHistograms; | ||
| internal Action? OnCollectObservableInstruments; | ||
|
|
||
| private readonly List<object> instrumentations = new(); | ||
|
|
@@ -83,7 +85,8 @@ internal MeterProviderSdk( | |
| state.CardinalityLimit, | ||
| this.EmitOverflowAttribute, | ||
| this.ReclaimUnusedMetricPoints, | ||
| this.ExemplarFilter); | ||
| this.ExemplarFilter, | ||
| this.ExemplarFilterForHistograms); | ||
|
|
||
| if (this.reader == null) | ||
| { | ||
|
|
@@ -490,37 +493,70 @@ private void ApplySpecificationConfigurationKeys(IConfiguration configuration) | |
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent("Reclaim unused metric point feature enabled via configuration."); | ||
| } | ||
|
|
||
| var hasProgrammaticExemplarFilterValue = this.ExemplarFilter.HasValue; | ||
|
|
||
| if (configuration.TryGetStringValue(ExemplarFilterConfigKey, out var configValue)) | ||
| { | ||
| if (this.ExemplarFilter.HasValue) | ||
| if (hasProgrammaticExemplarFilterValue) | ||
| { | ||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent( | ||
| $"Exemplar filter configuration value '{configValue}' has been ignored because a value '{this.ExemplarFilter}' was set programmatically."); | ||
| return; | ||
| } | ||
|
|
||
| ExemplarFilterType? exemplarFilter; | ||
| if (!TryParseExemplarFilterFromConfigurationValue(configValue, out var exemplarFilter)) | ||
| { | ||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter configuration was found but the value '{configValue}' is invalid and will be ignored."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we be showing string interpolation in our own logging.. though this is just startup only! |
||
| return; | ||
| } | ||
|
|
||
| this.ExemplarFilter = exemplarFilter; | ||
|
|
||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter set to '{exemplarFilter}' from configuration."); | ||
| } | ||
|
|
||
| if (configuration.TryGetStringValue(ExemplarFilterHistogramsConfigKey, out configValue)) | ||
| { | ||
| if (hasProgrammaticExemplarFilterValue) | ||
| { | ||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent( | ||
| $"Exemplar filter histogram configuration value '{configValue}' has been ignored because a value '{this.ExemplarFilter}' was set programmatically."); | ||
| return; | ||
| } | ||
|
|
||
| if (!TryParseExemplarFilterFromConfigurationValue(configValue, out var exemplarFilter)) | ||
| { | ||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter histogram configuration was found but the value '{configValue}' is invalid and will be ignored."); | ||
| return; | ||
| } | ||
|
|
||
| this.ExemplarFilterForHistograms = exemplarFilter; | ||
|
|
||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter for histograms set to '{exemplarFilter}' from configuration."); | ||
cijothomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| static bool TryParseExemplarFilterFromConfigurationValue(string? configValue, out ExemplarFilterType? exemplarFilter) | ||
| { | ||
| if (string.Equals("always_off", configValue, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| exemplarFilter = ExemplarFilterType.AlwaysOff; | ||
| return true; | ||
| } | ||
| else if (string.Equals("always_on", configValue, StringComparison.OrdinalIgnoreCase)) | ||
|
|
||
| if (string.Equals("always_on", configValue, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| exemplarFilter = ExemplarFilterType.AlwaysOn; | ||
| return true; | ||
| } | ||
| else if (string.Equals("trace_based", configValue, StringComparison.OrdinalIgnoreCase)) | ||
|
|
||
| if (string.Equals("trace_based", configValue, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| exemplarFilter = ExemplarFilterType.TraceBased; | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter configuration was found but the value '{configValue}' is invalid and will be ignored."); | ||
| return; | ||
| } | ||
|
|
||
| this.ExemplarFilter = exemplarFilter; | ||
|
|
||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter set to '{exemplarFilter}' from configuration."); | ||
| exemplarFilter = null; | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.