Skip to content

Commit d9fa8ba

Browse files
committed
More tests and bump size limit
1 parent 89f1ee2 commit d9fa8ba

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ module.exports = [
240240
import: createImport('init'),
241241
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
242242
gzip: true,
243-
limit: '160 KB',
243+
limit: '161 KB',
244244
},
245245
{
246246
name: '@sentry/node - without tracing',
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1,
8+
propagateTraceparent: true,
9+
transport: loggingTransport,
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
async function run() {
4+
// Wrap in span that is not sampled
5+
await Sentry.startSpan({ name: 'outer' }, async () => {
6+
await fetch(`${process.env.SERVER_URL}/api/v1`).then(res => res.text());
7+
});
8+
}
9+
10+
run();
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';
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)