diff --git a/packages/integration-tests/suites/public-api/startTransaction/basic_usage/subject.js b/packages/integration-tests/suites/public-api/startTransaction/basic_usage/subject.js new file mode 100644 index 000000000000..c75bd2718326 --- /dev/null +++ b/packages/integration-tests/suites/public-api/startTransaction/basic_usage/subject.js @@ -0,0 +1,30 @@ +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 +const span_2 = 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. +const span_4 = span_3.startChild({ op: 'span_4', data: { qux: 'quux' } }); + +// span_5 is another child of span_3 but finishes. +const span_5 = span_3.startChild({ op: 'span_5' }).finish(); + +// span_3 also finishes +span_3.finish(); + +transaction.finish(); diff --git a/packages/integration-tests/suites/public-api/startTransaction/basic_usage/test.ts b/packages/integration-tests/suites/public-api/startTransaction/basic_usage/test.ts new file mode 100644 index 000000000000..1dc2eff3febc --- /dev/null +++ b/packages/integration-tests/suites/public-api/startTransaction/basic_usage/test.ts @@ -0,0 +1,34 @@ +import { expect } from '@playwright/test'; + +import { sentryTest } from '../../../../utils/fixtures'; +import { getSentryTransactionRequest } from '../../../../utils/helpers'; + +sentryTest('should report a transaction in an envelope', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + const transaction = await getSentryTransactionRequest(page, url); + + expect(transaction.transaction).toBe('test_transaction_1'); + expect(transaction.spans).toBeDefined(); +}); + +sentryTest('should report finished spans as children of the root transaction', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + const transaction = await getSentryTransactionRequest(page, url); + + const rootSpanId = transaction?.contexts?.trace.spanId; + + expect(transaction.spans).toHaveLength(3); + + const span_1 = transaction.spans?.[0]; + expect(span_1?.op).toBe('span_1'); + expect(span_1?.parentSpanId).toEqual(rootSpanId); + expect(span_1?.data).toMatchObject({ foo: 'bar', baz: [1, 2, 3] }); + + const span_3 = transaction.spans?.[1]; + expect(span_3?.op).toBe('span_3'); + expect(span_3?.parentSpanId).toEqual(rootSpanId); + + const span_5 = transaction.spans?.[2]; + expect(span_5?.op).toBe('span_5'); + expect(span_5?.parentSpanId).toEqual(span_3?.spanId); +}); diff --git a/packages/integration-tests/suites/public-api/startTransaction/init.js b/packages/integration-tests/suites/public-api/startTransaction/init.js new file mode 100644 index 000000000000..b326cc489bde --- /dev/null +++ b/packages/integration-tests/suites/public-api/startTransaction/init.js @@ -0,0 +1,10 @@ +import * as Sentry from '@sentry/browser'; +// eslint-disable-next-line no-unused-vars +import * as _ from '@sentry/tracing'; + +window.Sentry = Sentry; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + tracesSampleRate: 1.0, +}); diff --git a/packages/integration-tests/suites/public-api/startTransaction/template.hbs b/packages/integration-tests/suites/public-api/startTransaction/template.hbs new file mode 100644 index 000000000000..a28a09b7b485 --- /dev/null +++ b/packages/integration-tests/suites/public-api/startTransaction/template.hbs @@ -0,0 +1,11 @@ + + +
+ +