feat(core): Support homogeneous primitive arrays as span/metric/log attributes#20427
feat(core): Support homogeneous primitive arrays as span/metric/log attributes#20427nicohrubec wants to merge 12 commits intodevelopfrom
Conversation
Relay's wire contract (AttributeType enum in relay-event-schema) defines
exactly five `type:` tags: boolean, integer, double, string, array.
The SDK's AttributeTypeMap previously declared typed array variants
(`string[]`, `integer[]`, etc.) that Relay does not recognize - these
were never actually emitted because the runtime serializer only handled
primitives, so array-valued attributes silently dropped.
This change:
- Collapses the four `x[]` variants in AttributeTypeMap into a single
`array` variant whose value is `Array<string> | Array<number> | Array<boolean>`.
- Extends getTypedAttributeValue to auto-detect homogeneous primitive
arrays and emit `{type: 'array', value: [...]}`.
- Adds an isHomogeneousPrimitiveArray guard so mixed-type and nested
arrays remain unsupported (dropped by default, stringified under
the fallback path).
- Updates tests to cover the new typed-array path (including empty
arrays, unit preservation, and mixed-type drop/stringify).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
size-limit report 📦
|
Arrays that were previously dropped by the serializer now ship as native array attributes (`type: 'array'`). Update the affected integration test expectations and bump size-limit thresholds for the five bundle scenarios whose gzipped/uncompressed sizes grew from the new serializer logic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the size-limit increases for the five bundle scenarios that grew from adding homogeneous primitive array support. Test expectation updates from the previous commit stay. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Re-apply the size-limit bumps needed to account for the new homogeneous-primitive-array detection logic. Five scenarios grew past their thresholds: - @sentry/browser (incl. Metrics & Logs): 28 → 29 KB - CDN Bundle (incl. Logs, Metrics): 30 → 31 KB - CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed: 258.5 → 259 KB - CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed: 268 → 269 KB - CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed: 271.5 → 272 KB Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e852120. Configure here.
…72 KB Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| } | ||
| } | ||
|
|
||
| function isHomogeneousPrimitiveArray(arr: unknown): arr is Array<string> | Array<number> | Array<boolean> { |
There was a problem hiding this comment.
q: Was it previously decided that SDKs have to guarantee homogeneity? Just wondering if we really have to iterate over the entire array for every array.
There was a problem hiding this comment.
Jap fair question, we are still discussing that one 😅
|
Converting back to draft until we have a definitive answer for SDK validation. |
|
|
||
| function isHomogeneousPrimitiveArray(arr: unknown): arr is Array<string> | Array<number> | Array<boolean> { | ||
| if (!Array.isArray(arr)) return false; | ||
| if (arr.length === 0) return true; |
There was a problem hiding this comment.
q: Do we even want to send empty ones?
| if (!Array.isArray(arr)) return false; | ||
| if (arr.length === 0) return true; | ||
| const t = typeof arr[0]; | ||
| if (t !== 'string' && t !== 'number' && t !== 'boolean') return false; |
There was a problem hiding this comment.
In otel, null is allowed - we should check this with ingest

Relay and EAP now accept homogeneous arrays alongside primitive types (spec). In the SDK we currently drop any non-primitives during serialization for spans/logs/metrics. This PR adds homogeneous array support to align with the spec:
x[]variants inAttributeTypeMapinto a single array variant, matching Relay's wire contract.getTypedAttributeValueto detect homogeneous primitive arrays and emit{ type: 'array', value: [...] }. Mixed-type and nested arrays remain unsupported (dropped by default, stringified under the fallback path).Note: the Sentry frontend doesn't render array attributes correctly yet, but that's expected to land soon and this is not necessarily blocking for this PR.
Blocks #20428
Should we call this out in the changelog?