-
Notifications
You must be signed in to change notification settings - Fork 51
Switch to standard OpenTelemetry environment variables for OTLP configuration #5824
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
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace ServiceControl.Infrastructure; | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| public static class OtlpEndpoint | ||
| { | ||
| // This is the default environment variable name used by the OpenTelemetry .NET SDK to configure the OTLP exporter endpoint | ||
| // as specified in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md. | ||
| const string EndpointKey = "OTEL_EXPORTER_OTLP_ENDPOINT"; | ||
|
|
||
| public static Uri Read(IConfiguration configuration) | ||
| { | ||
| var configuredEndpoint = configuration[EndpointKey]; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(configuredEndpoint)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (!Uri.TryCreate(configuredEndpoint, UriKind.Absolute, out var endpoint)) | ||
| { | ||
| throw new UriFormatException($"Invalid {EndpointKey}: {configuredEndpoint}"); | ||
| } | ||
|
|
||
| return endpoint; | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...trol.Monitoring.UnitTests/ApprovalFiles/SettingsTests.PlatformSampleSettings.approved.txt
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| { | ||
| "LoggingSettings": { | ||
| "LogLevel": "Information", | ||
| "LogPath": "C:\\Logs" | ||
|
|
||
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
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 |
|---|---|---|
|
|
@@ -152,14 +152,11 @@ public static void AddIngestionMetrics(this IHostApplicationBuilder hostBuilder, | |
| { | ||
| hostBuilder.Services.AddSingleton<IngestionMetrics>(); | ||
|
|
||
| if (string.IsNullOrEmpty(settings.OtlpEndpointUrl)) | ||
| { | ||
| return; | ||
| } | ||
| var otlpEndpoint = OtlpEndpoint.Read(hostBuilder.Configuration); | ||
|
|
||
| if (!Uri.TryCreate(settings.OtlpEndpointUrl, UriKind.Absolute, out var otlpEndpoint)) | ||
|
Contributor
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. Have you confirmed that the OpenTelemetry library does indeed fail an invalid URL?
Member
Author
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. It now fails if the URL is invalid, so it no longer defaults. |
||
| if (otlpEndpoint is null) | ||
| { | ||
| throw new UriFormatException($"Invalid OtlpEndpointUrl: {settings.OtlpEndpointUrl}"); | ||
| return; | ||
| } | ||
|
|
||
| hostBuilder.Services.AddOpenTelemetry() | ||
|
|
@@ -170,7 +167,7 @@ public static void AddIngestionMetrics(this IHostApplicationBuilder hostBuilder, | |
| .WithMetrics(metrics => | ||
| { | ||
| metrics.AddIngestionMetrics(); | ||
| metrics.AddOtlpExporter(exporter => exporter.Endpoint = otlpEndpoint); | ||
| metrics.AddOtlpExporter(); | ||
|
|
||
| if (Debugger.IsAttached) | ||
| { | ||
|
|
@@ -179,7 +176,7 @@ public static void AddIngestionMetrics(this IHostApplicationBuilder hostBuilder, | |
| }); | ||
|
|
||
| LoggerUtil.CreateStaticLogger(typeof(HostApplicationBuilderExtensions), settings.LoggingSettings.LogLevel) | ||
| .LogInformation("OpenTelemetry metrics exporter enabled: {OtlpEndpointUrl}", settings.OtlpEndpointUrl); | ||
| .LogInformation("OpenTelemetry metrics exporter enabled: {OtlpEndpoint}", otlpEndpoint); | ||
| } | ||
|
|
||
| static void RecordStartup(Settings settings, EndpointConfiguration endpointConfiguration) | ||
|
|
||
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.