diff --git a/packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/scenario.ts b/packages/node-integration-tests/suites/public-api/startTransaction/basic-usage/scenario.ts similarity index 100% rename from packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/scenario.ts rename to packages/node-integration-tests/suites/public-api/startTransaction/basic-usage/scenario.ts diff --git a/packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/test.ts b/packages/node-integration-tests/suites/public-api/startTransaction/basic-usage/test.ts similarity index 93% rename from packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/test.ts rename to packages/node-integration-tests/suites/public-api/startTransaction/basic-usage/test.ts index db4caddd9bce..ae1bf263b27a 100644 --- a/packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/test.ts +++ b/packages/node-integration-tests/suites/public-api/startTransaction/basic-usage/test.ts @@ -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); diff --git a/packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/scenario.ts b/packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/scenario.ts new file mode 100644 index 000000000000..5fe8dd195de6 --- /dev/null +++ b/packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/scenario.ts @@ -0,0 +1,40 @@ +import '@sentry/tracing'; + +import * as Sentry from '@sentry/node'; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/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(); diff --git a/packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/test.ts b/packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/test.ts new file mode 100644 index 000000000000..4a39a9d16f4c --- /dev/null +++ b/packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/test.ts @@ -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, + }, + ], + }); +}); diff --git a/packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/scenario.ts b/packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/scenario.ts deleted file mode 100644 index 58c0a83955f0..000000000000 --- a/packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/scenario.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as Sentry from '@sentry/node'; -import * as _ from '@sentry/tracing'; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - release: '1.0', - tracesSampleRate: 1.0, -}); - -const transaction = Sentry.startTransaction({ name: 'test_transaction_1' }); - -transaction.finish(); diff --git a/packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/test.ts b/packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/test.ts deleted file mode 100644 index 0df4b0d45611..000000000000 --- a/packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../utils'; - -test.skip('should send a manually started transaction when @sentry/tracing is imported using namespace import.', async () => { - const url = await runServer(__dirname); - const envelope = await getEnvelopeRequest(url); - - expect(envelope).toHaveLength(3); - - assertSentryTransaction(envelope[2], { - transaction: 'test_transaction_1', - }); -});