Skip to content

test(test-utils): Add Sentry CLI trace helpers as test-utils/cli - #24279

Merged
JPeer264 merged 4 commits into
developfrom
jp/test-utils-sentry-cli-helpers
Sep 18, 2026
Merged

JPeer264 merged 4 commits into
developfrom
jp/test-utils-sentry-cli-helpers

Conversation

@JPeer264

Copy link
Copy Markdown
Member

Adds @sentry-internal/test-utils/cli, a helper module for E2E apps that send real data to Sentry and have to wait until it is queryable. It shells out to the sentry CLI (sentry trace view <org>/<project>/<trace> --json --fresh) instead of hand-rolling requests against the organization trace endpoint, and exposes findErrorInTrace, findSpanInTrace, fetchTrace, flattenTrace, traceTarget and EVENT_POLLING_OPTIONS.

Decisions:

  • The CLI itself is a dev dependency of the consuming app (the sentry package on npm), not of test-utils. The helper runs pnpm exec sentry in the app's working directory, which keeps the 15 MB CLI out of every other test app.
  • The helper hands E2E_TEST_AUTH_TOKEN to the CLI as SENTRY_AUTH_TOKEN and sets SENTRY_FORCE_ENV_TOKEN=1. Without the flag the CLI prefers a developer's stored login over the env token, so local runs would authenticate differently from CI.
  • --fresh bypasses the CLI's response cache, which would otherwise defeat polling.
  • Exit code 23 ("not found") means the trace has not landed yet. The auth exit codes and a 401 or 403 in the output fail immediately, because waiting never fixes a token that lacks org:read.
  • A separate subpath export instead of the root index, so the dependency on the CLI stays with the apps that opt in.
  • traceTarget returns the CLI target, so a test can log a sentry trace view ... line that is paste-able into a terminal when a CI run fails.

The first consumer is the Cloudflare send-to-sentry E2E app in the follow-up PR. react-send-to-sentry and node-express-send-to-sentry keep their fetch-based copies for now and can move over separately.

Part of #23610

🤖 Generated with Claude Code

@JPeer264
JPeer264 added this pull request to stack #24281 September 10, 2026 06:29
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.09 kB - -
@sentry/browser - with treeshaking flags 27.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.26 kB - -
@sentry/browser (incl. Tracing) 50.6 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.62 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.61 kB - -
@sentry/browser (incl. Tracing, Replay) 90.15 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.25 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.85 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.83 kB - -
@sentry/browser (incl. Feedback) 46.62 kB - -
@sentry/browser (incl. sendFeedback) 34.15 kB - -
@sentry/browser (incl. FeedbackAsync) 39.26 kB - -
@sentry/browser (incl. Metrics) 30.1 kB - -
@sentry/browser (incl. Logs) 30.35 kB - -
@sentry/browser (incl. Metrics & Logs) 31.02 kB - -
@sentry/react 30.84 kB - -
@sentry/react (incl. Tracing) 52.94 kB - -
@sentry/vue 36.34 kB - -
@sentry/vue (incl. Tracing) 52.91 kB - -
@sentry/svelte 29.11 kB - -
CDN Bundle 30.8 kB - -
CDN Bundle (incl. Tracing) 51.15 kB - -
CDN Bundle (incl. Logs, Metrics) 33.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.14 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.75 kB - -
CDN Bundle (incl. Tracing, Replay) 88.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.78 kB - -
CDN Bundle - uncompressed 91.16 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.66 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.61 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.14 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 272.23 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 278.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.86 kB - -
@sentry/nextjs (client) 55.27 kB - -
@sentry/sveltekit (client) 51.05 kB - -
@sentry/core/server 39.63 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 132.37 kB +0.02% +18 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.03 kB - -
@sentry/node - without tracing 89.82 kB +0.04% +32 B 🔺
@sentry/node - without channel injection 111.23 kB +0.02% +22 B 🔺
@sentry/aws-serverless 98.06 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 204.52 kB - -
@sentry/cloudflare (withSentry) 508.73 kB - -

View base workflow run

@JPeer264
JPeer264 marked this pull request as ready for review September 11, 2026 15:11
@JPeer264 JPeer264 self-assigned this Sep 11, 2026
@JPeer264
JPeer264 force-pushed the jp/test-utils-sentry-cli-helpers branch from e333c07 to e709084 Compare September 11, 2026 15:13
Comment thread dev-packages/test-utils/src/cli.ts Outdated

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the "trace not landed" detection could be improved, but overall it's fine. The other concern (which I'm assuming is addressed in the next PR in the stack, otherwise why would you have done this? lol) is that nothing in the repo imports @sentry-internal/test-utils/cli. But assuming it does, then it's important to have it, and this PR adds it, so that's good ;)

Comment thread dev-packages/test-utils/src/cli.ts
Comment thread dev-packages/test-utils/src/cli.ts Outdated
@JPeer264

Copy link
Copy Markdown
Member Author

is that nothing in the repo imports @sentry-internal/test-utils/cli

Yeah you're right nothing does. I tried to split it up to make it easier to review :D

JPeer264 and others added 4 commits September 17, 2026 14:29
Send-to-sentry E2E apps need to wait until their data is queryable in
Sentry. The new subpath export polls through the `sentry` CLI instead of
hand-rolled requests against the trace endpoint, and gives the tests a
paste-able `sentry trace view` command for debugging.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: isaacs <i@izs.me>
Co-authored-by: isaacs <i@izs.me>
@JPeer264
JPeer264 force-pushed the jp/test-utils-sentry-cli-helpers branch from 3b11e66 to f6577bc Compare September 17, 2026 12:29
@JPeer264
JPeer264 merged commit fc7291b into develop Sep 18, 2026
562 of 564 checks passed
@JPeer264
JPeer264 deleted the jp/test-utils-sentry-cli-helpers branch September 18, 2026 09:21
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