Skip to content

Trim span/metadata/log attribute values to backend 5000-char limit#269

Merged
ypopovych merged 1 commit into
mainfrom
yehor.popovych/span-tag-5000-limit
Jun 3, 2026
Merged

Trim span/metadata/log attribute values to backend 5000-char limit#269
ypopovych merged 1 commit into
mainfrom
yehor.popovych/span-tag-5000-limit

Conversation

@ypopovych

@ypopovych ypopovych commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

What

Enforces the backend's 5000-character-per-tag limit for spans and span metadata (and applies the same cap to log attribute values), so over-long values are truncated before upload instead of being rejected/mangled by the backend.

Changes

  • Shared constant: AttributesSanitizer.Constraints.maxAttributeValueLength = 5000 lives in the common attributes sanitizer used by all features.
  • Span tags: trimmed via AttributesSanitizer.sanitizeValues(for:), reused by both DDSpan (SpanSanitizer) and TestSpan. Numeric values (.int/.double) pass through as metrics; every other value is serialized to its description (the exact representation the encoders emit) and truncated.
  • Span metadata: SpanMetadata.trimmed(toMaxLength:) trims both keys and string values; applied when the file header is built/updated in SpansExporter.
  • Log attribute values: LogSanitizer now truncates string attribute values, referencing the shared constant.
  • TestError: crash-log split threshold now uses the shared constant instead of a hardcoded 5000.

Testing

  • SpanSanitizerTests, LogSanitizerTests, JSONEncoderTests pass (19 tests).
  • EventsExporter and DatadogSDKTesting build cleanly on macOS.

🤖 Generated with Claude Code

…r limit

The backend accepts at most 5000 characters per tag for spans and span
metadata. Add the limit as `AttributesSanitizer.Constraints.maxAttributeValueLength`
(the common sanitizer for all features) and enforce it across:

- Span tags: trim values via `AttributesSanitizer.sanitizeValues`, reused by
  both `DDSpan` (`SpanSanitizer`) and `TestSpan`. Non-numeric values are
  serialized to their `description` (the representation the encoders emit) and
  truncated; numeric values pass through as metrics.
- Span metadata: trim keys and string values via `SpanMetadata.trimmed(toMaxLength:)`,
  applied when the file header is built/updated in `SpansExporter`.
- Log attribute values: trim string values in `LogSanitizer`, referencing the
  shared constant.
- `TestError` crash-log splitting now uses the shared constant instead of a
  hardcoded 5000.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ypopovych
ypopovych requested review from a team as code owners June 1, 2026 16:39
@ypopovych
ypopovych force-pushed the yehor.popovych/span-tag-5000-limit branch from 37ab743 to 57f8fac Compare June 1, 2026 16:47
@ypopovych
ypopovych requested a review from juan-fernandez June 2, 2026 10:58
@ypopovych
ypopovych merged commit 9b16daa into main Jun 3, 2026
11 checks passed
@ypopovych
ypopovych deleted the yehor.popovych/span-tag-5000-limit branch June 3, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants