Skip to content

Commit 7c0b479

Browse files
authored
ref(tests): Replace transaction listeners with envelope listeners. (#4565)
1 parent efc1488 commit 7c0b479

File tree

17 files changed

+58
-55
lines changed

17 files changed

+58
-55
lines changed

packages/integration-tests/suites/public-api/startTransaction/basic_usage/test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should report a transaction in an envelope', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
8-
const transaction = await getSentryTransactionRequest(page, url);
9+
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url);
910

1011
expect(transaction.transaction).toBe('test_transaction_1');
1112
expect(transaction.spans).toBeDefined();
1213
});
1314

1415
sentryTest('should report finished spans as children of the root transaction', async ({ getLocalTestPath, page }) => {
1516
const url = await getLocalTestPath({ testDir: __dirname });
16-
const transaction = await getSentryTransactionRequest(page, url);
17+
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url);
1718

1819
const rootSpanId = transaction?.contexts?.trace.spanId;
1920

packages/integration-tests/suites/tracing/browsertracing/backgroundtab-custom/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect, JSHandle } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
async function getPropertyValue(handle: JSHandle, prop: string) {
78
return (await handle.getProperty(prop))?.jsonValue();
@@ -10,7 +11,7 @@ async function getPropertyValue(handle: JSHandle, prop: string) {
1011
sentryTest('should finish a custom transaction when the page goes background', async ({ getLocalTestPath, page }) => {
1112
const url = await getLocalTestPath({ testDir: __dirname });
1213

13-
const pageloadTransaction = await getSentryTransactionRequest(page, url);
14+
const pageloadTransaction = await getFirstSentryEnvelopeRequest<Event>(page, url);
1415
expect(pageloadTransaction).toBeDefined();
1516

1617
await page.click('#start-transaction');

packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
@@ -10,7 +11,7 @@ sentryTest('should finish pageload transaction when the page goes background', a
1011

1112
page.click('#go-background');
1213

13-
const pageloadTransaction = await getSentryTransactionRequest(page);
14+
const pageloadTransaction = await getFirstSentryEnvelopeRequest<Event>(page);
1415

1516
expect(pageloadTransaction.contexts?.trace.op).toBe('pageload');
1617
expect(pageloadTransaction.contexts?.trace.status).toBe('cancelled');

packages/integration-tests/suites/tracing/browsertracing/meta/test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest(
78
'should create a pageload transaction based on `sentry-trace` <meta>',
89
async ({ getLocalTestPath, page }) => {
910
const url = await getLocalTestPath({ testDir: __dirname });
1011

11-
const eventData = await getSentryTransactionRequest(page, url);
12+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1213

1314
expect(eventData.contexts?.trace).toMatchObject({
1415
op: 'pageload',
@@ -25,8 +26,8 @@ sentryTest(
2526
async ({ getLocalTestPath, page }) => {
2627
const url = await getLocalTestPath({ testDir: __dirname });
2728

28-
const pageloadRequest = await getSentryTransactionRequest(page, url);
29-
const navigationRequest = await getSentryTransactionRequest(page, `${url}#foo`);
29+
const pageloadRequest = await getFirstSentryEnvelopeRequest<Event>(page, url);
30+
const navigationRequest = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);
3031

3132
expect(pageloadRequest.contexts?.trace).toMatchObject({
3233
op: 'pageload',

packages/integration-tests/suites/tracing/browsertracing/navigation/test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should create a navigation transaction on page navigation', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
89

9-
const pageloadRequest = await getSentryTransactionRequest(page, url);
10-
const navigationRequest = await getSentryTransactionRequest(page, `${url}#foo`);
10+
const pageloadRequest = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
const navigationRequest = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);
1112

1213
expect(pageloadRequest.contexts?.trace.op).toBe('pageload');
1314
expect(navigationRequest.contexts?.trace.op).toBe('navigation');

packages/integration-tests/suites/tracing/browsertracing/pageload/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should create a pageload transaction', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
89

9-
const eventData = await getSentryTransactionRequest(page, url);
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1011

1112
expect(eventData.contexts?.trace?.op).toBe('pageload');
1213
expect(eventData.spans?.length).toBeGreaterThan(0);

packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect, Page } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest.beforeEach(({ browserName }) => {
78
if (browserName !== 'chromium') {
@@ -23,7 +24,7 @@ async function createSessionWithLatency(page: Page, latency: number) {
2324

2425
sentryTest('should capture a `connection.rtt` metric.', async ({ getLocalTestPath, page }) => {
2526
const url = await getLocalTestPath({ testDir: __dirname });
26-
const eventData = await getSentryTransactionRequest(page, url);
27+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
2728

2829
expect(eventData.measurements).toBeDefined();
2930
expect(eventData.measurements?.['connection.rtt']?.value).toBe(0);
@@ -35,7 +36,7 @@ sentryTest(
3536
const session = await createSessionWithLatency(page, 200);
3637

3738
const url = await getLocalTestPath({ testDir: __dirname });
38-
const eventData = await getSentryTransactionRequest(page, url);
39+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
3940

4041
await session.detach();
4142

@@ -50,7 +51,7 @@ sentryTest(
5051
const session = await createSessionWithLatency(page, 100);
5152

5253
const url = await getLocalTestPath({ testDir: __dirname });
53-
const eventData = await getSentryTransactionRequest(page, url);
54+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
5455

5556
await session.detach();
5657

@@ -65,7 +66,7 @@ sentryTest(
6566
const session = await createSessionWithLatency(page, 50);
6667

6768
const url = await getLocalTestPath({ testDir: __dirname });
68-
const eventData = await getSentryTransactionRequest(page, url);
69+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
6970

7071
await session.detach();
7172

packages/integration-tests/suites/tracing/metrics/pageload-browser-spans/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should add browser-related spans to pageload transaction', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
89

9-
const eventData = await getSentryTransactionRequest(page, url);
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1011
const browserSpans = eventData.spans?.filter(({ op }) => op === 'browser');
1112

1213
// Spans `connect`, `cache` and `DNS` are not always inside `pageload` transaction.

packages/integration-tests/suites/tracing/metrics/pageload-resource-spans/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect, Route } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should add resource spans to pageload transaction', async ({ getLocalTestPath, page }) => {
78
// Intercepting asset requests to avoid network-related flakiness and random retries (on Firefox).
@@ -11,7 +12,7 @@ sentryTest('should add resource spans to pageload transaction', async ({ getLoca
1112

1213
const url = await getLocalTestPath({ testDir: __dirname });
1314

14-
const eventData = await getSentryTransactionRequest(page, url);
15+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1516
const resourceSpans = eventData.spans?.filter(({ op }) => op?.startsWith('resource'));
1617

1718
expect(resourceSpans?.length).toBe(3);

packages/integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest.beforeEach(async ({ browserName, page }) => {
78
if (browserName !== 'chromium') {
@@ -13,7 +14,7 @@ sentryTest.beforeEach(async ({ browserName, page }) => {
1314

1415
sentryTest('should capture a "GOOD" CLS vital with its source(s).', async ({ getLocalTestPath, page }) => {
1516
const url = await getLocalTestPath({ testDir: __dirname });
16-
const eventData = await getSentryTransactionRequest(page, `${url}#0.05`);
17+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#0.05`);
1718

1819
expect(eventData.measurements).toBeDefined();
1920
expect(eventData.measurements?.cls?.value).toBeDefined();
@@ -23,7 +24,7 @@ sentryTest('should capture a "GOOD" CLS vital with its source(s).', async ({ get
2324

2425
sentryTest('should capture a "MEH" CLS vital with its source(s).', async ({ getLocalTestPath, page }) => {
2526
const url = await getLocalTestPath({ testDir: __dirname });
26-
const eventData = await getSentryTransactionRequest(page, `${url}#0.21`);
27+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#0.21`);
2728

2829
expect(eventData.measurements).toBeDefined();
2930
expect(eventData.measurements?.cls?.value).toBeDefined();
@@ -33,7 +34,7 @@ sentryTest('should capture a "MEH" CLS vital with its source(s).', async ({ getL
3334

3435
sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ getLocalTestPath, page }) => {
3536
const url = await getLocalTestPath({ testDir: __dirname });
36-
const eventData = await getSentryTransactionRequest(page, `${url}#0.35`);
37+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#0.35`);
3738

3839
expect(eventData.measurements).toBeDefined();
3940
expect(eventData.measurements?.cls?.value).toBeDefined();

packages/integration-tests/suites/tracing/metrics/web-vitals-fid/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should capture a FID vital.', async ({ browserName, getLocalTestPath, page }) => {
78
// FID measurement is not generated on webkit
@@ -15,7 +16,7 @@ sentryTest('should capture a FID vital.', async ({ browserName, getLocalTestPath
1516
// To trigger FID
1617
page.click('#fid-btn');
1718

18-
const eventData = await getSentryTransactionRequest(page);
19+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
1920

2021
expect(eventData.measurements).toBeDefined();
2122
expect(eventData.measurements?.fid?.value).toBeDefined();

packages/integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should capture FP vital.', async ({ browserName, getLocalTestPath, page }) => {
78
// FP is not generated on webkit or firefox
@@ -10,7 +11,7 @@ sentryTest('should capture FP vital.', async ({ browserName, getLocalTestPath, p
1011
}
1112

1213
const url = await getLocalTestPath({ testDir: __dirname });
13-
const eventData = await getSentryTransactionRequest(page, url);
14+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1415

1516
expect(eventData.measurements).toBeDefined();
1617
expect(eventData.measurements?.fp?.value).toBeDefined();
@@ -26,7 +27,7 @@ sentryTest('should capture FP vital.', async ({ browserName, getLocalTestPath, p
2627

2728
sentryTest('should capture FCP vital.', async ({ getLocalTestPath, page }) => {
2829
const url = await getLocalTestPath({ testDir: __dirname });
29-
const eventData = await getSentryTransactionRequest(page, url);
30+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
3031

3132
expect(eventData.measurements).toBeDefined();
3233
expect(eventData.measurements?.fcp?.value).toBeDefined();

packages/integration-tests/suites/tracing/metrics/web-vitals-lcp/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect, Route } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should capture a LCP vital with element details.', async ({ browserName, getLocalTestPath, page }) => {
78
if (browserName !== 'chromium') {
@@ -17,7 +18,7 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN
1718

1819
// Force closure of LCP listener.
1920
page.click('body');
20-
const eventData = await getSentryTransactionRequest(page);
21+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
2122

2223
expect(eventData.measurements).toBeDefined();
2324
expect(eventData.measurements?.lcp?.value).toBeDefined();

packages/integration-tests/suites/tracing/metrics/web-vitals-ttfb/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should capture TTFB vital.', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
8-
const eventData = await getSentryTransactionRequest(page, url);
9+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
910

1011
expect(eventData.measurements).toBeDefined();
1112
expect(eventData.measurements?.ttfb?.value).toBeDefined();

packages/integration-tests/suites/tracing/request/fetch/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect, Request } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should create spans for multiple fetch requests', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
89

9-
const eventData = await getSentryTransactionRequest(page, url);
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1011
const requestSpans = eventData.spans?.filter(({ op }) => op === 'http.client');
1112

1213
expect(requestSpans).toHaveLength(3);

packages/integration-tests/suites/tracing/request/xhr/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect, Request } from '@playwright/test';
2+
import { Event } from '@sentry/types';
23

34
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
56

67
sentryTest('should create spans for multiple XHR requests', async ({ getLocalTestPath, page }) => {
78
const url = await getLocalTestPath({ testDir: __dirname });
89

9-
const eventData = await getSentryTransactionRequest(page, url);
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1011
const requestSpans = eventData.spans?.filter(({ op }) => op === 'http.client');
1112

1213
expect(requestSpans).toHaveLength(3);

packages/integration-tests/utils/helpers.ts

-13
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ async function getSentryRequest(page: Page, url?: string): Promise<Event> {
3535
return (await getMultipleSentryRequests(page, 1, url))[0];
3636
}
3737

38-
/**
39-
* Wait and get Sentry's request sending transaction at the given URL, or the current page
40-
*
41-
* @param {Page} page
42-
* @param {string} [url]
43-
* @return {*} {Promise<Event>}
44-
*/
45-
async function getSentryTransactionRequest(page: Page, url?: string): Promise<Event> {
46-
// TODO: Remove this and update all usages in favour of `getFirstSentryEnvelopeRequest` and `getMultipleSentryEnvelopeRequests`
47-
return (await getMultipleSentryEnvelopeRequests<Event>(page, 1, url))[0];
48-
}
49-
5038
/**
5139
* Get Sentry events at the given URL, or the current page.
5240
*
@@ -185,7 +173,6 @@ export {
185173
getMultipleSentryEnvelopeRequests,
186174
getFirstSentryEnvelopeRequest,
187175
getSentryRequest,
188-
getSentryTransactionRequest,
189176
getSentryEvents,
190177
injectScriptAndGetEvents,
191178
};

0 commit comments

Comments
 (0)