Skip to content

Commit e4f5787

Browse files
nicohrubecclaude
andcommitted
test(core): Cover attachStacktrace opt-out; clarify option docs
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>
1 parent 2b0b905 commit e4f5787

6 files changed

Lines changed: 56 additions & 2 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
attachStacktrace: false,
8+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureMessage('foo');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/core';
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('does not capture a stack trace if `attachStackTrace` is `false`', async ({ getLocalTestUrl, page }) => {
7+
const url = await getLocalTestUrl({ testDir: __dirname });
8+
9+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
10+
11+
expect(eventData.message).toBe('foo');
12+
expect(eventData.level).toBe('info');
13+
expect(eventData.exception).toBeUndefined();
14+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0',
7+
transport: loggingTransport,
8+
attachStacktrace: false,
9+
});
10+
11+
Sentry.captureMessage('Message');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { afterAll, expect, test } from 'vitest';
2+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
3+
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
test('does not capture a stack trace if `attachStackTrace` is `false`', async () => {
9+
await createRunner(__dirname, 'scenario.ts')
10+
.expect({
11+
event: event => {
12+
expect(event.message).toBe('Message');
13+
expect(event.level).toBe('info');
14+
expect(event.exception).toBeUndefined();
15+
},
16+
})
17+
.start()
18+
.completed();
19+
});

packages/core/src/types/options.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
182182
enabled?: boolean;
183183

184184
/**
185-
* Stack traces are automatically attached to all events captured with `Sentry.captureMessage`.
186-
* Set this to `false` to disable attaching stack traces to these events.
185+
* Stack traces are automatically attached to events that don't otherwise have one. This applies
186+
* to events captured with `Sentry.captureMessage` and to non-Error values passed to
187+
* `Sentry.captureException`. Set this to `false` to disable attaching these stack traces.
187188
*
188189
* Grouping in Sentry is different for events with stack traces and without. As a result, you will get
189190
* new groups as you enable or disable this flag for certain events.

0 commit comments

Comments
 (0)