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
test(e2e): Port Bun E2E test apps to span streaming#23997
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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 |
|---|---|---|
| @@ -7,7 +7,6 @@ app.use( | ||
| sentry(app, { | ||
| dsn: process.env.SENTRY_DSN, | ||
| tracesSampleRate: 1.0, | ||
| traceLifecycle: 'static', | ||
| }), | ||
| ); | ||
89 changes: 34 additions & 55 deletions
89 dev-packages/bun-integration-tests/suites/hono-sdk/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
1 change: 0 additions & 1 deletion
1 dev-packages/e2e-tests/test-applications/bun-bytecode/src/main.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
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
79 changes: 44 additions & 35 deletions
79 dev-packages/e2e-tests/test-applications/bun-mysql/tests/mysql.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 |
|---|---|---|
| @@ -1,55 +1,64 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
| import { collectStreamedSpans, getSpanOp } from '@sentry-internal/test-utils'; | ||
| import type { SerializedStreamedSpan } from '@sentry/core'; | ||
| // `Bun.serve` without `routes` has no parameterized route, so with span streaming the | ||
| // http.server segment is named after the method only; the path lives in `url.path`. | ||
| function isTestMysqlSegment(span: SerializedStreamedSpan): boolean { | ||
| return getSpanOp(span) === 'http.server' && span.is_segment && span.attributes['url.path']?.value === '/test-mysql'; | ||
| } | ||
| test('mysql queries emit a db span with orchestrion-channel attributes', async ({ baseURL }) => { | ||
| // Each incoming request gets a Sentry http.server transaction; the mysql | ||
| // queries run inside it, so their db spans attach to that transaction. The | ||
| // channels were injected at build time by `@sentry/bun/plugin`, and the Bun | ||
| // SDK subscribes to them by default. | ||
| const transactionPromise = waitForTransaction('bun-mysql', event => { | ||
| return ( | ||
| event?.contexts?.trace?.op === 'http.server' && | ||
| (event.request?.url ?? '').includes('/test-mysql') && | ||
| (event.spans?.some(span => span.op === 'db') ?? false) | ||
| ); | ||
| }); | ||
| // Each incoming request gets a Sentry http.server segment span; the mysql | ||
| // queries run inside it, so their db spans join that trace. The channels | ||
| // were injected at build time by `@sentry/bun/plugin`, and the Bun SDK | ||
| // subscribes to them by default. | ||
| const spansPromise = collectStreamedSpans( | ||
| 'bun-mysql', | ||
| spans => spans.some(isTestMysqlSegment) && spans.some(span => getSpanOp(span) === 'db'), | ||
| ); | ||
| const res = await fetch(`${baseURL}/test-mysql`); | ||
| expect(res.status).toBe(200); | ||
| await res.json(); | ||
| const transaction = await transactionPromise; | ||
| const dbSpans = transaction.spans!.filter(span => span.op === 'db'); | ||
| const spans = await spansPromise; | ||
| const dbSpans = spans.filter(span => getSpanOp(span) === 'db'); | ||
| const firstQuery = dbSpans.find(span => span.description === 'SELECT 1 + 1 AS solution'); | ||
| const firstQuery = dbSpans.find(span => span.attributes['db.query.text']?.value === 'SELECT 1 + 1 AS solution'); | ||
| expect(firstQuery).toBeDefined(); | ||
| expect(firstQuery!.data?.['sentry.origin']).toBe('auto.db.mysql'); | ||
| expect(firstQuery!.data?.['db.system.name']).toBe('mysql'); | ||
| expect(firstQuery!.data?.['db.query.text']).toBe('SELECT 1 + 1 AS solution'); | ||
| expect(firstQuery!.data?.['server.port']).toBe(3306); | ||
| expect(firstQuery!.data?.['db.user']).toBe('root'); | ||
| // With span streaming, db span names are the low-cardinality query summary, not the raw SQL | ||
| expect(firstQuery!.name).toBe('SELECT'); | ||
| expect(firstQuery!.attributes).toMatchObject({ | ||
| 'sentry.origin': { value: 'auto.db.mysql', type: 'string' }, | ||
| 'db.system.name': { value: 'mysql', type: 'string' }, | ||
| 'db.query.text': { value: 'SELECT 1 + 1 AS solution', type: 'string' }, | ||
| 'server.port': { value: 3306, type: 'integer' }, | ||
| 'db.user': { value: 'root', type: 'string' }, | ||
| }); | ||
| }); | ||
| test('a nested query lands on the same transaction (async context restored)', async ({ baseURL }) => { | ||
| test('a nested query lands on the same trace (async context restored)', async ({ baseURL }) => { | ||
| // The second query runs inside the first query's callback — i.e. across | ||
| // mysql's async socket-callback dispatch. Both spans appearing on the SAME | ||
| // http.server transaction proves the channel subscriber restored the parent | ||
| // mysql's async socket-callback dispatch. Both db spans being children of the | ||
| // SAME http.server segment proves the channel subscriber restored the parent | ||
| // span across that async boundary (otherwise the nested query would start its | ||
| // own trace and never join this transaction). | ||
| const transactionPromise = waitForTransaction('bun-mysql', event => { | ||
| return ( | ||
| event?.contexts?.trace?.op === 'http.server' && | ||
| (event.request?.url ?? '').includes('/test-mysql') && | ||
| (event.spans?.filter(span => span.op === 'db').length ?? 0) >= 2 | ||
| ); | ||
| }); | ||
| // own trace and never join this one). | ||
| const spansPromise = collectStreamedSpans( | ||
| 'bun-mysql', | ||
| spans => spans.some(isTestMysqlSegment) && spans.filter(span => getSpanOp(span) === 'db').length >= 2, | ||
| ); | ||
| const res = await fetch(`${baseURL}/test-mysql`); | ||
| expect(res.status).toBe(200); | ||
| await res.json(); | ||
| const transaction = await transactionPromise; | ||
| const descriptions = transaction.spans!.filter(span => span.op === 'db').map(span => span.description); | ||
| expect(descriptions).toContain('SELECT 1 + 1 AS solution'); | ||
| expect(descriptions).toContain('SELECT NOW()'); | ||
| const spans = await spansPromise; | ||
| const segment = spans.find(isTestMysqlSegment)!; | ||
| const dbSpans = spans.filter(span => getSpanOp(span) === 'db'); | ||
| const queries = dbSpans.map(span => span.attributes['db.query.text']?.value); | ||
| expect(queries).toContain('SELECT 1 + 1 AS solution'); | ||
| expect(queries).toContain('SELECT NOW()'); | ||
| expect(dbSpans.every(span => span.parent_span_id === segment.span_id)).toBe(true); | ||
| }); |
1 change: 1 addition & 0 deletions
1 dev-packages/e2e-tests/test-applications/elysia-bun-static/.gitignore
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 @@ | ||
| dist |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.