-
Notifications
You must be signed in to change notification settings - Fork 772
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
Add support for OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE environment variable #4667
Changes from all commits
fcbe3a4
f379d06
1146438
fcba290
6663152
1a2fa11
21a2160
1b2eedc
9d3f89a
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,6 +15,8 @@ | |||||||||
// </copyright> | ||||||||||
|
||||||||||
using System.Diagnostics.Metrics; | ||||||||||
using System.Reflection; | ||||||||||
using Microsoft.Extensions.Configuration; | ||||||||||
using Microsoft.Extensions.DependencyInjection; | ||||||||||
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; | ||||||||||
using OpenTelemetry.Metrics; | ||||||||||
|
@@ -704,6 +706,50 @@ public void TestHistogramToOtlpMetric(string name, string description, string un | |||||||||
Assert.Empty(dataPoint.Exemplars); | ||||||||||
} | ||||||||||
|
||||||||||
[Theory] | ||||||||||
[InlineData("cumulative", MetricReaderTemporalityPreference.Cumulative)] | ||||||||||
[InlineData("Cumulative", MetricReaderTemporalityPreference.Cumulative)] | ||||||||||
[InlineData("CUMULATIVE", MetricReaderTemporalityPreference.Cumulative)] | ||||||||||
[InlineData("delta", MetricReaderTemporalityPreference.Delta)] | ||||||||||
[InlineData("Delta", MetricReaderTemporalityPreference.Delta)] | ||||||||||
[InlineData("DELTA", MetricReaderTemporalityPreference.Delta)] | ||||||||||
public void TestTemporalityPreferenceConfiguration(string configValue, MetricReaderTemporalityPreference expectedTemporality) | ||||||||||
{ | ||||||||||
var configData = new Dictionary<string, string> { ["OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE"] = configValue }; | ||||||||||
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. nit: Use the constant 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. This was done on purpose. If someone accidentally changes the environment variable key name in the 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. I don't necessarily disagree with your logic, but it does break with all other envvar tests that I can recall seeing. Ex: Lines 62 to 65 in e7f7cd6
I would probably go with the constant to be consistent and follow DRY principle. If someone does have a valid reason to change it they should only have to do it in one spot. But I made this a "nit" comment because I figured you might disagree 🤣 Up to you! 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. I think we should think about what do we want to test? If we want to test, that a user a can configure something by providing a value for a particular string in the config, then our tests shouldn't be using the same const as the src file. Our tests would be too dynamic for their own good. 😄 |
||||||||||
var configuration = new ConfigurationBuilder() | ||||||||||
.AddInMemoryCollection(configData) | ||||||||||
.Build(); | ||||||||||
|
||||||||||
// Check for both the code paths: | ||||||||||
// 1. The final extension method which accepts `Action<OtlpExporterOptions>`. | ||||||||||
// 2. The final extension method which accepts `Action<OtlpExporterOptions, MetricReaderOptions>`. | ||||||||||
|
||||||||||
// Test 1st code path | ||||||||||
using var meterProvider1 = Sdk.CreateMeterProviderBuilder() | ||||||||||
.ConfigureServices(services => services.AddSingleton<IConfiguration>(configuration)) | ||||||||||
.AddOtlpExporter() // This would in turn call the extension method which accepts `Action<OtlpExporterOptions>` | ||||||||||
.Build(); | ||||||||||
|
||||||||||
var assembly = typeof(Sdk).Assembly; | ||||||||||
var type = assembly.GetType("OpenTelemetry.Metrics.MeterProviderSdk"); | ||||||||||
var fieldInfo = type.GetField("reader", BindingFlags.Instance | BindingFlags.NonPublic); | ||||||||||
var reader = fieldInfo.GetValue(meterProvider1) as MetricReader; | ||||||||||
var temporality = reader.TemporalityPreference; | ||||||||||
|
||||||||||
Assert.Equal(expectedTemporality, temporality); | ||||||||||
|
||||||||||
// Test 2nd code path | ||||||||||
using var meterProvider2 = Sdk.CreateMeterProviderBuilder() | ||||||||||
.ConfigureServices(services => services.AddSingleton<IConfiguration>(configuration)) | ||||||||||
.AddOtlpExporter((_, _) => { }) // This would in turn call the extension method which accepts `Action<OtlpExporterOptions, MetricReaderOptions>` | ||||||||||
.Build(); | ||||||||||
|
||||||||||
reader = fieldInfo.GetValue(meterProvider2) as MetricReader; | ||||||||||
temporality = reader.TemporalityPreference; | ||||||||||
|
||||||||||
Assert.Equal(expectedTemporality, temporality); | ||||||||||
} | ||||||||||
|
||||||||||
private static IEnumerable<KeyValuePair<string, object>> ToAttributes(object[] keysValues) | ||||||||||
{ | ||||||||||
var keys = keysValues?.Where((_, index) => index % 2 == 0).ToArray(); | ||||||||||
|
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.
Remove this todo as well. Can be a separate PR
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.
Good call out. I was thinking we should update that README once we have released a version of the package with this feature instead of doing that now.