Skip to content

Commit 89f1ee2

Browse files
committed
Test http
1 parent c448386 commit 89f1ee2

File tree

5 files changed

+78
-29
lines changed

5 files changed

+78
-29
lines changed

dev-packages/node-core-integration-tests/suites/tracing/requests/fetch-sampled/test.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

dev-packages/node-core-integration-tests/suites/tracing/requests/fetch-sampled/instrument.mjs renamed to dev-packages/node-core-integration-tests/suites/tracing/requests/traceparent/instrument.mjs

File renamed without changes.

dev-packages/node-core-integration-tests/suites/tracing/requests/fetch-sampled/scenario.mjs renamed to dev-packages/node-core-integration-tests/suites/tracing/requests/traceparent/scenario-fetch.mjs

File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Sentry from '@sentry/node-core';
2+
import * as http from 'http';
3+
4+
function makeHttpRequest(url) {
5+
return new Promise(resolve => {
6+
http
7+
.request(url, httpRes => {
8+
httpRes.on('data', () => {
9+
// we don't care about data
10+
});
11+
httpRes.on('end', () => {
12+
resolve();
13+
});
14+
})
15+
.end();
16+
});
17+
}
18+
19+
await Sentry.startSpan({ name: 'outer' }, async () => {
20+
await makeHttpRequest(`${process.env.SERVER_URL}/api/v1`);
21+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { describe, expect } from 'vitest';
2+
import { createEsmAndCjsTests } from '../../../../utils/runner';
3+
import { createTestServer } from '../../../../utils/server';
4+
5+
describe('outgoing traceparent', () => {
6+
createEsmAndCjsTests(__dirname, 'scenario-fetch.mjs', 'instrument.mjs', (createRunner, test) => {
7+
test('outgoing fetch requests should get traceparent headers', async () => {
8+
expect.assertions(5);
9+
10+
const [SERVER_URL, closeTestServer] = await createTestServer()
11+
.get('/api/v1', headers => {
12+
expect(headers['baggage']).toEqual(expect.any(String));
13+
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f\d]{32})-([a-f\d]{16})-1$/));
14+
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000-0');
15+
expect(headers['traceparent']).toEqual(expect.stringMatching(/^00-([a-f\d]{32})-([a-f\d]{16})-01$/));
16+
})
17+
.start();
18+
19+
await createRunner()
20+
.withEnv({ SERVER_URL })
21+
.expect({
22+
transaction: {
23+
// we're not too concerned with the actual transaction here since this is tested elsewhere
24+
},
25+
})
26+
.start()
27+
.completed();
28+
closeTestServer();
29+
});
30+
});
31+
32+
createEsmAndCjsTests(__dirname, 'scenario-http.mjs', 'instrument.mjs', (createRunner, test) => {
33+
test('outgoing http requests should get traceparent headers', async () => {
34+
expect.assertions(5);
35+
36+
const [SERVER_URL, closeTestServer] = await createTestServer()
37+
.get('/api/v1', headers => {
38+
expect(headers['baggage']).toEqual(expect.any(String));
39+
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f\d]{32})-([a-f\d]{16})-1$/));
40+
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000-0');
41+
expect(headers['traceparent']).toEqual(expect.stringMatching(/^00-([a-f\d]{32})-([a-f\d]{16})-01$/));
42+
})
43+
.start();
44+
45+
await createRunner()
46+
.withEnv({ SERVER_URL })
47+
.expect({
48+
transaction: {
49+
// we're not too concerned with the actual transaction here since this is tested elsewhere
50+
},
51+
})
52+
.start()
53+
.completed();
54+
closeTestServer();
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)