Skip to content

feat(core)!: Default attachStacktrace to true#22572

Merged
nicohrubec merged 10 commits into
developfrom
feat/attach-stacktrace-default-true
Jul 24, 2026
Merged

feat(core)!: Default attachStacktrace to true#22572
nicohrubec merged 10 commits into
developfrom
feat/attach-stacktrace-default-true

Conversation

@nicohrubec

@nicohrubec nicohrubec commented Jul 24, 2026

Copy link
Copy Markdown
Member

attachStacktrace: true is now the default. Stack traces are attached to message/string-derived events unless a user explicitly sets attachStacktrace: false.

This by default attaches a synthetic stack trace in three cases going forward:

  1. captureMessage(...): always (browser + server).
  2. captureException(<non-Error primitive, e.g. a string>): browser only (server already attached one unconditionally).
  3. captureException(<DOMException/DOMError with a .stack>): browser only.

Closes #21188

Attach synthetic stack traces by default for message/string-derived
events. Explicit `attachStacktrace: false` still opts out.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.95 kB +0.02% +3 B 🔺
@sentry/browser - with treeshaking flags 26.39 kB +0.02% +3 B 🔺
@sentry/browser (incl. Tracing) 46.41 kB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.18 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.21 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay) 85.69 kB +0.01% +6 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.33 kB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 90.4 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 103.06 kB +0.01% +4 B 🔺
@sentry/browser (incl. Feedback) 45.13 kB +0.02% +7 B 🔺
@sentry/browser (incl. sendFeedback) 32.74 kB +0.01% +2 B 🔺
@sentry/browser (incl. FeedbackAsync) 37.8 kB +0.01% +1 B 🔺
@sentry/browser (incl. Metrics) 29.04 kB +0.02% +5 B 🔺
@sentry/browser (incl. Logs) 29.26 kB +0.02% +4 B 🔺
@sentry/browser (incl. Metrics & Logs) 29.97 kB +0.05% +12 B 🔺
@sentry/react 29.75 kB +0.03% +8 B 🔺
@sentry/react (incl. Tracing) 48.71 kB +0.02% +7 B 🔺
@sentry/vue 33.38 kB +0.02% +4 B 🔺
@sentry/vue (incl. Tracing) 48.4 kB +0.01% +3 B 🔺
@sentry/svelte 27.97 kB +0.02% +4 B 🔺
CDN Bundle 30.28 kB +0.05% +13 B 🔺
CDN Bundle (incl. Tracing) 48.26 kB +0.03% +13 B 🔺
CDN Bundle (incl. Logs, Metrics) 31.85 kB +0.02% +6 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 49.58 kB +0.03% +12 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 71.13 kB +0.02% +8 B 🔺
CDN Bundle (incl. Tracing, Replay) 85.83 kB +0.02% +12 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.14 kB +0.02% +13 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.6 kB +0.02% +16 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.89 kB +0.02% +16 B 🔺
CDN Bundle - uncompressed 90.15 kB +0.06% +54 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 145.22 kB +0.04% +54 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.86 kB +0.06% +54 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.2 kB +0.04% +54 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.62 kB +0.03% +54 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.46 kB +0.03% +54 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.42 kB +0.03% +54 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.16 kB +0.02% +54 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.11 kB +0.02% +54 B 🔺
@sentry/nextjs (client) 51.24 kB +0.02% +10 B 🔺
@sentry/sveltekit (client) 46.84 kB +0.01% +1 B 🔺
@sentry/core/server 80.05 kB +0.02% +10 B 🔺
@sentry/core/browser 52.01 kB +0.03% +11 B 🔺
@sentry/node 123.1 kB +0.02% +17 B 🔺
@sentry/node (incl. diagnostics channel injection) 167.12 kB +0.01% +15 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 73.3 kB +0.02% +8 B 🔺
@sentry/aws-serverless 82.81 kB +0.02% +9 B 🔺
@sentry/cloudflare (withSentry) - minified 197.05 kB +0.02% +25 B 🔺
@sentry/cloudflare (withSentry) 484.73 kB +0.01% +31 B 🔺

View base workflow run

nicohrubec and others added 2 commits July 24, 2026 07:53
Add browser + node integration suites asserting `attachStacktrace: false`
produces no stack trace, and reword the option JSDoc to reflect that it also
applies to non-Error values passed to captureException.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
With attachStacktrace now defaulting to true, message events gained a
synthetic exception. This broke tests that assert message events have no
exception (browser captureConsole, cloudflare http-server, deno snapshots)
and node scope/DSC tests whose strict envelope ordering shifted because the
synthetic stack trace triggers async ContextLines source reads. None of
these tests concern stack traces, so opt them out with attachStacktrace:
false rather than reworking their assertions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [captureConsoleIntegration()],
attachStacktrace: false,

