Skip to content

test(node): Add startTransaction integration tests. #4797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../utils';
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';

test('should send a manually started transaction when @sentry/tracing is imported using unnamed import.', async () => {
const url = await runServer(__dirname);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import '@sentry/tracing';

import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
});

const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
const span_1 = transaction.startChild({
op: 'span_1',
data: {
foo: 'bar',
baz: [1, 2, 3],
},
});
for (let i = 0; i < 2000; i++);

// span_1 finishes
span_1.finish();

// span_2 doesn't finish
transaction.startChild({ op: 'span_2' });
for (let i = 0; i < 4000; i++);

const span_3 = transaction.startChild({ op: 'span_3' });
for (let i = 0; i < 4000; i++);

// span_4 is the child of span_3 but doesn't finish.
span_3.startChild({ op: 'span_4', data: { qux: 'quux' } });

// span_5 is another child of span_3 but finishes.
span_3.startChild({ op: 'span_5' }).finish();

// span_3 also finishes
span_3.finish();

transaction.finish();
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';

test('should report finished spans as children of the root transaction.', async () => {
const url = await runServer(__dirname);
const envelope = await getEnvelopeRequest(url);

expect(envelope).toHaveLength(3);

const rootSpanId = (envelope?.[2] as any)?.contexts?.trace?.span_id;
const span3Id = (envelope?.[2] as any)?.spans?.[1].span_id;

expect(rootSpanId).toEqual(expect.any(String));
expect(span3Id).toEqual(expect.any(String));

assertSentryTransaction(envelope[2], {
transaction: 'test_transaction_1',
spans: [
{
op: 'span_1',
data: {
foo: 'bar',
baz: [1, 2, 3],
},
parent_span_id: rootSpanId,
},
{
op: 'span_3',
parent_span_id: rootSpanId,
},
{
op: 'span_5',
parent_span_id: span3Id,
},
],
});
});

This file was deleted.

This file was deleted.