-
-
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
Merged
+230
−3
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e35457
feat(core): Deprecate `beforeSendTransaction` and `ignoreTransactions`
Lms24 98c58ac
cleanup
Lms24 2415c4b
streamline warning
Lms24 21fd1c9
oxlint-disable
Lms24 a1f0fb1
perf(core): Shrink the ignored-transaction-options warning
Lms24 450468e
fix(core): Skip transaction-option warning when the client is disabled
Lms24 3545bc2
remove useless comments, size limit
Lms24 3b75af6
adjust warning
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
26 changes: 26 additions & 0 deletions
26
packages/core/src/utils/warnAboutIgnoredTransactionOptions.ts
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
| 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.
|
||
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
85 changes: 85 additions & 0 deletions
85
packages/core/test/lib/utils/warnAboutIgnoredTransactionOptions.test.ts
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
| 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(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.