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

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

  • dev-packages/node-integration-tests/suites/public-api/getTracingHeadersForFetchRequest/basic-usage
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import*asSentryfrom'@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+
constheaders=getTracingHeadersForFetchRequest('https://example.com/api',{});
13+
14+
if(!headers||typeofheaders!=='object'||Array.isArray(headers)){
15+
thrownewError('getTracingHeadersForFetchRequest returned invalid headers');
16+
}
17+
18+
constsentryTrace='sentry-trace'inheaders ? headers['sentry-trace'] : undefined;
19+
constbaggage='baggage'inheaders ? headers.baggage : undefined;
20+
21+
if(!sentryTrace||typeofsentryTrace!=='string'||!sentryTrace.match(/^[0-9a-f]{32}-[0-9a-f]{16}-[01]$/)){
22+
thrownewError('sentry-trace header is invalid or missing');
23+
}
24+
25+
if(!baggage||typeofbaggage!=='string'||!baggage.includes('sentry-')){
26+
thrownewError('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+
awaitcreateRunner(__dirname,'scenario.ts')
10+
.expect({
11+
event: {
12+
message: 'test message',
13+
},
14+
})
15+
.start()
16+
.completed();
17+
});

0 commit comments

Comments
 (0)