Skip to content

Commit c5da976

Browse files
committed
add client report generation, also for child spans, add tests for sampling
1 parent 11cfe2b commit c5da976

19 files changed

Lines changed: 403 additions & 168 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.0,
8+
transport: loggingTransport,
9+
traceLifecycle: 'stream',
10+
ignoreSpans: ['middleware - expressInit', 'custom-to-drop'],
11+
clientReportFlushInterval: 1_000,
12+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import express from 'express';
2+
import cors from 'cors';
3+
import * as Sentry from '@sentry/node';
4+
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
5+
6+
const app = express();
7+
8+
app.use(cors());
9+
10+
app.get('/test/express', (_req, res) => {
11+
Sentry.startSpan(
12+
{
13+
name: 'custom-to-drop',
14+
op: 'custom',
15+
},
16+
() => {
17+
Sentry.startSpan(
18+
{
19+
name: 'custom',
20+
op: 'custom',
21+
},
22+
() => {},
23+
);
24+
},
25+
);
26+
res.send({ response: 'response 1' });
27+
});
28+
29+
Sentry.setupExpressErrorHandler(app);
30+
31+
startExpressServerAndSendPortToRunner(app);

dev-packages/node-integration-tests/suites/tracing/ignoreSpans/children/test.ts renamed to dev-packages/node-integration-tests/suites/tracing/ignoreSpans-streamed/children/test.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import { afterAll, describe, expect, test } from 'vitest';
2-
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
1+
import { afterAll, describe, expect } from 'vitest';
2+
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
33
import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
44

55
describe('filtering child spans with ignoreSpans (streaming)', () => {
66
afterAll(() => {
77
cleanupChildProcesses();
88
});
99

10-
describe('CJS', () => {
10+
createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => {
1111
test('child spans are dropped and remaining spans correctly parented', async () => {
12-
const runner = createRunner(__dirname, 'server.js')
12+
const runner = createRunner()
13+
.unignore('client_report')
14+
.expect({
15+
client_report: {
16+
discarded_events: [
17+
{
18+
category: 'span',
19+
quantity: 2,
20+
reason: 'ignored',
21+
},
22+
],
23+
},
24+
})
1325
.expect({
1426
span: container => {
1527
// 5 spans: 1 root, 2 middleware, 1 request handler, 1 custom
@@ -44,27 +56,5 @@ describe('filtering child spans with ignoreSpans (streaming)', () => {
4456

4557
await runner.completed();
4658
});
47-
48-
test('client report contains discarded spans', async () => {
49-
const runner = createRunner(__dirname, 'server.js')
50-
.ignore('span')
51-
.unignore('client_report')
52-
.expect({
53-
client_report: {
54-
discarded_events: [
55-
{
56-
category: 'span',
57-
quantity: 2,
58-
reason: 'ignored',
59-
},
60-
],
61-
},
62-
})
63-
.start();
64-
65-
runner.makeRequest('get', '/test/express');
66-
67-
await runner.completed();
68-
});
6959
});
7060
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.0,
8+
transport: loggingTransport,
9+
traceLifecycle: 'stream',
10+
ignoreSpans: [/\/health/],
11+
clientReportFlushInterval: 1_000,
12+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import express from 'express';
2+
import cors from 'cors';
3+
import * as Sentry from '@sentry/node';
4+
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
5+
6+
const app = express();
7+
8+
app.use(cors());
9+
10+
app.get('/health', (_req, res) => {
11+
res.send({ status: 'ok-health' });
12+
});
13+
14+
app.get('/ok', (_req, res) => {
15+
res.send({ status: 'ok' });
16+
});
17+
18+
Sentry.setupExpressErrorHandler(app);
19+
20+
startExpressServerAndSendPortToRunner(app);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { afterAll, describe, expect } from 'vitest';
2+
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
3+
4+
describe('filtering segment spans with ignoreSpans (streaming)', () => {
5+
afterAll(() => {
6+
cleanupChildProcesses();
7+
});
8+
9+
createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => {
10+
test('segment spans matching ignoreSpans are dropped including all children', async () => {
11+
const runner = createRunner()
12+
.unignore('client_report')
13+
.expect({
14+
client_report: {
15+
discarded_events: [
16+
{
17+
category: 'span',
18+
quantity: 5, // 1 segment ignored + 4 child spans (implicitly ignored)
19+
reason: 'ignored',
20+
},
21+
],
22+
},
23+
})
24+
.expect({
25+
span: container => {
26+
expect(container.items).toHaveLength(5);
27+
const segmentSpan = container.items.find(s => s.name === 'GET /ok' && !!s.is_segment);
28+
29+
expect(segmentSpan).toBeDefined();
30+
expect(container.items.every(s => s.trace_id === segmentSpan!.trace_id)).toBe(true);
31+
},
32+
})
33+
34+
.start();
35+
36+
const res = await runner.makeRequest('get', '/health');
37+
expect((res as { status: string }).status).toBe('ok-health');
38+
39+
const res2 = await runner.makeRequest('get', '/ok'); // contains all spans
40+
expect((res2 as { status: string }).status).toBe('ok');
41+
42+
await runner.completed();
43+
});
44+
});
45+
});

dev-packages/node-integration-tests/suites/tracing/ignoreSpans/children/server.js

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

dev-packages/node-integration-tests/suites/tracing/ignoreSpans/segments/server.js

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

dev-packages/node-integration-tests/suites/tracing/ignoreSpans/segments/test.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
tracesSampler: ({ inheritOrSampleWith, name }) => {
8+
if (name === 'GET /health') {
9+
return inheritOrSampleWith(0);
10+
}
11+
return inheritOrSampleWith(1);
12+
},
13+
transport: loggingTransport,
14+
clientReportFlushInterval: 1_000,
15+
});

0 commit comments

Comments
 (0)