[RUM-7478] Encode non-encodable attribute values as their string description#3003
[RUM-7478] Encode non-encodable attribute values as their string description#3003mariedm wants to merge 3 commits into
Conversation
6aadd86 to
7f0dfbc
Compare
This comment has been minimized.
This comment has been minimized.
e70cb8a to
336ede1
Compare
336ede1 to
8d17abd
Compare
There was a problem hiding this comment.
💡 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".
| 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) |
There was a problem hiding this comment.
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 👍 / 👎.
| 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) |
There was a problem hiding this comment.
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 👍 / 👎.
What and why?
When a non-encodable value is passed as an attribute, the entire event was previously dropped. This fixes the gap for
AnyEncodableby falling back toString(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'sdefaultencoding 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
make api-surfacewhen adding new APIs