feat(sdk): support OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT#3377
Open
bryantbiggs wants to merge 2 commits intoopen-telemetry:mainfrom
Open
feat(sdk): support OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT#3377bryantbiggs wants to merge 2 commits intoopen-telemetry:mainfrom
bryantbiggs wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3377 +/- ##
=======================================
+ Coverage 83.2% 83.4% +0.1%
=======================================
Files 128 128
Lines 25045 25319 +274
=======================================
+ Hits 20858 21123 +265
- Misses 4187 4196 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
39d7133 to
07b684f
Compare
07b684f to
29da1dd
Compare
Add support for the OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT environment variable and TracerProviderBuilder::with_max_attribute_value_length(). When configured, Value::String and Array::String attribute values are truncated to the specified number of Unicode characters (not bytes) on: - Span attributes (both at build time and via set_attribute) - Span event attributes - Span link attributes Truncation respects UTF-8 character boundaries and avoids allocations when the string is already within the limit. The limit defaults to None (unlimited) and can be set via: - The OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT env var - TracerProviderBuilder::with_max_attribute_value_length()
Move the duplicated truncation logic (3x in tracer.rs, 1x helper in span.rs) into SpanLimits::truncate_string_values(). All call sites now use the shared method. Fix SDK changelog to note the breaking SpanLimits field addition. Add opentelemetry crate changelog for new pub truncate() methods.
29da1dd to
a37a513
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMITper the SDK environment variable specification. When configured,Value::StringandArray::Stringattribute values are truncated to the specified number of Unicode characters on spans, span events, and span links.This is a spec-required feature that Go and Java SDKs have supported since their 1.0 releases. Its absence is tracked as part of #3374 (missing spec-required environment variables). The stale PR #3090 by @msierks-pcln attempted this 6+ months ago but stalled after CLA issues; this implementation incorporates the maintainer review feedback from that PR.
Supersedes #3090.
Why this belongs in a single PR
The changes span two crates but form a single logical unit:
opentelemetrycrate —Value::truncate()andStringValue::truncate()are general-purpose string truncation methods needed becauseStringValue's internal storage ispub(crate), so the SDK crate cannot manipulate it directly. These methods contain no enforcement logic — they are utilities.opentelemetry-sdkcrate — The enforcement: reading the env var, storing the limit inSpanLimits, and callingtruncate()at every attribute ingestion point (span build,set_attribute,add_event,add_link).Splitting these into separate PRs would leave the API methods without a caller, or the SDK enforcement without the methods it calls.
Design decisions
u32noti32— only positive values are meaningful (addresses feat: add support for OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT #3090 reviewer feedback)Option<u32>withNonedefault — no sentinel needed; unlimited by default per specOTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, notOTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT— the global fallback should wait until logs also support it (per maintainer feedback on feat: add support for OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT #3090: "OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT is not something we can add right now, as Logs don't respect this at all"). This is consistent with howOTEL_SPAN_ATTRIBUTE_COUNT_LIMITexists without a globalOTEL_ATTRIBUTE_COUNT_LIMITfallback in this codebase.char_indices().nth()to find the byte offset, never splits a multi-byte characterBreaking change
SpanLimitsgains a new public fieldmax_attribute_value_length: Option<u32>. Code that constructsSpanLimitsvia struct literal will need to add this field (useNonefor unlimited). This is a known limitation ofSpanLimitsnot being#[non_exhaustive], tracked in #2551.Changes
opentelemetry: addValue::truncate()andStringValue::truncate()with 8 unit testsSpanLimits: addmax_attribute_value_length: Option<u32>field andtruncate_string_values()helperConfig: readOTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMITenv var with 4 unit testsTracerProviderBuilder: addwith_max_attribute_value_length(u32)builder methodSpan/SdkTracer: apply truncation at all attribute ingestion points with 5 integration testsTest plan
StringValue::truncate: ASCII, empty, zero-length, multi-byte UTF-8 (euro sign, CJK, accented chars)Value::truncate: only affects String/Array::String, leaves bool/i64/f64 and their arrays unchangedset_attributecargo fmt --all -- --checkcargo clippy(both crates)bash ./scripts/lint.shcargo check