Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Deprecate beforeSendTransaction and ignoreTransactions and log warnings if used with streaming#22908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5e3545798c58ac2415c4b21fd1c9a1f0fb1450468e3545bc23b75af6File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { ClientOptions } from '../types/options'; | ||
| import { consoleSandbox } from './debug-logger'; | ||
| /** | ||
| * Warns about `beforeSendTransaction` and `ignoreTransactions` being ignored because span streaming is enabled. | ||
| * | ||
| * Both options are tied to the transaction event that span streaming no longer produces, so they silently | ||
| * stop taking effect when users upgrade. Since that's easy to miss, this warning bypasses the `debug` logger | ||
| * (which is opt-in and stripped from non-debug bundles) and writes to the console directly. | ||
| */ | ||
| export function maybeWarnAboutIgnoredTransactionOptions(options: ClientOptions): void { | ||
| if ( | ||
| options.traceLifecycle !== 'stream' || | ||
| // oxlint-disable-next-line typescript/no-deprecated | ||
| !(options.beforeSendTransaction || options.ignoreTransactions?.length) | ||
| ) { | ||
| return; | ||
| } | ||
| consoleSandbox(() => { | ||
| // oxlint-disable-next-line no-console | ||
| console.warn( | ||
| "[Sentry] `beforeSendTransaction` and `ignoreTransactions` are ignored with `traceLifecycle: 'stream'` (enabled by default). Use `beforeSendSpan` and `ignoreSpans` instead, or set `traceLifecycle: 'static'`.", | ||
| ); | ||
| }); | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -96,6 +96,93 @@ describe('Client', () => { | ||
| }); | ||
| }); | ||
| describe('init() / transaction option warnings', () => { | ||
| test('warns about transaction options ignored by span streaming', () => { | ||
| const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); | ||
| const options = getDefaultTestClientOptions({ | ||
| dsn: PUBLIC_DSN, | ||
| traceLifecycle: 'stream', | ||
| beforeSendTransaction: event => event, | ||
| ignoreTransactions: ['/healthcheck'], | ||
| }); | ||
| new TestClient(options).init(); | ||
| expect(consoleWarnSpy).toHaveBeenCalledTimes(1); | ||
| expect(consoleWarnSpy).toHaveBeenCalledWith( | ||
| expect.stringContaining( | ||
| "`beforeSendTransaction` and `ignoreTransactions` are ignored with `traceLifecycle: 'stream'` (enabled by default).", | ||
| ), | ||
| ); | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| consoleWarnSpy.mockRestore(); | ||
| }); | ||
| test('stays silent when the client is disabled because no DSN was provided', () => { | ||
| const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); | ||
| const options = getDefaultTestClientOptions({ | ||
| traceLifecycle: 'stream', | ||
| beforeSendTransaction: event => event, | ||
| ignoreTransactions: ['/healthcheck'], | ||
| }); | ||
| new TestClient(options).init(); | ||
| expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
| consoleWarnSpy.mockRestore(); | ||
| }); | ||
| test('stays silent when the client is disabled via `enabled: false`', () => { | ||
| const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); | ||
| const options = getDefaultTestClientOptions({ | ||
| dsn: PUBLIC_DSN, | ||
| enabled: false, | ||
| traceLifecycle: 'stream', | ||
| beforeSendTransaction: event => event, | ||
| }); | ||
| new TestClient(options).init(); | ||
| expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
| consoleWarnSpy.mockRestore(); | ||
| }); | ||
| test('warns without a DSN when Spotlight is enabled, since spans are still sent', () => { | ||
| const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); | ||
| const options = getDefaultTestClientOptions({ | ||
| traceLifecycle: 'stream', | ||
| beforeSendTransaction: event => event, | ||
| integrations: [{ name: 'SpotlightBrowser' }], | ||
| }); | ||
| new TestClient(options).init(); | ||
| expect(consoleWarnSpy).toHaveBeenCalledTimes(1); | ||
| consoleWarnSpy.mockRestore(); | ||
| }); | ||
| test('stays silent when an integration falls back to the static trace lifecycle during setup', () => { | ||
| const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); | ||
| const options = getDefaultTestClientOptions({ | ||
| dsn: PUBLIC_DSN, | ||
| traceLifecycle: 'stream', | ||
| beforeSendTransaction: event => event, | ||
| integrations: [ | ||
| { | ||
| name: 'FallsBackToStatic', | ||
| setup: client => { | ||
| client.getOptions().traceLifecycle = 'static'; | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| new TestClient(options).init(); | ||
| expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
| consoleWarnSpy.mockRestore(); | ||
| }); | ||
| }); | ||
| describe('getOptions()', () => { | ||
| test('returns the options', () => { | ||
| expect.assertions(1); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { ClientOptions } from '../../../src/types/options'; | ||
| import * as debugLoggerModule from '../../../src/utils/debug-logger'; | ||
| import { maybeWarnAboutIgnoredTransactionOptions } from '../../../src/utils/warnAboutIgnoredTransactionOptions'; | ||
| describe('maybeWarnAboutIgnoredTransactionOptions', () => { | ||
| let consoleWarnSpy: ReturnType<typeof vi.spyOn>; | ||
| beforeEach(() => { | ||
| consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); | ||
| vi.spyOn(debugLoggerModule, 'consoleSandbox').mockImplementation(cb => cb()); | ||
| }); | ||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
| function options(overrides: Partial<ClientOptions>): ClientOptions { | ||
| return { integrations: [], transport: () => ({}) as never, stackParser: () => [], ...overrides } as ClientOptions; | ||
| } | ||
| it('warns when `beforeSendTransaction` is set and span streaming is enabled', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions( | ||
| options({ traceLifecycle: 'stream', beforeSendTransaction: event => event }), | ||
| ); | ||
| expect(consoleWarnSpy).toHaveBeenCalledTimes(1); | ||
| expect(consoleWarnSpy.mock.calls[0]?.[0]).toContain('`beforeSendTransaction` and `ignoreTransactions`'); | ||
| }); | ||
| it('warns when `ignoreTransactions` is set and span streaming is enabled', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions( | ||
| options({ traceLifecycle: 'stream', ignoreTransactions: ['/healthcheck'] }), | ||
| ); | ||
| expect(consoleWarnSpy).toHaveBeenCalledTimes(1); | ||
| expect(consoleWarnSpy.mock.calls[0]?.[0]).toContain('`beforeSendTransaction` and `ignoreTransactions`'); | ||
| }); | ||
| it('warns only once when both options are set', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions( | ||
| options({ | ||
| traceLifecycle: 'stream', | ||
| beforeSendTransaction: event => event, | ||
| ignoreTransactions: ['/healthcheck'], | ||
| }), | ||
| ); | ||
| expect(consoleWarnSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| it('points at the replacement options and the opt-out', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions( | ||
| options({ traceLifecycle: 'stream', beforeSendTransaction: event => event }), | ||
| ); | ||
| const message = consoleWarnSpy.mock.calls[0]?.[0]; | ||
| expect(message).toContain('`beforeSendSpan` and `ignoreSpans`'); | ||
| expect(message).toContain("`traceLifecycle: 'static'`"); | ||
| }); | ||
| it('does not warn when the trace lifecycle is static', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions( | ||
| options({ | ||
| traceLifecycle: 'static', | ||
| beforeSendTransaction: event => event, | ||
| ignoreTransactions: ['/healthcheck'], | ||
| }), | ||
| ); | ||
| expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| it('does not warn when neither option is set', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions(options({ traceLifecycle: 'stream' })); | ||
| expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| it('does not warn for an empty `ignoreTransactions` array', () => { | ||
| maybeWarnAboutIgnoredTransactionOptions(options({ traceLifecycle: 'stream', ignoreTransactions: [] })); | ||
| expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.