-
Notifications
You must be signed in to change notification settings - Fork 137
Add signal based OTLP configuration #3527
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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb2542f
Add signal based otlp configuration
RassK e8cc437
remove unused variable
RassK 5e74da0
Merge branch 'main' into refator-otlp-envs
RassK 22d914c
remove default handling from auto
RassK a873345
docs, changelog, cleanup
RassK aed056b
Merge branch 'main' into refator-otlp-envs
RassK d683972
update changelog
RassK 8c54da6
Merge branch 'main' into refator-otlp-envs
RassK e858b60
Merge branch 'main' into refator-otlp-envs
RassK 57025bd
Merge branch 'main' into refator-otlp-envs
RassK 0067968
Update CHANGELOG.md
Kielek 9ea0035
Merge branch 'main' into refator-otlp-envs
RassK c429012
Merge branch 'main' into refator-otlp-envs
Kielek 2c63183
typo fix
Kielek 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
89 changes: 89 additions & 0 deletions
89
src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSettings.cs
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,89 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.Exporter; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.Otlp; | ||
|
|
||
| /// <summary> | ||
| /// Overrides SDK logic and sets separate values for every signal | ||
| /// when more detailed environment variable is set. | ||
| /// </summary> | ||
| internal class OtlpSettings | ||
| { | ||
| public OtlpSettings(OtlpSignalType signalType, Configuration configuration) | ||
| { | ||
| Protocol = GetExporterOtlpProtocol(signalType, configuration); | ||
|
|
||
| var priorityVar = OtlpSpecConfigDefinitions.GetHeadersEnvVar(signalType); | ||
| Headers = configuration.GetString(priorityVar); | ||
|
|
||
| priorityVar = OtlpSpecConfigDefinitions.GetTimeoutEnvVar(signalType); | ||
| TimeoutMilliseconds = configuration.GetInt32(priorityVar); | ||
|
|
||
| priorityVar = OtlpSpecConfigDefinitions.GetEndpointEnvVar(signalType); | ||
| Endpoint = configuration.GetUri(priorityVar); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the OTLP transport protocol. Supported values: Grpc and HttpProtobuf. | ||
| /// </summary> | ||
| public OtlpExportProtocol? Protocol { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the optional headers for the connection. | ||
| /// </summary> | ||
| public string? Headers { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the max waiting time (in milliseconds) for the backend to | ||
| /// process each batch. Default value: <c>10000</c>. | ||
| /// </summary> | ||
| public int? TimeoutMilliseconds { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the target to which the exporter is going to send telemetry. | ||
| /// </summary> | ||
| public Uri? Endpoint { get; private set; } | ||
|
|
||
| public void CopyTo(OtlpExporterOptions options) | ||
| { | ||
| if (Protocol.HasValue) | ||
| { | ||
| options.Protocol = Protocol.Value; | ||
| } | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(Headers)) | ||
| { | ||
| options.Headers = Headers; | ||
| } | ||
|
|
||
| if (Endpoint is not null) | ||
| { | ||
| // NOTE! This must be always full path. Endpoint setter is disabling further path handling in SDK side. | ||
| options.Endpoint = Endpoint; | ||
| } | ||
|
|
||
| if (TimeoutMilliseconds.HasValue) | ||
| { | ||
| options.TimeoutMilliseconds = TimeoutMilliseconds.Value; | ||
| } | ||
| } | ||
|
|
||
| private static OtlpExportProtocol? GetExporterOtlpProtocol(OtlpSignalType signalType, Configuration configuration) | ||
| { | ||
| // the default in SDK is grpc. http/protobuf should be default for our purposes | ||
| var priorityVar = OtlpSpecConfigDefinitions.GetProtocolEnvVar(signalType); | ||
| var exporterOtlpProtocol = configuration.GetString(priorityVar) ?? | ||
| configuration.GetString(OtlpSpecConfigDefinitions.DefaultProtocolEnvVarName); | ||
|
|
||
| if (string.IsNullOrEmpty(exporterOtlpProtocol)) | ||
| { | ||
| // override settings only for http/protobuf | ||
| return OtlpExportProtocol.HttpProtobuf; | ||
| } | ||
|
|
||
| // null value here means that it will be handled by OTEL .NET SDK | ||
| return null; | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSignalType.cs
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,11 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.Otlp; | ||
|
|
||
| internal enum OtlpSignalType | ||
| { | ||
| Traces, | ||
| Metrics, | ||
| Logs | ||
| } |
65 changes: 65 additions & 0 deletions
65
src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSpecConfigDefinitions.cs
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,65 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.Otlp; | ||
|
|
||
| /// <summary> | ||
| /// Contains spec environment variable key definitions for OpenTelemetry Protocol (OTLP) exporter. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Specification: <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md"/>. | ||
| /// </remarks> | ||
| internal static class OtlpSpecConfigDefinitions | ||
| { | ||
| public const string DefaultEndpointEnvVarName = "OTEL_EXPORTER_OTLP_ENDPOINT"; | ||
| public const string DefaultHeadersEnvVarName = "OTEL_EXPORTER_OTLP_HEADERS"; | ||
| public const string DefaultTimeoutEnvVarName = "OTEL_EXPORTER_OTLP_TIMEOUT"; | ||
| public const string DefaultProtocolEnvVarName = "OTEL_EXPORTER_OTLP_PROTOCOL"; | ||
|
|
||
| public const string LogsEndpointEnvVarName = "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"; | ||
| public const string LogsHeadersEnvVarName = "OTEL_EXPORTER_OTLP_LOGS_HEADERS"; | ||
| public const string LogsTimeoutEnvVarName = "OTEL_EXPORTER_OTLP_LOGS_TIMEOUT"; | ||
| public const string LogsProtocolEnvVarName = "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL"; | ||
|
|
||
| public const string MetricsEndpointEnvVarName = "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"; | ||
| public const string MetricsHeadersEnvVarName = "OTEL_EXPORTER_OTLP_METRICS_HEADERS"; | ||
| public const string MetricsTimeoutEnvVarName = "OTEL_EXPORTER_OTLP_METRICS_TIMEOUT"; | ||
| public const string MetricsProtocolEnvVarName = "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL"; | ||
|
|
||
| public const string TracesEndpointEnvVarName = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"; | ||
| public const string TracesHeadersEnvVarName = "OTEL_EXPORTER_OTLP_TRACES_HEADERS"; | ||
| public const string TracesTimeoutEnvVarName = "OTEL_EXPORTER_OTLP_TRACES_TIMEOUT"; | ||
| public const string TracesProtocolEnvVarName = "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"; | ||
|
|
||
| public static string GetProtocolEnvVar(OtlpSignalType signal) => signal switch | ||
| { | ||
| OtlpSignalType.Traces => TracesProtocolEnvVarName, | ||
| OtlpSignalType.Metrics => MetricsProtocolEnvVarName, | ||
| OtlpSignalType.Logs => LogsProtocolEnvVarName, | ||
| _ => throw new NotSupportedException() | ||
| }; | ||
|
|
||
| public static string GetHeadersEnvVar(OtlpSignalType signal) => signal switch | ||
| { | ||
| OtlpSignalType.Traces => TracesHeadersEnvVarName, | ||
| OtlpSignalType.Metrics => MetricsHeadersEnvVarName, | ||
| OtlpSignalType.Logs => LogsHeadersEnvVarName, | ||
| _ => throw new NotSupportedException() | ||
| }; | ||
|
|
||
| public static string GetEndpointEnvVar(OtlpSignalType signal) => signal switch | ||
| { | ||
| OtlpSignalType.Traces => TracesEndpointEnvVarName, | ||
| OtlpSignalType.Metrics => MetricsEndpointEnvVarName, | ||
| OtlpSignalType.Logs => LogsEndpointEnvVarName, | ||
| _ => throw new NotSupportedException() | ||
| }; | ||
|
|
||
| public static string GetTimeoutEnvVar(OtlpSignalType signal) => signal switch | ||
| { | ||
| OtlpSignalType.Traces => TracesTimeoutEnvVarName, | ||
| OtlpSignalType.Metrics => MetricsTimeoutEnvVarName, | ||
| OtlpSignalType.Logs => LogsTimeoutEnvVarName, | ||
| _ => throw new NotSupportedException() | ||
| }; | ||
| } |
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.