diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index f0f9461eff6..dbea72b5ad0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -8,6 +8,10 @@ not AOT-compatible. Removed the dependency on `System.Reflection.Emit.Lightweight`. ([#4859](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4859)) +* Added support for `OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT` + and `OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT`. + ([#4887](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4887)) + ## 1.6.0 Released 2023-Sep-05 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs index 3fba6ff8cb8..028a02b5126 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs @@ -75,8 +75,8 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO otlpLogRecord.SeverityText = logRecord.Severity.Value.ToShortName(); } - var attributeValueLengthLimit = sdkLimitOptions.AttributeValueLengthLimit; - var attributeCountLimit = sdkLimitOptions.AttributeCountLimit ?? int.MaxValue; + var attributeValueLengthLimit = sdkLimitOptions.LogRecordAttributeValueLengthLimit; + var attributeCountLimit = sdkLimitOptions.LogRecordAttributeCountLimit ?? int.MaxValue; /* // Removing this temporarily for stable release diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/SdkLimitOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/SdkLimitOptions.cs index 28503c1bdad..9edfe000dab 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/SdkLimitOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/SdkLimitOptions.cs @@ -30,6 +30,10 @@ internal sealed class SdkLimitOptions private bool spanEventAttributeCountLimitSet; private int? spanLinkAttributeCountLimit; private bool spanLinkAttributeCountLimitSet; + private int? logRecordAttributeValueLengthLimit; + private bool logRecordAttributeValueLengthLimitSet; + private int? logRecordAttributeCountLimit; + private bool logRecordAttributeCountLimitSet; public SdkLimitOptions() : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) @@ -38,17 +42,21 @@ public SdkLimitOptions() internal SdkLimitOptions(IConfiguration configuration) { - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#attribute-limits + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#attribute-limits SetIntConfigValue(configuration, "OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT", value => this.AttributeValueLengthLimit = value, null); SetIntConfigValue(configuration, "OTEL_ATTRIBUTE_COUNT_LIMIT", value => this.AttributeCountLimit = value, DefaultSdkLimit); - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#span-limits + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#span-limits SetIntConfigValue(configuration, "OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT", value => this.SpanAttributeValueLengthLimit = value, null); SetIntConfigValue(configuration, "OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", value => this.SpanAttributeCountLimit = value, null); SetIntConfigValue(configuration, "OTEL_SPAN_EVENT_COUNT_LIMIT", value => this.SpanEventCountLimit = value, DefaultSdkLimit); SetIntConfigValue(configuration, "OTEL_SPAN_LINK_COUNT_LIMIT", value => this.SpanLinkCountLimit = value, DefaultSdkLimit); SetIntConfigValue(configuration, "OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT", value => this.SpanEventAttributeCountLimit = value, null); SetIntConfigValue(configuration, "OTEL_LINK_ATTRIBUTE_COUNT_LIMIT", value => this.SpanLinkAttributeCountLimit = value, null); + + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#logrecord-limits + SetIntConfigValue(configuration, "OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT", value => this.LogRecordAttributeValueLengthLimit = value, null); + SetIntConfigValue(configuration, "OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT", value => this.LogRecordAttributeCountLimit = value, null); } /// @@ -135,6 +143,38 @@ public int? SpanLinkAttributeCountLimit } } + /// + /// Gets or sets the maximum allowed log record attribute value size. + /// + /// + /// Note: Overrides the setting for log records if specified. + /// + public int? LogRecordAttributeValueLengthLimit + { + get => this.logRecordAttributeValueLengthLimitSet ? this.logRecordAttributeValueLengthLimit : this.AttributeValueLengthLimit; + set + { + this.logRecordAttributeValueLengthLimitSet = true; + this.logRecordAttributeValueLengthLimit = value; + } + } + + /// + /// Gets or sets the maximum allowed log record attribute count. + /// + /// + /// Note: Overrides the setting for log records if specified. + /// + public int? LogRecordAttributeCountLimit + { + get => this.logRecordAttributeCountLimitSet ? this.logRecordAttributeCountLimit : this.AttributeCountLimit; + set + { + this.logRecordAttributeCountLimitSet = true; + this.logRecordAttributeCountLimit = value; + } + } + private static void SetIntConfigValue(IConfiguration configuration, string key, Action setter, int? defaultValue) { if (configuration.TryGetIntValue(key, out var result)) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 7cf0d819a31..568370008e7 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -197,14 +197,14 @@ specification](https://github.com/open-telemetry/opentelemetry-specification/blo The following environment variables can be used to override the default values of the attribute limits -(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.15.0/specification/sdk-environment-variables.md#attribute-limits)). +(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.25.0/specification/configuration/sdk-environment-variables.md#attribute-limits)). * `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` * `OTEL_ATTRIBUTE_COUNT_LIMIT` The following environment variables can be used to override the default values of the span limits -(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.15.0/specification/sdk-environment-variables.md#span-limits)). +(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.25.0/specification/configuration/sdk-environment-variables.md#span-limits)). * `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` * `OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT` @@ -213,6 +213,13 @@ values of the span limits * `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT` * `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT` +The following environment variables can be used to override the default +values of the log record limits +(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.25.0/specification/configuration/sdk-environment-variables.md#logrecord-limits)). + +* `OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT` +* `OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT` + ## Configure HttpClient The `HttpClientFactory` option is provided on `OtlpExporterOptions` for users diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/SdkLimitOptionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/SdkLimitOptionsTests.cs index f496e5596c8..a0563e63202 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/SdkLimitOptionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/SdkLimitOptionsTests.cs @@ -45,6 +45,8 @@ public void SdkLimitOptionsDefaults() Assert.Equal(128, options.SpanLinkCountLimit); Assert.Equal(128, options.SpanEventAttributeCountLimit); Assert.Equal(128, options.SpanLinkAttributeCountLimit); + Assert.Null(options.LogRecordAttributeValueLengthLimit); + Assert.Equal(128, options.LogRecordAttributeCountLimit); } [Fact] @@ -79,14 +81,19 @@ public void SpanAttributeValueLengthLimitFallback() options.AttributeValueLengthLimit = 10; Assert.Equal(10, options.AttributeValueLengthLimit); Assert.Equal(10, options.SpanAttributeValueLengthLimit); + Assert.Equal(10, options.LogRecordAttributeValueLengthLimit); options.SpanAttributeValueLengthLimit = 20; + options.LogRecordAttributeValueLengthLimit = 21; Assert.Equal(10, options.AttributeValueLengthLimit); Assert.Equal(20, options.SpanAttributeValueLengthLimit); + Assert.Equal(21, options.LogRecordAttributeValueLengthLimit); options.SpanAttributeValueLengthLimit = null; + options.LogRecordAttributeValueLengthLimit = null; Assert.Equal(10, options.AttributeValueLengthLimit); Assert.Null(options.SpanAttributeValueLengthLimit); + Assert.Null(options.LogRecordAttributeValueLengthLimit); } [Fact] @@ -99,6 +106,7 @@ public void SpanAttributeCountLimitFallback() Assert.Equal(10, options.SpanAttributeCountLimit); Assert.Equal(10, options.SpanEventAttributeCountLimit); Assert.Equal(10, options.SpanLinkAttributeCountLimit); + Assert.Equal(10, options.LogRecordAttributeCountLimit); options.SpanAttributeCountLimit = 20; Assert.Equal(10, options.AttributeCountLimit); @@ -150,6 +158,8 @@ public void SdkLimitOptionsUsingIConfiguration() ["OTEL_SPAN_LINK_COUNT_LIMIT"] = "28", ["OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT"] = "29", ["OTEL_LINK_ATTRIBUTE_COUNT_LIMIT"] = "30", + ["OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT"] = "31", + ["OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT"] = "32", }; var configuration = new ConfigurationBuilder() @@ -166,6 +176,8 @@ public void SdkLimitOptionsUsingIConfiguration() Assert.Equal(28, options.SpanLinkCountLimit); Assert.Equal(29, options.SpanEventAttributeCountLimit); Assert.Equal(30, options.SpanLinkAttributeCountLimit); + Assert.Equal(31, options.LogRecordAttributeValueLengthLimit); + Assert.Equal(32, options.LogRecordAttributeCountLimit); } private static void ClearEnvVars() @@ -178,5 +190,7 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable("OTEL_SPAN_LINK_COUNT_LIMIT", null); Environment.SetEnvironmentVariable("OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT", null); Environment.SetEnvironmentVariable("OTEL_LINK_ATTRIBUTE_COUNT_LIMIT", null); + Environment.SetEnvironmentVariable("OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT", null); + Environment.SetEnvironmentVariable("OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT", null); } }