-
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
Merged
CodeBlanch
merged 10 commits into
open-telemetry:main
from
CodeBlanch:sdk-exemplarfilter-histograms
May 16, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70acc57
Add experimental envvar for setting ExemplarFilter for histograms.
CodeBlanch 60e6191
Update CHANGELOG.
CodeBlanch cbf3ef1
Code review.
CodeBlanch 9d9fa2b
Merge branch 'main' into sdk-exemplarfilter-histograms
cijothomas 5aafc2f
Code review.
CodeBlanch b97bc0d
Merge branch 'sdk-exemplarfilter-histograms' of https://github.com/Co…
CodeBlanch 50f3edd
Test tweak.
CodeBlanch a088d08
Add logging for MeterProvider settings.
CodeBlanch 85857de
Merge from main.
CodeBlanch 63b947e
Code review.
CodeBlanch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
@@ -72,6 +74,9 @@ internal MeterProviderSdk( | |
|
|
||
| this.viewConfigs = state.ViewConfigs; | ||
|
|
||
| OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent( | ||
| $"MeterProvider configuration: {{MetricLimit={state.MetricLimit}, CardinalityLimit={state.CardinalityLimit}, EmitOverflowAttribute={this.EmitOverflowAttribute}, ReclaimUnusedMetricPoints={this.ReclaimUnusedMetricPoints}, ExemplarFilter={this.ExemplarFilter}, ExemplarFilterForHistograms={this.ExemplarFilterForHistograms}}}."); | ||
|
|
||
| foreach (var reader in state.Readers) | ||
| { | ||
| Guard.ThrowIfNull(reader); | ||
|
|
@@ -83,7 +88,8 @@ internal MeterProviderSdk( | |
| state.CardinalityLimit, | ||
| this.EmitOverflowAttribute, | ||
| this.ReclaimUnusedMetricPoints, | ||
| this.ExemplarFilter); | ||
| this.ExemplarFilter, | ||
| this.ExemplarFilterForHistograms); | ||
|
|
||
| if (this.reader == null) | ||
| { | ||
|
|
@@ -490,37 +496,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; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.