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
Open
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe6c48c
test: Check that runtimes drop the server spans of managed tunnel req…
logaretm bd5d7ab
test(bun): Run the managed tunnel suite only with the Bun SDK
logaretm 1884646
test(node): Assert the tunnel request sends no server span at all
logaretm e81da25
test(deno): Move the Deno.serve managed tunnel test to the Deno integ…
logaretm 74fe197
test(cloudflare): Move the managed tunnel span test to a workerd inte…
logaretm 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
24 changes: 24 additions & 0 deletions
24
dev-packages/cloudflare-integration-tests/suites/tracing/managed-tunnel/index.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,24 @@ | ||
| import * as Sentry from '@sentry/cloudflare'; | ||
| import { getTunnelPath } from '@sentry/core'; | ||
|
|
||
| interface Env { | ||
| SENTRY_DSN: string; | ||
| } | ||
|
|
||
| export default Sentry.withSentry( | ||
| (env: Env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| tracesSampleRate: 1, | ||
| // A meta-framework answers the tunnel requests, the Worker only drops their server spans. | ||
| tunnel: true, | ||
| }), | ||
| { | ||
| async fetch(request, env) { | ||
| if (new URL(request.url).pathname === '/tunnel-path') { | ||
| return new Response(getTunnelPath(env.SENTRY_DSN)); | ||
| } | ||
|
|
||
| return new Response('app'); | ||
| }, | ||
| }, | ||
| ); |
25 changes: 25 additions & 0 deletions
25
dev-packages/cloudflare-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,25 @@ | ||
| import { expect, it } from 'vitest'; | ||
| import { createRunner } from '../../../runner'; | ||
| import { getSpanOp, getSpansFromEnvelope } from '../../../spanUtils'; | ||
|
|
||
| function expectServerSpanAt(path: string) { | ||
| return (envelope: Parameters<typeof getSpansFromEnvelope>[0]) => { | ||
| const serverSpans = getSpansFromEnvelope(envelope).filter(span => getSpanOp(span) === 'http.server'); | ||
|
|
||
| expect(serverSpans.map(span => span.attributes['url.path']?.value)).toEqual([path]); | ||
| }; | ||
| } | ||
|
|
||
| it('drops the server span of managed tunnel requests', async ({ signal }) => { | ||
| // Envelopes are expected in order, so a span of the tunnel request would arrive before the last one. | ||
| const runner = createRunner(__dirname) | ||
| .expect(expectServerSpanAt('/tunnel-path')) | ||
| .expect(expectServerSpanAt('/after-tunnel')) | ||
| .start(signal); | ||
|
|
||
| const tunnelPath = await runner.makeRequest<string>('get', '/tunnel-path'); | ||
| expect(await runner.makeRequest<string>('post', tunnelPath!, { data: 'envelope' })).toBe('app'); | ||
| await runner.makeRequest('get', '/after-tunnel'); | ||
|
|
||
| await runner.completed(); | ||
|
logaretm marked this conversation as resolved.
|
||
| }); | ||
6 changes: 6 additions & 0 deletions
6
dev-packages/cloudflare-integration-tests/suites/tracing/managed-tunnel/wrangler.jsonc
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,6 @@ | ||
| { | ||
| "name": "managed-tunnel", | ||
| "compatibility_date": "2025-06-17", | ||
| "main": "index.ts", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| } |
49 changes: 49 additions & 0 deletions
49
dev-packages/deno-integration-tests/suites/deno-serve-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,49 @@ | ||
| // <reference lib="deno.ns" /> | ||
|
|
||
| import { getTunnelPath } from '@sentry/core'; | ||
| import { flush, init } from '@sentry/deno'; | ||
| import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; | ||
| import { getSpanOp, resetGlobals, spanSink, withTimeout } from '../../src/index.ts'; | ||
|
|
||
| const DSN = 'https://username@domain/123'; | ||
|
|
||
| Deno.test('Deno.serve drops the server span of managed tunnel requests', async () => { | ||
| resetGlobals(); | ||
| const sink = spanSink(); | ||
|
|
||
| init({ | ||
| dsn: DSN, | ||
| tracesSampleRate: 1, | ||
| // A meta-framework answers the tunnel requests, Deno only drops their server spans. | ||
| tunnel: true, | ||
| transport: sink.transport, | ||
| }); | ||
|
|
||
| const abortController = new AbortController(); | ||
| let onListen: ((_: unknown) => void) | undefined; | ||
| const listening = new Promise(resolve => (onListen = resolve)); | ||
| const server = Deno.serve({ port: 0, signal: abortController.signal, onListen }, () => new Response('app')); | ||
| await listening; | ||
|
|
||
| try { | ||
| const baseUrl = `http://localhost:${server.addr.port}`; | ||
| const anchorSpanPromise = withTimeout( | ||
| sink.waitFor(span => getSpanOp(span) === 'http.server' && span.attributes['url.path']?.value === '/after-tunnel'), | ||
| 5_000, | ||
| 'segment span for /after-tunnel', | ||
| ); | ||
|
|
||
| await (await fetch(`${baseUrl}${getTunnelPath(DSN)}`, { method: 'POST', body: 'envelope' })).text(); | ||
| await (await fetch(`${baseUrl}/after-tunnel`)).text(); | ||
|
|
||
| await flush(); | ||
| await anchorSpanPromise; | ||
| assertEquals( | ||
| sink.spans.filter(span => getSpanOp(span) === 'http.server').map(span => span.attributes['url.path']?.value), | ||
| ['/after-tunnel'], | ||
| ); | ||
| } finally { | ||
| abortController.abort(); | ||
| await server.finished; | ||
| } | ||
| }); |
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(); | ||
| }); | ||
|
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
| 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); | ||
| }); | ||
| }); |
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.