-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): Fix withStreamedSpan typing error add missing exports
#20124
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
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4cba0db
fix(core): Fix `withStreamedSpan` typing error and export from SDKs
Lms24 44ea531
format
Lms24 53f5d9c
fix leftover debug init and reduce to unknown in type check
Lms24 b6e5ea9
fix integration test (not our fault but express instrumentation changed)
Lms24 ab520d6
maybe fix ts 3.8 test
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
28 changes: 28 additions & 0 deletions
28
dev-packages/browser-integration-tests/suites/public-api/beforeSendSpan-streamed/init.js
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 * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration(), Sentry.spanStreamingIntegration()], | ||
| tracesSampleRate: 1, | ||
| beforeSendSpan: Sentry.withStreamedSpan(span => { | ||
| if (span.attributes['sentry.op'] === 'pageload') { | ||
| span.name = 'customPageloadSpanName'; | ||
| span.links = [ | ||
| { | ||
| context: { | ||
| traceId: '123', | ||
| spanId: '456', | ||
| }, | ||
| attributes: { | ||
| 'sentry.link.type': 'custom_link', | ||
| }, | ||
| }, | ||
| ]; | ||
| span.attributes['sentry.custom_attribute'] = 'customAttributeValue'; | ||
| span.status = 'something'; | ||
| } | ||
| return span; | ||
| }), | ||
| }); |
35 changes: 35 additions & 0 deletions
35
dev-packages/browser-integration-tests/suites/public-api/beforeSendSpan-streamed/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,35 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { shouldSkipTracingTest, testingCdnBundle } from '../../../utils/helpers'; | ||
| import { getSpanOp, waitForStreamedSpan } from '../../../utils/spanUtils'; | ||
|
|
||
| sentryTest('beforeSendSpan applies changes to streamed span', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest() || testingCdnBundle()); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const pageloadSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'pageload'); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| const pageloadSpan = await pageloadSpanPromise; | ||
|
|
||
| expect(pageloadSpan.name).toBe('customPageloadSpanName'); | ||
| expect(pageloadSpan.links).toEqual([ | ||
| { | ||
| context: { | ||
| traceId: '123', | ||
| spanId: '456', | ||
| }, | ||
| attributes: { | ||
| 'sentry.link.type': { type: 'string', value: 'custom_link' }, | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pageloadSpan.attributes?.['sentry.custom_attribute']).toEqual({ | ||
| type: 'string', | ||
| value: 'customAttributeValue', | ||
| }); | ||
| // we allow overriding any kinds of fields on the span, so we have to expect invalid values | ||
| expect(pageloadSpan.status).toBe('something'); | ||
| }); |
43 changes: 43 additions & 0 deletions
43
...ackages/node-core-integration-tests/suites/public-api/beforeSendSpan-streamed/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,43 @@ | ||
| import * as Sentry from '@sentry/node-core'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
| import { setupOtel } from '../../../utils/setupOtel'; | ||
|
|
||
| const client = Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| tracesSampleRate: 1.0, | ||
| traceLifecycle: 'stream', | ||
| transport: loggingTransport, | ||
| release: '1.0.0', | ||
| beforeSendSpan: Sentry.withStreamedSpan(span => { | ||
| if (span.name === 'test-child-span') { | ||
| span.name = 'customChildSpanName'; | ||
| if (!span.attributes) { | ||
| span.attributes = {}; | ||
| } | ||
| span.attributes['sentry.custom_attribute'] = 'customAttributeValue'; | ||
| // oxlint-disable-next-line typescript/ban-ts-comment | ||
| // @ts-expect-error - technically this is something we have to expect, despite types saying it's invalid | ||
| span.status = 'something'; | ||
| span.links = [ | ||
| { | ||
| trace_id: '123', | ||
| span_id: '456', | ||
| attributes: { | ||
| 'sentry.link.type': 'custom_link', | ||
| }, | ||
| }, | ||
| ]; | ||
| } | ||
| return span; | ||
| }), | ||
| }); | ||
|
|
||
| setupOtel(client); | ||
|
|
||
| Sentry.startSpan({ name: 'test-span', op: 'test' }, () => { | ||
| Sentry.startSpan({ name: 'test-child-span', op: 'test-child' }, () => { | ||
| // noop | ||
| }); | ||
| }); | ||
|
|
||
| void Sentry.flush(); |
32 changes: 32 additions & 0 deletions
32
dev-packages/node-core-integration-tests/suites/public-api/beforeSendSpan-streamed/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,32 @@ | ||
| import { expect, test } from 'vitest'; | ||
| import { createRunner } from '../../../utils/runner'; | ||
|
|
||
| test('beforeSendSpan applies changes to streamed span', async () => { | ||
| await createRunner(__dirname, 'scenario.ts') | ||
| .expect({ | ||
| span: container => { | ||
| const spans = container.items; | ||
| expect(spans.length).toBe(2); | ||
|
|
||
| const customChildSpan = spans.find(s => s.name === 'customChildSpanName'); | ||
|
|
||
| expect(customChildSpan).toBeDefined(); | ||
| expect(customChildSpan!.attributes?.['sentry.custom_attribute']).toEqual({ | ||
| type: 'string', | ||
| value: 'customAttributeValue', | ||
| }); | ||
| expect(customChildSpan!.status).toBe('something'); | ||
| expect(customChildSpan!.links).toEqual([ | ||
| { | ||
| trace_id: '123', | ||
| span_id: '456', | ||
| attributes: { | ||
| 'sentry.link.type': { type: 'string', value: 'custom_link' }, | ||
| }, | ||
| }, | ||
| ]); | ||
| }, | ||
| }) | ||
| .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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| import type { BeforeSendStramedSpanCallback, ClientOptions } from '../../types-hoist/options'; | ||
| import type { CoreOptions } from '../../types-hoist/options'; | ||
| import type { BeforeSendStreamedSpanCallback, ClientOptions } from '../../types-hoist/options'; | ||
| import type { StreamedSpanJSON } from '../../types-hoist/span'; | ||
| import { addNonEnumerableProperty } from '../../utils/object'; | ||
|
|
||
| type StaticBeforeSendSpanCallback = CoreOptions['beforeSendSpan']; | ||
|
|
||
| /** | ||
| * A wrapper to use the new span format in your `beforeSendSpan` callback. | ||
| * | ||
|
|
@@ -23,9 +26,9 @@ import { addNonEnumerableProperty } from '../../utils/object'; | |
| */ | ||
| export function withStreamedSpan( | ||
| callback: (span: StreamedSpanJSON) => StreamedSpanJSON, | ||
| ): BeforeSendStramedSpanCallback { | ||
| ): StaticBeforeSendSpanCallback & { _streamed: true } { | ||
| addNonEnumerableProperty(callback, '_streamed', true); | ||
| return callback; | ||
| return callback as unknown as StaticBeforeSendSpanCallback & { _streamed: true }; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -35,7 +38,7 @@ export function withStreamedSpan( | |
| * @returns `true` if the callback was wrapped with {@link withStreamedSpan}. | ||
| */ | ||
| export function isStreamedBeforeSendSpanCallback( | ||
| callback: ClientOptions['beforeSendSpan'], | ||
| ): callback is BeforeSendStramedSpanCallback { | ||
| return !!callback && '_streamed' in callback && !!callback._streamed; | ||
| callback: (ClientOptions['beforeSendSpan'] & { _streamed?: true }) | unknown, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: is this not equivalent to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, good call, thanks! |
||
| ): callback is BeforeSendStreamedSpanCallback { | ||
| return !!callback && typeof callback === 'function' && '_streamed' in callback && !!callback._streamed; | ||
| } | ||
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
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
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.