@nicohrubec nicohrubec Jul 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

opted out some tests that are not directly about the stacktrace before to not have to adjust the assertions, but can also switch this if we prefer to test the default case everywhere

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 you found a good balance of opting some tests out of the change while adjusting some others. No objections!

nicohrubec and others added 2 commits July 24, 2026 08:42
…on inputs

With attachStacktrace defaulting to true, non-Error values passed to
captureException (e.g. a Response) now hit the exception-building branch in
eventFromString, which set `value` to the raw object (serialized to `{}`)
instead of the readable `[object Response]` string. Pass the stringified
input so the value matches the pre-existing behavior. Also bump the deno
captureException snapshot line numbers shifted by the test-only opt-out.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e suites

An audit of all node-integration suites found four more that fire multiple
captureMessage calls and assert them in strict envelope order. With the
synthetic stack trace now attached by default, async ContextLines source
reads race and reorder emission, flaking these tests. Opt them out with
attachStacktrace: false like the others; none concern stack traces.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread packages/core/src/utils/eventbuilder.ts Outdated
Comment thread packages/browser/src/eventbuilder.ts Outdated
//
// So bail out and capture it as a simple message:
event = eventFromString(stackParser, exception as string, syntheticException, attachStacktrace);
event = eventFromString(stackParser, `${exception}`, syntheticException, attachStacktrace);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the exception string here sets event.exception.values[0].value, without this change e.g. a new Response() input to captureException() gets set directly here which is then serialized to {} instead of [object Response]

@nicohrubec
nicohrubec marked this pull request as ready for review July 24, 2026 08:23
@nicohrubec
nicohrubec requested review from a team as code owners July 24, 2026 08:23
@nicohrubec
nicohrubec requested review from Lms24, andreiborza, isaacs, logaretm and msonnb and removed request for a team July 24, 2026 08:23
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [captureConsoleIntegration()],
attachStacktrace: false,

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 you found a good balance of opting some tests out of the change while adjusting some others. No objections!

Comment thread packages/browser/src/eventbuilder.ts Outdated
Comment thread packages/core/src/utils/eventbuilder.ts Outdated

@chargome chargome 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.

Wondering if we should also incorporate frameContextLines here?

…ctor

Set attachStacktrace to true once in the base Client constructor instead of
asserting `!== false` at each stacktrace guard. The guards revert to plain
truthy checks and every SDK client inherits the default via super(). This is
easier to reason about and slightly smaller. Move the message default-on
assertion to a client-level browser test, since the eventFromMessage helper
no longer defaults on its own.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread packages/browser/src/eventbuilder.ts Outdated

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ee1271. Configure here.

Comment thread packages/browser/test/index.test.ts
nicohrubec and others added 3 commits July 24, 2026 11:55
…puts

`${exception}` throws a TypeError for Symbol inputs. Use String() instead,
which safely handles Symbols while producing identical output for all other
values. This was a pre-existing issue on the addExceptionTypeValue line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…acktrace

The pre-existing "should capture an message" test asserted no exception but
only passed due to the empty stackParser, reading as a contradiction with the
new default-case test beside it. Set attachStacktrace: false so the assertion
reflects the opt-out path explicitly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Broaden the v10->v11 migration entry to cover non-Error captureException
inputs and to call out that message/console events now mark sessions as
errored (not crashed), plus the Logs alternative for informational messages.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nicohrubec

Copy link
Copy Markdown
Member Author

@chargome if I understand correctly this is about attaching the stack frames and frameContextLines is about attaching the actual source code so should be independent

The exact-match getOptions() assertion now needs the attachStacktrace: true
default injected by the base Client constructor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nicohrubec
nicohrubec requested a review from a team as a code owner July 24, 2026 10:39
@nicohrubec nicohrubec changed the title feat(core): Default attachStacktrace to true feat(core)!: Default attachStacktrace to true Jul 24, 2026
@nicohrubec
nicohrubec merged commit 5ff9fd0 into develop Jul 24, 2026
549 of 552 checks passed
@nicohrubec
nicohrubec deleted the feat/attach-stacktrace-default-true branch July 24, 2026 11:17
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.

Default attachStacktrace to true for captureMessage

3 participants