Switch to standard OpenTelemetry environment variables for OTLP configuration - #5824
Conversation
6ac19eb to
9abb2a3
Compare
…guration Removes the custom OtlpEndpointUrl setting in favor of standard environment variables such as OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_METRICS_ENDPOINT. This ensures compatibility with native OpenTelemetry SDK configuration, supports both gRPC and HTTP protocols, and simplifies instance configuration.
9abb2a3 to
5005697
Compare
| public static class OtlpEndpoint | ||
| { | ||
| public static string MetricsEndpointFromEnvironment() => | ||
| Read("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT") ?? Read("OTEL_EXPORTER_OTLP_ENDPOINT"); |
There was a problem hiding this comment.
It looks like OTEL_EXPORTER_OTLP_METRICS_ENDPOINT isnt supported when using AddOtlpExporter - https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.17.0/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md?plain=1#L520-L530
There was a problem hiding this comment.
I removed that and mentioned it in the docs
| } | ||
| var otlpEndpoint = OtlpEndpoint.MetricsEndpointFromEnvironment(); | ||
|
|
||
| if (!Uri.TryCreate(settings.OtlpEndpointUrl, UriKind.Absolute, out var otlpEndpoint)) |
There was a problem hiding this comment.
Have you confirmed that the OpenTelemetry library does indeed fail an invalid URL?
There was a problem hiding this comment.
It now fails if the URL is invalid, so it no longer defaults.
|
|
||
| static string Read(string variable) | ||
| { | ||
| var value = Environment.GetEnvironmentVariable(variable); |
There was a problem hiding this comment.
Should we read through IConfiguration rather direct from env var? This would provide more flexibility to the user in how they set this.
The OpenTelemetry SDK only honors signal-specific environment variables, such as OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, when using UseOtlpExporter. Since instances use AddOtlpExporter to restrict OTLP to metrics, these specific variables have no effect and have been removed to avoid confusion. This also switches the endpoint detection to use IConfiguration and returns a Uri to ensure the configured value is valid.
Removes the custom OtlpEndpointUrl setting in favor of standard environment variables such as OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_METRICS_ENDPOINT. This ensures compatibility with native OpenTelemetry SDK configuration, supports both gRPC and HTTP protocols, and simplifies instance configuration.
This came from #5816 (comment)