Skip to content

Commit 7c34138

Browse files
cursoragentclaude
andcommitted
test(core): Add integration test for getTracingHeadersForFetchRequest
This adds an integration test that demonstrates cross-package usage of the getTracingHeadersForFetchRequest function exported from @sentry/core. The test validates that the function correctly generates tracing headers (sentry-trace and baggage) when called from another package within an active span context. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1622527 commit 7c34138

File tree

2 files changed

+47
-0
lines changed
  • dev-packages/node-integration-tests/suites/public-api/getTracingHeadersForFetchRequest/basic-usage

2 files changed

+47
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as Sentry from '@sentry/node';
2+
import { getTracingHeadersForFetchRequest } from '@sentry/core';
3+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
});
10+
11+
Sentry.startSpan({ name: 'test-span' }, () => {
12+
const headers = getTracingHeadersForFetchRequest('https://example.com/api', {});
13+
14+
if (!headers || typeof headers !== 'object' || Array.isArray(headers)) {
15+
throw new Error('getTracingHeadersForFetchRequest returned invalid headers');
16+
}
17+
18+
const sentryTrace = 'sentry-trace' in headers ? headers['sentry-trace'] : undefined;
19+
const baggage = 'baggage' in headers ? headers.baggage : undefined;
20+
21+
if (!sentryTrace || typeof sentryTrace !== 'string' || !sentryTrace.match(/^[0-9a-f]{32}-[0-9a-f]{16}-[01]$/)) {
22+
throw new Error('sentry-trace header is invalid or missing');
23+
}
24+
25+
if (!baggage || typeof baggage !== 'string' || !baggage.includes('sentry-')) {
26+
throw new Error('baggage header is invalid or missing');
27+
}
28+
29+
Sentry.captureMessage('test message');
30+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { afterAll, test } from 'vitest';
2+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
3+
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
test('should generate tracing headers for fetch request', async () => {
9+
await createRunner(__dirname, 'scenario.ts')
10+
.expect({
11+
event: {
12+
message: 'test message',
13+
},
14+
})
15+
.start()
16+
.completed();
17+
});

0 commit comments

Comments
 (0)