-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core)!: Make beforeSendSpan compatible with streamed spans by default
#22643
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
Draft
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5d99eac
feat(core)!: Stream beforeSendSpan payloads by default
Lms24 3380bc9
ref(core): Centralize span lifecycle and `beforeSendSpan` validation
Lms24 bf75bf3
cleanup
Lms24 065b623
fix a few oversights, jsdoc, migration
Lms24 ae953cf
account for v2 web vital spans in static mode
Lms24 fd99c4b
reword migration
Lms24 9176c4b
size limit
Lms24 b3d2fb6
remove marker type and "cheat" in `withStaticSpan` callback
Lms24 6cd4d44
fix tests
Lms24 0ec024e
remove v1 path from static spans, reword migration guide, add span st…
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
28 changes: 28 additions & 0 deletions
28
...ages/node-integration-tests/suites/public-api/beforeSendSpan-static/scenario-unwrapped.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,28 @@ | ||
| import type { SpanJSON } from '@sentry/core'; | ||
| import type { NodeOptions } from '@sentry/node'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| // Simulates a callback that was not migrated to `withStaticSpan`. The cast stands in for the | ||
| // JavaScript users who don't get a type error here. | ||
| const unmigratedBeforeSendSpan = ((span: SpanJSON) => { | ||
| span.description = 'thisShouldNotBeApplied'; | ||
| return span; | ||
| }) as unknown as NodeOptions['beforeSendSpan']; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| release: '1.0.0', | ||
| traceLifecycle: 'static', | ||
| beforeSendSpan: unmigratedBeforeSendSpan, | ||
| }); | ||
|
|
||
| Sentry.startSpan({ name: 'test-span', op: 'test' }, () => { | ||
| Sentry.startSpan({ name: 'test-child-span', op: 'test-child' }, () => { | ||
| // noop | ||
| }); | ||
| }); | ||
|
|
||
| void Sentry.flush(); |
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/public-api/beforeSendSpan-static/scenario.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,31 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| release: '1.0.0', | ||
| traceLifecycle: 'static', | ||
| beforeSendSpan: Sentry.withStaticSpan(span => { | ||
| if (span.description === 'test-child-span') { | ||
| span.description = 'customChildSpanName'; | ||
| span.data['sentry.custom_attribute'] = 'customAttributeValue'; | ||
| } | ||
|
|
||
| if (span.is_segment) { | ||
| span.description = 'customRootSpanName'; | ||
| span.data['sentry.custom_root_attribute'] = 'customRootAttributeValue'; | ||
| } | ||
|
|
||
| return span; | ||
| }), | ||
| }); | ||
|
|
||
| Sentry.startSpan({ name: 'test-span', op: 'test' }, () => { | ||
| Sentry.startSpan({ name: 'test-child-span', op: 'test-child' }, () => { | ||
| // noop | ||
| }); | ||
| }); | ||
|
|
||
| void Sentry.flush(); |
46 changes: 46 additions & 0 deletions
46
dev-packages/node-integration-tests/suites/public-api/beforeSendSpan-static/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,46 @@ | ||
| import { afterAll, expect, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('withStaticSpan applies changes to child spans', async () => { | ||
| await createRunner(__dirname, 'scenario.ts') | ||
| .expect({ | ||
| transaction: event => { | ||
| expect(event.spans).toHaveLength(1); | ||
|
|
||
| const childSpan = event.spans![0]!; | ||
| expect(childSpan.description).toBe('customChildSpanName'); | ||
| expect(childSpan.data['sentry.custom_attribute']).toBe('customAttributeValue'); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('withStaticSpan applies changes to the root span', async () => { | ||
| await createRunner(__dirname, 'scenario.ts') | ||
| .expect({ | ||
| transaction: event => { | ||
| expect(event.transaction).toBe('customRootSpanName'); | ||
| expect(event.contexts?.trace?.data?.['sentry.custom_root_attribute']).toBe('customRootAttributeValue'); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('a beforeSendSpan callback without withStaticSpan is not invoked in the static trace lifecycle', async () => { | ||
| await createRunner(__dirname, 'scenario-unwrapped.ts') | ||
| .expect({ | ||
| transaction: event => { | ||
| expect(event.transaction).toBe('test-span'); | ||
| expect(event.spans).toHaveLength(1); | ||
| expect(event.spans![0]!.description).toBe('test-child-span'); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); |
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
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
Oops, something went wrong.
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.