Conversation
… the sentry CLI `sentry trace view --json` drops all attributes of a span when the trace-items endpoint returns an `int` attribute, because the endpoint sends those values as strings and the CLI's schema rejects them. Read the attributes through `sentry api` instead, and share the CLI runner with fetchTrace. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
JPeer264
added this pull request to stack #24516
September 18, 2026 18:47
JPeer264
marked this pull request as ready for review
September 18, 2026 18:49
Comment on lines
+102
to
+103
| const { attributes } = JSON.parse(result.stdout) as { attributes: { name: string; value: unknown }[] }; | ||
| return Object.fromEntries(attributes.map(({ name, value }) => [name, value])); |
Contributor
There was a problem hiding this comment.
Bug: The fetchSpanAttributes function may crash with a TypeError because it calls .map() on the attributes property from an API response without verifying its existence or type.
Severity: MEDIUM
Suggested Fix
Add a guard to check that the attributes property exists and is an array before attempting to call .map() on it. If attributes is missing or not an array, handle it gracefully, for example by treating it as an empty array or throwing a more informative error.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: dev-packages/test-utils/src/cli.ts#L102-L103
Potential issue: The `fetchSpanAttributes` function parses a JSON response from the
Sentry API and uses a TypeScript type assertion to assume the presence of an
`attributes` key. It then immediately calls `.map()` on the destructured `attributes`
property. If the API returns a successful response but the JSON body lacks the
`attributes` key, or its value is `null`, the code will throw a `TypeError` when
attempting to call `.map()` on a non-array value. This lack of a defensive check makes
the code vulnerable to crashes from unexpected but valid API response structures, such
as a future schema change.
Did we get this right? 👍 / 👎 to inform future reviews.
Contributor
size-limit report 📦
|
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.
This is helpful for the stacked PR where we add a test for workers-ai
Adds
fetchSpanAttributes(traceId, spanId)to@sentry-internal/test-utils/cli, so send-to-sentry E2E tests can assert span attributes and not only the span op.sentry trace view --jsonlooks like it returns span attributes, but it silently drops all of them for most spans: the trace-items endpoint sendsintattribute values as strings, the CLI's schema (0.44.1 and 0.45.0) expects numbers, and a failed schema check only logsCould not fetch details for span. The helper calls the same endpoint throughsentry api, which does no schema check. The spawn and credential handling moved into a shared runner so both helpers use the E2E token the same way.🤖 Generated with Claude Code