Skip to content

Switch to standard OpenTelemetry environment variables for OTLP configuration - #5824

Merged
johnsimons merged 2 commits into
masterfrom
john/otel_envvar
Aug 25, 2026
Merged

Switch to standard OpenTelemetry environment variables for OTLP configuration#5824
johnsimons merged 2 commits into
masterfrom
john/otel_envvar

Conversation

@johnsimons

@johnsimons johnsimons commented Aug 25, 2026

Copy link
Copy Markdown
Member

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)

@johnsimons
johnsimons requested a review from rbev August 25, 2026 00:20
@johnsimons johnsimons self-assigned this Aug 25, 2026
…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.
@johnsimons johnsimons changed the title Allow OpenTelemetry configuration via standard environment variables Switch to standard OpenTelemetry environment variables for OTLP configuration Aug 25, 2026
Comment thread src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs
Comment thread src/ServiceControl.Monitoring/App.config
public static class OtlpEndpoint
{
public static string MetricsEndpointFromEnvironment() =>
Read("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT") ?? Read("OTEL_EXPORTER_OTLP_ENDPOINT");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed that and mentioned it in the docs

}
var otlpEndpoint = OtlpEndpoint.MetricsEndpointFromEnvironment();

if (!Uri.TryCreate(settings.OtlpEndpointUrl, UriKind.Absolute, out var otlpEndpoint))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you confirmed that the OpenTelemetry library does indeed fail an invalid URL?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now fails if the URL is invalid, so it no longer defaults.


static string Read(string variable)
{
var value = Environment.GetEnvironmentVariable(variable);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we read through IConfiguration rather direct from env var? This would provide more flexibility to the user in how they set this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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.
@johnsimons
johnsimons merged commit 7a0f478 into master Aug 25, 2026
36 checks passed
@johnsimons
johnsimons deleted the john/otel_envvar branch August 25, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants