opentelemetry-dotnet icon indicating copy to clipboard operation
opentelemetry-dotnet copied to clipboard

[bug] Attribute Limits (SdkLimitOptions) cannot be changed programmatically

Open jordankay13 opened this issue 9 months ago • 2 comments

Package

OpenTelemetry

Package Version

Package Name Version
OpenTelemetry.Exporter.OpenTelemetryProtocol 1.11.2

Runtime Version

net462, net48

Description

According to the specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute-limits

If the SDK implements the limits above, it MUST provide a way to change these limits programmatically. Names of the configuration options SHOULD be the same as in the list below.

Environment variables could be argued as "programmable" but I would argue this should be understood as "we can set it from the application code", and not "we can set it from our infrastructure-as-code code".

The only way to affect this limit in the current OpenTelemetry.Exporter.OpenTelemetryProtocol is to set the environment variables OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_ATTRIBUTE_COUNT_LIMIT & their signal-specific equivalents.

SdkLimitOptions is internal: https://github.com/open-telemetry/opentelemetry-dotnet/blob/f63f8d93f85c185074a15b0a9a93eaf0d2e38379/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/SdkLimitOptions.cs#L8

The only OtlpTraceExporter that accepts SdkLimitOptions is also internal: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs#L47

I can't find any public method to adjust the SdkLimitOptions.

Steps to Reproduce

SdkLimitOptions is internal and cannot be accessed. No public method exists to update SpanAttributeCountLimit (or the other properties).

Expected Result

I expect to be able to change the properties of SdkLimitOptions from application code

Actual Result

I have not been able to find a way, other than through environment variables, to set this limit.

Additional Context

No response

jordankay13 avatar Mar 26 '25 16:03 jordankay13

During implementation this class should be moved to Sdk package. There is a need to find a way how to configure it programmatically, all settings should be respected by all exporters/processors(?).

Adding for the Future to avoid clossing.

@jordankay13, would you like to start working on this/contribute PR/prepare design doc how to achieve this?

Kielek avatar Nov 04 '25 09:11 Kielek

Consider exploring this too, if working on moving the limits to Sdk package:

To properly implement Attribute Limits for Span (Activity), we'd likely need some support from runtime library itself - to either enforce the limits there, or provide mechanisms to implement that in OTel.

The current implementation at the OTLP Exporter level is mainly to help scenarios where telemetry is dropped by backends due to excess size. If the goal is to limit the memory taken inside the process, then it must be implemented at the SDK level, and this would require runtime/diagnostic-source support.

cijothomas avatar Nov 04 '25 14:11 cijothomas