Skip to content

Commit 8cdf45c

Browse files
onurtemizkanlforst
authored andcommitted
test(node): Add startTransaction integration tests(#4797)
1 parent 22b0dba commit 8cdf45c

File tree

6 files changed

+77
-25
lines changed

6 files changed

+77
-25
lines changed

packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/test.ts renamed to packages/node-integration-tests/suites/public-api/startTransaction/basic-usage/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../utils';
1+
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';
22

33
test('should send a manually started transaction when @sentry/tracing is imported using unnamed import.', async () => {
44
const url = await runServer(__dirname);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import '@sentry/tracing';
2+
3+
import * as Sentry from '@sentry/node';
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
release: '1.0',
8+
tracesSampleRate: 1.0,
9+
});
10+
11+
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
12+
const span_1 = transaction.startChild({
13+
op: 'span_1',
14+
data: {
15+
foo: 'bar',
16+
baz: [1, 2, 3],
17+
},
18+
});
19+
for (let i = 0; i < 2000; i++);
20+
21+
// span_1 finishes
22+
span_1.finish();
23+
24+
// span_2 doesn't finish
25+
transaction.startChild({ op: 'span_2' });
26+
for (let i = 0; i < 4000; i++);
27+
28+
const span_3 = transaction.startChild({ op: 'span_3' });
29+
for (let i = 0; i < 4000; i++);
30+
31+
// span_4 is the child of span_3 but doesn't finish.
32+
span_3.startChild({ op: 'span_4', data: { qux: 'quux' } });
33+
34+
// span_5 is another child of span_3 but finishes.
35+
span_3.startChild({ op: 'span_5' }).finish();
36+
37+
// span_3 also finishes
38+
span_3.finish();
39+
40+
transaction.finish();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';
2+
3+
test('should report finished spans as children of the root transaction.', async () => {
4+
const url = await runServer(__dirname);
5+
const envelope = await getEnvelopeRequest(url);
6+
7+
expect(envelope).toHaveLength(3);
8+
9+
const rootSpanId = (envelope?.[2] as any)?.contexts?.trace?.span_id;
10+
const span3Id = (envelope?.[2] as any)?.spans?.[1].span_id;
11+
12+
expect(rootSpanId).toEqual(expect.any(String));
13+
expect(span3Id).toEqual(expect.any(String));
14+
15+
assertSentryTransaction(envelope[2], {
16+
transaction: 'test_transaction_1',
17+
spans: [
18+
{
19+
op: 'span_1',
20+
data: {
21+
foo: 'bar',
22+
baz: [1, 2, 3],
23+
},
24+
parent_span_id: rootSpanId,
25+
},
26+
{
27+
op: 'span_3',
28+
parent_span_id: rootSpanId,
29+
},
30+
{
31+
op: 'span_5',
32+
parent_span_id: span3Id,
33+
},
34+
],
35+
});
36+
});

packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/scenario.ts

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

packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/test.ts

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

0 commit comments

Comments
 (0)