diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e00245683..83adf92d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,19 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h - Environment variables `OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED`, `OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED`, and `OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED` are now marked as deprecated. +- Support signal specific OTLP exporter variables (See [docs](/docs/config.md#otlp)): + - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, + - `OTEL_EXPORTER_OTLP_TRACES_HEADERS`, + - `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`, + - `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`, + - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`, + - `OTEL_EXPORTER_OTLP_METRICS_HEADERS`, + - `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT`, + - `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL`, + - `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`, + - `OTEL_EXPORTER_OTLP_LOGS_HEADERS`, + - `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT`, + - `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL`. ### Changed diff --git a/docs/config.md b/docs/config.md index b518e529a3..0bbe8cfad4 100644 --- a/docs/config.md +++ b/docs/config.md @@ -93,7 +93,7 @@ The following resource detectors are included and enabled by default: | `AZUREAPPSERVICE` | Azure App Service detector | [Azure resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.Azure-1.0.0-beta.8/src/OpenTelemetry.Resources.Azure/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `CONTAINER` | Container detector | [Container resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.Container-1.0.0-beta.9/src/OpenTelemetry.Resources.Container/README.md) **Not supported on .NET Framework** | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `HOST` | Host detector | [Host resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.Host-0.1.0-beta.2/src/OpenTelemetry.Resources.Host/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OPERATINGSYSTEM` | Operating System detector | [Operating System resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.OperatingSystem-0.1.0-alpha.2/src/OpenTelemetry.Resources.OperatingSystem/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OPERATINGSYSTEM` | Operating System detector | [Operating System resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.OperatingSystem-0.1.0-alpha.2/src/OpenTelemetry.Resources.OperatingSystem/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `PROCESS` | Process detector | [Process resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.Process-0.1.0-beta.2/src/OpenTelemetry.Resources.Process/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `PROCESSRUNTIME` | Process Runtime detector | [Process Runtime resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/Resources.ProcessRuntime-0.1.0-beta.2/src/OpenTelemetry.Resources.ProcessRuntime/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | @@ -300,20 +300,32 @@ To customize the OTLP exporter using environment variables, see the [OTLP exporter documentation](https://github.com/open-telemetry/opentelemetry-dotnet/tree/core-1.7.0/src/OpenTelemetry.Exporter.OpenTelemetryProtocol#environment-variables). Important environment variables include: -| Environment variable | Description | Default value | Status | -|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------| -| `OTEL_EXPORTER_OTLP_ENDPOINT` | Target endpoint for the OTLP exporter. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md) for more details. | `http://localhost:4318` for the `http/protobuf` protocol, `http://localhost:4317` for the `grpc` protocol | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP exporter transport protocol. Supported values are `grpc`, `http/protobuf`. [1] | `http/protobuf` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_EXPORTER_OTLP_TIMEOUT` | The max waiting time (in milliseconds) for the backend to process each batch. | `10000` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_EXPORTER_OTLP_HEADERS` | Comma-separated list of additional HTTP headers sent with each export, for example: `Authorization=secret,X-Key=Value`. | | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` | Maximum allowed attribute value size. | none | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed span attribute count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | Maximum allowed attribute value size. [Not applicable for metrics.](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.15.0/specification/metrics/sdk.md#attribute-limits). | none | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed span attribute count. [Not applicable for metrics.](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.15.0/specification/metrics/sdk.md#attribute-limits). | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_SPAN_EVENT_COUNT_LIMIT` | Maximum allowed span event count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_SPAN_LINK_COUNT_LIMIT` | Maximum allowed span link count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed attribute per span event count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed attribute per span link count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| Environment variable | Description | Default value | Status | +|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------| +| `OTEL_EXPORTER_OTLP_ENDPOINT` | Target endpoint for the OTLP exporter. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md) for more details. | `http/protobuf`: `http://localhost:4318`, `grpc`: `http://localhost:4317` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | Equivalent to `OTEL_EXPORTER_OTLP_ENDPOINT`, but applies only to traces. | `http/protobuf`: `http://localhost:4318/v1/traces`, `grpc`: `http://localhost:4317` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` | Equivalent to `OTEL_EXPORTER_OTLP_ENDPOINT`, but applies only to metrics. | `http/protobuf`: `http://localhost:4318/v1/metrics`, `grpc`: `http://localhost:4317` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Equivalent to `OTEL_EXPORTER_OTLP_ENDPOINT`, but applies only to logs. | `http/protobuf`: `http://localhost:4318/v1/logs`, `grpc`: `http://localhost:4317` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP exporter transport protocol. Supported values are `grpc`, `http/protobuf`. [1] | `http/protobuf` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` | Equivalent to `OTEL_EXPORTER_OTLP_PROTOCOL`, but applies only to traces. | `http/protobuf` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL` | Equivalent to `OTEL_EXPORTER_OTLP_PROTOCOL`, but applies only to metrics. | `http/protobuf` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL` | Equivalent to `OTEL_EXPORTER_OTLP_PROTOCOL`, but applies only to logs. | `http/protobuf` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_TIMEOUT` | The max waiting time (in milliseconds) for the backend to process each batch. | `10000` (10s) | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` | Equivalent to `OTEL_EXPORTER_OTLP_TIMEOUT`, but applies only to traces. | `10000` (10s) | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT` | Equivalent to `OTEL_EXPORTER_OTLP_TIMEOUT`, but applies only to metrics. | `10000` (10s) | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` | Equivalent to `OTEL_EXPORTER_OTLP_TIMEOUT`, but applies only to logs. | `10000` (10s) | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_HEADERS` | Comma-separated list of additional HTTP headers sent with each export, for example: `Authorization=secret,X-Key=Value`. | | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_TRACES_HEADERS` | Equivalent to `OTEL_EXPORTER_OTLP_HEADERS`, but applies only to traces. | | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_METRICS_HEADERS` | Equivalent to `OTEL_EXPORTER_OTLP_HEADERS`, but applies only to metrics. | | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EXPORTER_OTLP_LOGS_HEADERS` | Equivalent to `OTEL_EXPORTER_OTLP_HEADERS`, but applies only to logs. | | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` | Maximum allowed attribute value size. | none | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed span attribute count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | Maximum allowed attribute value size. [Not applicable for metrics.](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.15.0/specification/metrics/sdk.md#attribute-limits). | none | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed span attribute count. [Not applicable for metrics.](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.15.0/specification/metrics/sdk.md#attribute-limits). | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_SPAN_EVENT_COUNT_LIMIT` | Maximum allowed span event count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_SPAN_LINK_COUNT_LIMIT` | Maximum allowed span link count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed attribute per span event count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT` | Maximum allowed attribute per span link count. | 128 | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | **[1]**: Considerations on the `OTEL_EXPORTER_OTLP_PROTOCOL`: diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/Configuration.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/Configuration.cs index 3fd9b69121..8a17379050 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/Configuration.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/Configuration.cs @@ -69,4 +69,23 @@ public Configuration(bool failFast, params IConfigurationSource[] sources) return _sources.Select(source => source.GetBool(key)) .FirstOrDefault(value => value.HasValue); } + + /// + /// Gets the value of the first setting found with + /// the specified key from the current list of configuration sources. + /// Sources are queried in the order in which they were added. + /// + /// The key that identifies the setting. + /// The value of the setting, or null if not found. + public Uri? GetUri(string key) + { + var value = GetString(key); + + if (Uri.TryCreate(value, UriKind.Absolute, out var uri)) + { + return uri; + } + + return null; + } } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index 4c1770e3e5..551ac5f161 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -21,12 +21,6 @@ internal partial class ConfigurationKeys public const string ProfilingEnabled = "CORECLR_ENABLE_PROFILING"; #endif - /// - /// Configuration key for the OTLP protocol to be used. - /// Default is "http/protobuf". - /// - public const string ExporterOtlpProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL"; - /// /// Configuration key for enabling the flushing of telemetry data when an unhandled exception occurs. /// diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs index 0974313b0e..8231467a68 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationMetricHelper.cs @@ -153,10 +153,8 @@ public static MeterProviderBuilder AddOtlpExporter(MeterProviderBuilder builder, { return builder.AddOtlpExporter((options, metricReaderOptions) => { - if (settings.OtlpExportProtocol.HasValue) - { - options.Protocol = settings.OtlpExportProtocol.Value; - } + // Copy Auto settings to SDK settings + settings.OtlpSettings?.CopyTo(options); pluginManager.ConfigureMetricsOptions(options); pluginManager.ConfigureMetricsOptions(metricReaderOptions); diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs index 26b6b0e58c..cba0907e98 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/EnvironmentConfigurationTracerHelper.cs @@ -247,10 +247,8 @@ public static TracerProviderBuilder AddOtlpExporter(TracerProviderBuilder builde { return builder.AddOtlpExporter(options => { - if (settings.OtlpExportProtocol.HasValue) - { - options.Protocol = settings.OtlpExportProtocol.Value; - } + // Copy Auto settings to SDK settings + settings.OtlpSettings?.CopyTo(options); pluginManager.ConfigureTracesOptions(options); }); diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs index 03244c34e6..ef733d9fa5 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using OpenTelemetry.AutoInstrumentation.Configurations.Otlp; using OpenTelemetry.AutoInstrumentation.Logging; namespace OpenTelemetry.AutoInstrumentation.Configurations; @@ -32,11 +33,21 @@ internal class LogSettings : Settings /// public IReadOnlyList EnabledInstrumentations { get; private set; } = new List(); + /// + /// Gets logs OTLP Settings. + /// + public OtlpSettings? OtlpSettings { get; private set; } + protected override void OnLoad(Configuration configuration) { LogsEnabled = configuration.GetBool(ConfigurationKeys.Logs.LogsEnabled) ?? true; var consoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Logs.ConsoleExporterEnabled) ?? false; LogExporters = ParseLogExporter(configuration, consoleExporterEnabled); + if (LogExporters.Contains(LogExporter.Otlp)) + { + OtlpSettings = new OtlpSettings(OtlpSignalType.Logs, configuration); + } + IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false; var instrumentationEnabledByDefault = diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs index d269dfa4e6..8b6c0bedc2 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using OpenTelemetry.AutoInstrumentation.Configurations.Otlp; using OpenTelemetry.AutoInstrumentation.Logging; namespace OpenTelemetry.AutoInstrumentation.Configurations; @@ -32,10 +33,19 @@ internal class MetricSettings : Settings /// public IList Meters { get; } = new List(); + /// + /// Gets metrics OTLP Settings. + /// + public OtlpSettings? OtlpSettings { get; private set; } + protected override void OnLoad(Configuration configuration) { var consoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Metrics.ConsoleExporterEnabled) ?? false; MetricExporters = ParseMetricExporter(configuration, consoleExporterEnabled); + if (MetricExporters.Contains(MetricsExporter.Otlp)) + { + OtlpSettings = new OtlpSettings(OtlpSignalType.Metrics, configuration); + } var instrumentationEnabledByDefault = configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled) ?? diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSettings.cs new file mode 100644 index 0000000000..366ad01c8d --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSettings.cs @@ -0,0 +1,89 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using OpenTelemetry.Exporter; + +namespace OpenTelemetry.AutoInstrumentation.Configurations.Otlp; + +/// +/// Overrides SDK logic and sets separate values for every signal +/// when more detailed environment variable is set. +/// +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); + } + + /// + /// Gets the OTLP transport protocol. Supported values: Grpc and HttpProtobuf. + /// + public OtlpExportProtocol? Protocol { get; private set; } + + /// + /// Gets the optional headers for the connection. + /// + public string? Headers { get; private set; } + + /// + /// Gets the max waiting time (in milliseconds) for the backend to + /// process each batch. Default value: 10000. + /// + public int? TimeoutMilliseconds { get; private set; } + + /// + /// Gets the target to which the exporter is going to send telemetry. + /// + 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; + } +} diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSignalType.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSignalType.cs new file mode 100644 index 0000000000..1f91bce5f7 --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSignalType.cs @@ -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 +} diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSpecConfigDefinitions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSpecConfigDefinitions.cs new file mode 100644 index 0000000000..200561fda8 --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/Otlp/OtlpSpecConfigDefinitions.cs @@ -0,0 +1,65 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +namespace OpenTelemetry.AutoInstrumentation.Configurations.Otlp; + +/// +/// Contains spec environment variable key definitions for OpenTelemetry Protocol (OTLP) exporter. +/// +/// +/// Specification: . +/// +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() + }; +} diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/Settings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/Settings.cs index 5fc53eb408..eece253424 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/Settings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/Settings.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -using OpenTelemetry.Exporter; - namespace OpenTelemetry.AutoInstrumentation.Configurations; /// @@ -10,11 +8,6 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; /// internal abstract class Settings { - /// - /// Gets the the OTLP transport protocol. Supported values: Grpc and HttpProtobuf. - /// - public OtlpExportProtocol? OtlpExportProtocol { get; private set; } - public static T FromDefaultSources(bool failFast) where T : Settings, new() { @@ -26,7 +19,6 @@ public static T FromDefaultSources(bool failFast) public void Load(Configuration configuration) { - OtlpExportProtocol = GetExporterOtlpProtocol(configuration); OnLoad(configuration); } @@ -36,19 +28,4 @@ public void Load(Configuration configuration) /// /// The to use when retrieving configuration values. protected abstract void OnLoad(Configuration configuration); - - private static OtlpExportProtocol? GetExporterOtlpProtocol(Configuration configuration) - { - // the default in SDK is grpc. http/protobuf should be default for our purposes - var exporterOtlpProtocol = configuration.GetString(ConfigurationKeys.ExporterOtlpProtocol); - - if (string.IsNullOrEmpty(exporterOtlpProtocol)) - { - // override settings only for http/protobuf - return Exporter.OtlpExportProtocol.HttpProtobuf; - } - - // null value here means that it will be handled by OTEL .NET SDK - return null; - } } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs index 3a3122a450..059ac9f735 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using OpenTelemetry.AutoInstrumentation.Configurations.Otlp; using OpenTelemetry.AutoInstrumentation.Logging; namespace OpenTelemetry.AutoInstrumentation.Configurations; @@ -47,10 +48,19 @@ internal class TracerSettings : Settings /// public InstrumentationOptions InstrumentationOptions { get; private set; } = new(new Configuration(failFast: false)); + /// + /// Gets tracing OTLP Settings. + /// + public OtlpSettings? OtlpSettings { get; private set; } + protected override void OnLoad(Configuration configuration) { var consoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false; TracesExporters = ParseTracesExporter(configuration, consoleExporterEnabled); + if (TracesExporters.Contains(TracesExporter.Otlp)) + { + OtlpSettings = new OtlpSettings(OtlpSignalType.Traces, configuration); + } var instrumentationEnabledByDefault = configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationEnabled) ?? diff --git a/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs index 937dd5306c..916cb2963e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs @@ -79,10 +79,8 @@ private static void AddOpenTelemetryLogs(ILoggingBuilder builder) case LogExporter.Otlp: options.AddOtlpExporter(otlpOptions => { - if (settings.OtlpExportProtocol.HasValue) - { - otlpOptions.Protocol = settings.OtlpExportProtocol.Value; - } + // Copy Auto settings to SDK settings + settings.OtlpSettings?.CopyTo(otlpOptions); pluginManager?.ConfigureLogsOptions(otlpOptions); }); diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index 77d81efa94..8c34f8f05c 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -7,6 +7,8 @@ using OpenTelemetry.Exporter; using Xunit; +using AutoOtlpDefinitions = OpenTelemetry.AutoInstrumentation.Configurations.Otlp.OtlpSpecConfigDefinitions; + namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations; // use collection to indicate that tests should not be run @@ -35,7 +37,6 @@ internal void GeneralSettings_DefaultValues() settings.Plugins.Should().BeEmpty(); settings.EnabledResourceDetectors.Should().NotBeEmpty(); settings.FlushOnUnhandledException.Should().BeFalse(); - settings.OtlpExportProtocol.Should().Be(OtlpExportProtocol.HttpProtobuf); } } @@ -48,7 +49,6 @@ internal void TracerSettings_DefaultValues() { settings.TracesEnabled.Should().BeTrue(); settings.TracesExporters.Should().Equal(TracesExporter.Otlp); - settings.OtlpExportProtocol.Should().Be(OtlpExportProtocol.HttpProtobuf); settings.EnabledInstrumentations.Should().NotBeEmpty(); settings.ActivitySources.Should().BeEquivalentTo(new List { "OpenTelemetry.AutoInstrumentation.*" }); settings.AdditionalLegacySources.Should().BeEmpty(); @@ -70,6 +70,12 @@ internal void TracerSettings_DefaultValues() settings.InstrumentationOptions.HttpInstrumentationCaptureResponseHeaders.Should().BeEmpty(); settings.InstrumentationOptions.OracleMdaSetDbStatementForText.Should().BeFalse(); settings.InstrumentationOptions.SqlClientSetDbStatementForText.Should().BeFalse(); + + settings.OtlpSettings.Should().NotBeNull(); + settings.OtlpSettings!.Protocol.Should().Be(OtlpExportProtocol.HttpProtobuf); + settings.OtlpSettings.Endpoint.Should().BeNull(); + settings.OtlpSettings.Headers.Should().BeNull(); + settings.OtlpSettings.TimeoutMilliseconds.Should().BeNull(); } } @@ -82,9 +88,14 @@ internal void MeterSettings_DefaultValues() { settings.MetricsEnabled.Should().BeTrue(); settings.MetricExporters.Should().Equal(MetricsExporter.Otlp); - settings.OtlpExportProtocol.Should().Be(OtlpExportProtocol.HttpProtobuf); settings.EnabledInstrumentations.Should().NotBeEmpty(); settings.Meters.Should().BeEmpty(); + + settings.OtlpSettings.Should().NotBeNull(); + settings.OtlpSettings!.Protocol.Should().Be(OtlpExportProtocol.HttpProtobuf); + settings.OtlpSettings.Endpoint.Should().BeNull(); + settings.OtlpSettings.Headers.Should().BeNull(); + settings.OtlpSettings.TimeoutMilliseconds.Should().BeNull(); } } @@ -97,9 +108,14 @@ internal void LogSettings_DefaultValues() { settings.LogsEnabled.Should().BeTrue(); settings.LogExporters.Should().Equal(LogExporter.Otlp); - settings.OtlpExportProtocol.Should().Be(OtlpExportProtocol.HttpProtobuf); settings.EnabledInstrumentations.Should().NotBeEmpty(); settings.IncludeFormattedMessage.Should().BeFalse(); + + settings.OtlpSettings.Should().NotBeNull(); + settings.OtlpSettings!.Protocol.Should().Be(OtlpExportProtocol.HttpProtobuf); + settings.OtlpSettings.Endpoint.Should().BeNull(); + settings.OtlpSettings.Headers.Should().BeNull(); + settings.OtlpSettings.TimeoutMilliseconds.Should().BeNull(); } } @@ -333,12 +349,13 @@ internal void IncludeFormattedMessage_DependsOnCorrespondingEnvVariable(string i [InlineData("nonExistingProtocol", null)] internal void OtlpExportProtocol_DependsOnCorrespondingEnvVariable(string? otlpProtocol, OtlpExportProtocol? expectedOtlpExportProtocol) { - Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, otlpProtocol); + Environment.SetEnvironmentVariable(AutoOtlpDefinitions.DefaultProtocolEnvVarName, otlpProtocol); var settings = Settings.FromDefaultSources(false); // null values for expected data will be handled by OTel .NET SDK - settings.OtlpExportProtocol.Should().Be(expectedOtlpExportProtocol); + settings.OtlpSettings.Should().NotBeNull(); + settings.OtlpSettings!.Protocol.Should().Be(expectedOtlpExportProtocol); } [Theory] @@ -398,7 +415,7 @@ private static void ClearEnvVars() } Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, null); + Environment.SetEnvironmentVariable(AutoOtlpDefinitions.DefaultProtocolEnvVarName, null); Environment.SetEnvironmentVariable(ConfigurationKeys.FlushOnUnhandledException, null); Environment.SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, null);