|
1 | | -import { type Page, expect, test } from '@playwright/test'; |
| 1 | +import { expect, test } from '@playwright/test'; |
2 | 2 |
|
3 | | -async function extractTraceAndBaggageFromMeta( |
4 | | - page: Page, |
5 | | -): Promise<{ sentryTrace?: string | null; sentryBaggage?: string | null }> { |
6 | | - const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
7 | | - const sentryTraceContent = await sentryTraceTag?.getAttribute('content'); |
8 | | - |
9 | | - const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
10 | | - const sentryBaggageContent = await sentryBaggageTag?.getAttribute('content'); |
11 | | - |
12 | | - return { sentryTrace: sentryTraceContent, sentryBaggage: sentryBaggageContent }; |
13 | | -} |
| 3 | +// With Server-Timing headers as the primary trace propagation method, |
| 4 | +// meta tags are no longer injected in Node.js/Cloudflare environments. |
| 5 | +// These tests verify that meta tags are NOT present for various loader types. |
14 | 6 |
|
15 | | -test('should inject `sentry-trace` and `baggage` meta tags with empty loader', async ({ page }) => { |
| 7 | +test('should NOT inject meta tags with empty loader (Server-Timing is used instead)', async ({ page }) => { |
16 | 8 | await page.goto('/?type=empty'); |
17 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
18 | 9 |
|
19 | | - expect(sentryTrace).toMatch(/.+/); |
20 | | - expect(sentryBaggage).toMatch(/.+/); |
| 10 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 11 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 12 | + |
| 13 | + // Meta tags should not be present - Server-Timing headers are used instead |
| 14 | + expect(sentryTraceTag).toBeNull(); |
| 15 | + expect(sentryBaggageTag).toBeNull(); |
21 | 16 | }); |
22 | 17 |
|
23 | | -test('should inject `sentry-trace` and `baggage` meta tags with plain object loader', async ({ page }) => { |
| 18 | +test('should NOT inject meta tags with plain object loader (Server-Timing is used instead)', async ({ page }) => { |
24 | 19 | await page.goto('/?type=plain'); |
25 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
26 | 20 |
|
27 | | - expect(sentryTrace).toMatch(/.+/); |
28 | | - expect(sentryBaggage).toMatch(/.+/); |
| 21 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 22 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 23 | + |
| 24 | + expect(sentryTraceTag).toBeNull(); |
| 25 | + expect(sentryBaggageTag).toBeNull(); |
29 | 26 | }); |
30 | 27 |
|
31 | | -test('should inject `sentry-trace` and `baggage` meta tags with JSON response loader', async ({ page }) => { |
| 28 | +test('should NOT inject meta tags with JSON response loader (Server-Timing is used instead)', async ({ page }) => { |
32 | 29 | await page.goto('/?type=json'); |
33 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
34 | 30 |
|
35 | | - expect(sentryTrace).toMatch(/.+/); |
36 | | - expect(sentryBaggage).toMatch(/.+/); |
| 31 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 32 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 33 | + |
| 34 | + expect(sentryTraceTag).toBeNull(); |
| 35 | + expect(sentryBaggageTag).toBeNull(); |
37 | 36 | }); |
38 | 37 |
|
39 | | -test('should inject `sentry-trace` and `baggage` meta tags with deferred response loader', async ({ page }) => { |
| 38 | +test('should NOT inject meta tags with deferred response loader (Server-Timing is used instead)', async ({ page }) => { |
40 | 39 | await page.goto('/?type=defer'); |
41 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
42 | 40 |
|
43 | | - expect(sentryTrace).toMatch(/.+/); |
44 | | - expect(sentryBaggage).toMatch(/.+/); |
| 41 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 42 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 43 | + |
| 44 | + expect(sentryTraceTag).toBeNull(); |
| 45 | + expect(sentryBaggageTag).toBeNull(); |
45 | 46 | }); |
46 | 47 |
|
47 | | -test('should inject `sentry-trace` and `baggage` meta tags with null loader', async ({ page }) => { |
| 48 | +test('should NOT inject meta tags with null loader (Server-Timing is used instead)', async ({ page }) => { |
48 | 49 | await page.goto('/?type=null'); |
49 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
50 | 50 |
|
51 | | - expect(sentryTrace).toMatch(/.+/); |
52 | | - expect(sentryBaggage).toMatch(/.+/); |
| 51 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 52 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 53 | + |
| 54 | + expect(sentryTraceTag).toBeNull(); |
| 55 | + expect(sentryBaggageTag).toBeNull(); |
53 | 56 | }); |
54 | 57 |
|
55 | | -test('should inject `sentry-trace` and `baggage` meta tags with undefined loader', async ({ page }) => { |
| 58 | +test('should NOT inject meta tags with undefined loader (Server-Timing is used instead)', async ({ page }) => { |
56 | 59 | await page.goto('/?type=undefined'); |
57 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
58 | 60 |
|
59 | | - expect(sentryTrace).toMatch(/.+/); |
60 | | - expect(sentryBaggage).toMatch(/.+/); |
| 61 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 62 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 63 | + |
| 64 | + expect(sentryTraceTag).toBeNull(); |
| 65 | + expect(sentryBaggageTag).toBeNull(); |
61 | 66 | }); |
62 | 67 |
|
63 | | -test('should inject `sentry-trace` and `baggage` meta tags with throw redirect loader', async ({ page }) => { |
| 68 | +test('should NOT inject meta tags with throw redirect loader (Server-Timing is used instead)', async ({ page }) => { |
64 | 69 | await page.goto('/?type=throwRedirect'); |
65 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
66 | 70 |
|
67 | 71 | // We should be successfully redirected to the path. |
68 | 72 | expect(page.url()).toEqual(expect.stringContaining('/?type=plain')); |
69 | 73 |
|
70 | | - expect(sentryTrace).toMatch(/.+/); |
71 | | - expect(sentryBaggage).toMatch(/.+/); |
| 74 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 75 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 76 | + |
| 77 | + // Meta tags should not be present after redirect either |
| 78 | + expect(sentryTraceTag).toBeNull(); |
| 79 | + expect(sentryBaggageTag).toBeNull(); |
72 | 80 | }); |
73 | 81 |
|
74 | | -test('should inject `sentry-trace` and `baggage` meta tags with return redirect loader', async ({ page, baseURL }) => { |
| 82 | +test('should NOT inject meta tags with return redirect loader (Server-Timing is used instead)', async ({ |
| 83 | + page, |
| 84 | + baseURL, |
| 85 | +}) => { |
75 | 86 | await page.goto(`${baseURL}/?type=returnRedirect`); |
76 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
77 | 87 |
|
78 | 88 | // We should be successfully redirected to the path. |
79 | 89 | expect(page.url()).toEqual(expect.stringContaining('/?type=plain')); |
80 | 90 |
|
81 | | - expect(sentryTrace).toMatch(/.+/); |
82 | | - expect(sentryBaggage).toMatch(/.+/); |
| 91 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 92 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
| 93 | + |
| 94 | + // Meta tags should not be present after redirect either |
| 95 | + expect(sentryTraceTag).toBeNull(); |
| 96 | + expect(sentryBaggageTag).toBeNull(); |
83 | 97 | }); |
84 | 98 |
|
85 | | -test('should return redirect to an external path with no baggage and trace injected.', async ({ page, baseURL }) => { |
| 99 | +test('should return redirect to an external path with no baggage and trace meta tags.', async ({ page, baseURL }) => { |
86 | 100 | await page.goto(`${baseURL}/?type=returnRedirectToExternal`); |
87 | 101 |
|
88 | 102 | expect(page.url()).toEqual(expect.stringContaining('docs.sentry.io')); |
89 | 103 |
|
90 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
| 104 | + // External page won't have our meta tags |
| 105 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 106 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
91 | 107 |
|
92 | | - expect(sentryTrace).toBeUndefined(); |
93 | | - expect(sentryBaggage).toBeUndefined(); |
| 108 | + expect(sentryTraceTag).toBeNull(); |
| 109 | + expect(sentryBaggageTag).toBeNull(); |
94 | 110 | }); |
95 | 111 |
|
96 | | -test('should throw redirect to an external path with no baggage and trace injected.', async ({ page, baseURL }) => { |
| 112 | +test('should throw redirect to an external path with no baggage and trace meta tags.', async ({ page, baseURL }) => { |
97 | 113 | await page.goto(`${baseURL}/?type=throwRedirectToExternal`); |
98 | 114 |
|
99 | 115 | // We should be successfully redirected to the external path. |
100 | 116 | expect(page.url()).toEqual(expect.stringContaining('docs.sentry.io')); |
101 | 117 |
|
102 | | - const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); |
| 118 | + // External page won't have our meta tags |
| 119 | + const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); |
| 120 | + const sentryBaggageTag = await page.$('meta[name="baggage"]'); |
103 | 121 |
|
104 | | - expect(sentryTrace).toBeUndefined(); |
105 | | - expect(sentryBaggage).toBeUndefined(); |
| 122 | + expect(sentryTraceTag).toBeNull(); |
| 123 | + expect(sentryBaggageTag).toBeNull(); |
106 | 124 | }); |
0 commit comments