Skip to content

Commit 2d59315

Browse files
committed
add node integration test
1 parent 5eb68a2 commit 2d59315

3 files changed

Lines changed: 81 additions & 0 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: [{ attributes: { 'http.method': 'POST' } }],
11+
clientReportFlushInterval: 1_000,
12+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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('/keep', (_req, res) => {
11+
res.send({ status: 'kept' });
12+
setTimeout(() => {
13+
// flush to avoid waiting for the span buffer timeout to send spans
14+
// but defer it to the next tick to let the SDK finish the http.server span first.
15+
Sentry.flush();
16+
});
17+
});
18+
19+
app.post('/drop', (_req, res) => {
20+
res.send({ status: 'dropped' });
21+
});
22+
23+
Sentry.setupExpressErrorHandler(app);
24+
25+
startExpressServerAndSendPortToRunner(app);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { afterAll, describe, expect } from 'vitest';
2+
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
3+
4+
describe('filtering segment spans by attribute with ignoreSpans (streaming)', () => {
5+
afterAll(() => {
6+
cleanupChildProcesses();
7+
});
8+
9+
createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => {
10+
test('segment spans matching an attribute filter 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 /keep' && !!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+
.start();
34+
35+
const dropRes = await runner.makeRequest('post', '/drop');
36+
expect((dropRes as { status: string }).status).toBe('dropped');
37+
38+
const keepRes = await runner.makeRequest('get', '/keep');
39+
expect((keepRes as { status: string }).status).toBe('kept');
40+
41+
await runner.completed();
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)