Skip to content

[RUM-7478] Encode non-encodable attribute values as their string description#3003

Open
mariedm wants to merge 3 commits into
developfrom
marie/RUM-7478/anyencodable-string-fallback
Open

[RUM-7478] Encode non-encodable attribute values as their string description#3003
mariedm wants to merge 3 commits into
developfrom
marie/RUM-7478/anyencodable-string-fallback

Conversation

@mariedm

@mariedm mariedm commented Jun 18, 2026

Copy link
Copy Markdown
Member

What and why?

When a non-encodable value is passed as an attribute, the entire event was previously dropped. This fixes the gap for AnyEncodable by falling back to String(describing:) as a last resort, consistent with Android SDK behavior.

This is particularly relevant for cross-platform SDKs (e.g. Kotlin Multiplatform) where objects bridged from other languages aren't Swift-encodable but have a meaningful toString() / description.

How?

In AnyEncodable's default encoding case (previously a hard throw), the value's string description is now encoded instead. A debug log is emitted to inform developers when this fallback is triggered.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs - see our guidelines (internal)
  • Run make api-surface when adding new APIs

@mariedm mariedm force-pushed the marie/RUM-7478/anyencodable-string-fallback branch from 6aadd86 to 7f0dfbc Compare June 18, 2026 16:35
@datadog-prod-us1-5

This comment has been minimized.

@mariedm mariedm force-pushed the marie/RUM-7478/anyencodable-string-fallback branch 3 times, most recently from e70cb8a to 336ede1 Compare June 19, 2026 14:49
@mariedm mariedm force-pushed the marie/RUM-7478/anyencodable-string-fallback branch from 336ede1 to 8d17abd Compare June 23, 2026 12:44
@mariedm mariedm marked this pull request as ready for review June 24, 2026 09:10
@mariedm mariedm requested review from a team as code owners June 24, 2026 09:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d17abd1b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +127 to +129
let stringValue = String(describing: value)
DD.logger.debug("AnyEncodable: value of type '\(type(of: value))' is not encodable. It will be encoded as its string description: '\(stringValue)'.")
try container.encode(stringValue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Truncate fallback descriptions before encoding

When a Log user attribute wraps a non-Encodable value whose description is longer than the 25,600 UTF-16-unit attribute limit, this fallback creates and encodes the string after LogEventSanitizer has already run. The sanitizer only truncates values it can already decode as String (DatadogLogs/Sources/Log/LogEventSanitizer.swift, AttributesSanitizer.sanitizeValues), so these new fallback strings bypass the documented backend hard limit and can produce over-limit log payloads instead of the same truncated string behavior as normal string attributes.

Useful? React with 👍 / 👎.

Comment on lines +127 to +129
let stringValue = String(describing: value)
DD.logger.debug("AnyEncodable: value of type '\(type(of: value))' is not encodable. It will be encoded as its string description: '\(stringValue)'.")
try container.encode(stringValue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid double-quoting fallback span attributes

For Trace spans, non-String tag/user/account attributes are converted to strings by JSON-encoding AnyEncodable in SpanEventBuilder.castValuesToString; with this fallback, a non-encodable value whose description is foo first encodes as the JSON string "foo", and that raw JSON literal is then emitted as the meta.* value. This makes affected span attributes contain extra quote characters (unlike normal String tags, which are emitted as foo), so ObjC/manual AnyEncodable span tags no longer carry the promised string description.

Useful? React with 👍 / 👎.

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.

1 participant