Repository navigation
test: Check that runtimes drop the server spans of managed tunnel requests #25414
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
+177
−0
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions
11
dev-packages/node-integration-tests/suites/tracing/managed-tunnel/instrument.mjs
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,11 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| // A meta-framework answers the tunnel requests, Node only drops their server spans. | ||
| tunnel: true, | ||
| transport: loggingTransport, | ||
| }); |
10 changes: 10 additions & 0 deletions
10
dev-packages/node-integration-tests/suites/tracing/managed-tunnel/server.mjs
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,10 @@ | ||
| import { sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import http from 'http'; | ||
|
|
||
| const server = http.createServer((_request, response) => { | ||
| response.end('app'); | ||
| }); | ||
|
|
||
| server.listen(0, () => { | ||
| sendPortToRunner(server.address().port); | ||
| }); |
29 changes: 29 additions & 0 deletions
29
dev-packages/node-integration-tests/suites/tracing/managed-tunnel/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,29 @@ | ||
| import { URL_PATH } from '@sentry/conventions/attributes'; | ||
| import { getTunnelPath } from '@sentry/core'; | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| describe('managed tunnel', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => { | ||
| test('drops the server span of tunnel requests', async () => { | ||
| const runner = createRunner() | ||
| .expect({ | ||
| span: container => { | ||
| // Spans flush in order, so a span for the tunnel request would arrive in this container or before it. | ||
| const segmentPaths = container.items.filter(item => item.is_segment).map(item => item.attributes[URL_PATH]); | ||
| expect(segmentPaths).toEqual([{ type: 'string', value: '/after-tunnel' }]); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.makeRequest('post', getTunnelPath('https://public@dsn.ingest.sentry.io/1337')!); | ||
| await runner.makeRequest('get', '/after-tunnel'); | ||
|
|
||
| await runner.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type { TransactionEvent } from '@sentry/core'; | ||
| import * as SentryCore from '@sentry/core'; | ||
| import { afterEach, describe, expect, test } from 'bun:test'; | ||
| import { init } from '../src'; | ||
|
|
||
| const DSN = 'https://username@domain/123'; | ||
|
|
||
| describe('managed tunnel', () => { | ||
| afterEach(() => { | ||
| SentryCore.getCurrentScope().setClient(undefined); | ||
| }); | ||
|
|
||
| test('Bun.serve drops the server span of tunnel requests', async () => { | ||
| const transactions: string[] = []; | ||
| init({ | ||
| dsn: DSN, | ||
| tracesSampleRate: 1, | ||
| traceLifecycle: 'static', | ||
| // A meta-framework answers the tunnel requests, Bun only drops their server spans. | ||
| tunnel: true, | ||
| beforeSendTransaction: (event: TransactionEvent) => { | ||
| transactions.push(event.request?.url ?? ''); | ||
| return null; | ||
| }, | ||
| transport: () => | ||
| SentryCore.createTransport({ recordDroppedEvent: () => undefined }, () => SentryCore.resolvedSyncPromise({})), | ||
| }); | ||
|
|
||
| const server = Bun.serve({ port: 0, fetch: () => new Response('app') }); | ||
| const baseUrl = `http://localhost:${server.port}`; | ||
|
|
||
| const tunnelResponse = await fetch(`${baseUrl}${SentryCore.getTunnelPath(DSN)}`, { | ||
| method: 'POST', | ||
| body: 'envelope', | ||
| }); | ||
| expect(await tunnelResponse.text()).toBe('app'); | ||
| await (await fetch(`${baseUrl}/after-tunnel`)).text(); | ||
| await SentryCore.flush(); | ||
| server.stop(); | ||
|
|
||
| expect(transactions).toHaveLength(1); | ||
| expect(transactions[0]?.endsWith('/after-tunnel')).toBe(true); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // <reference lib="deno.ns" /> | ||
|
|
||
| import type { TransactionEvent } from '@sentry/core'; | ||
| import { getMainCarrier, getTunnelPath } from '@sentry/core'; | ||
| import { assertEquals } from 'https://deno.land/std@0.212.0/assert/mod.ts'; | ||
| import { init } from '../build/esm/index.js'; | ||
|
|
||
| const DSN = 'https://username@domain/123'; | ||
|
|
||
| Deno.test('Deno.serve drops the server span of managed tunnel requests', async () => { | ||
| getMainCarrier().__SENTRY__ = undefined; | ||
| const transactions: string[] = []; | ||
|
|
||
| init({ | ||
| dsn: DSN, | ||
| tracesSampleRate: 1, | ||
| traceLifecycle: 'static', | ||
| // A meta-framework answers the tunnel requests, Deno only drops their server spans. | ||
| tunnel: true, | ||
| beforeSendTransaction: (event: TransactionEvent) => { | ||
| transactions.push(event.request?.url ?? ''); | ||
| return null; | ||
| }, | ||
| }); | ||
|
|
||
| const abortController = new AbortController(); | ||
| let onListen: ((_: unknown) => void) | undefined = undefined; | ||
| const listening = new Promise(resolve => (onListen = resolve)); | ||
| const server = Deno.serve({ port: 0, signal: abortController.signal, onListen }, () => new Response('app')); | ||
| await listening; | ||
|
|
||
| const baseUrl = `http://localhost:${server.addr.port}`; | ||
| const tunnelResponse = await fetch(`${baseUrl}${getTunnelPath(DSN)}`, { method: 'POST', body: 'envelope' }); | ||
| assertEquals(await tunnelResponse.text(), 'app'); | ||
| await (await fetch(`${baseUrl}/after-tunnel`)).text(); | ||
|
|
||
| abortController.abort(); | ||
| await server.finished; | ||
|
|
||
| assertEquals(transactions.length, 1); | ||
| assertEquals(transactions[0]?.endsWith('/after-tunnel'), true); | ||
| }); |
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.