|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE } from '@sentry/core'; |
| 3 | + |
| 4 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 5 | +import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../../utils/helpers'; |
| 6 | + |
| 7 | +sentryTest("navigation spans link back to previous trace's root span", async ({ getLocalTestUrl, page }) => { |
| 8 | + if (shouldSkipTracingTest()) { |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 13 | + |
| 14 | + const pageloadTraceContext = await sentryTest.step('Initial pageload', async () => { |
| 15 | + const pageloadRequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'pageload'); |
| 16 | + await page.goto(url); |
| 17 | + const pageloadRequest = envelopeRequestParser(await pageloadRequestPromise); |
| 18 | + return pageloadRequest.contexts?.trace; |
| 19 | + }); |
| 20 | + |
| 21 | + const navigation1TraceContext = await sentryTest.step('First navigation', async () => { |
| 22 | + const navigation1RequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'navigation'); |
| 23 | + await page.goto(`${url}#foo`); |
| 24 | + const navigation1Request = envelopeRequestParser(await navigation1RequestPromise); |
| 25 | + return navigation1Request.contexts?.trace; |
| 26 | + }); |
| 27 | + |
| 28 | + const navigation2TraceContext = await sentryTest.step('Second navigation', async () => { |
| 29 | + const navigation2RequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'navigation'); |
| 30 | + await page.goto(`${url}#bar`); |
| 31 | + const navigation2Request = envelopeRequestParser(await navigation2RequestPromise); |
| 32 | + return navigation2Request.contexts?.trace; |
| 33 | + }); |
| 34 | + |
| 35 | + const pageloadTraceId = pageloadTraceContext?.trace_id; |
| 36 | + const navigation1TraceId = navigation1TraceContext?.trace_id; |
| 37 | + const navigation2TraceId = navigation2TraceContext?.trace_id; |
| 38 | + |
| 39 | + expect(pageloadTraceContext?.links).toBeUndefined(); |
| 40 | + |
| 41 | + expect(navigation1TraceContext?.links).toEqual([ |
| 42 | + { |
| 43 | + trace_id: pageloadTraceId, |
| 44 | + span_id: pageloadTraceContext?.span_id, |
| 45 | + sampled: true, |
| 46 | + attributes: { |
| 47 | + [SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: 'previous_trace', |
| 48 | + }, |
| 49 | + }, |
| 50 | + ]); |
| 51 | + |
| 52 | + expect(navigation2TraceContext?.links).toEqual([ |
| 53 | + { |
| 54 | + trace_id: navigation1TraceId, |
| 55 | + span_id: navigation1TraceContext?.span_id, |
| 56 | + sampled: true, |
| 57 | + attributes: { |
| 58 | + [SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: 'previous_trace', |
| 59 | + }, |
| 60 | + }, |
| 61 | + ]); |
| 62 | + |
| 63 | + expect(pageloadTraceId).not.toEqual(navigation1TraceId); |
| 64 | + expect(navigation1TraceId).not.toEqual(navigation2TraceId); |
| 65 | + expect(pageloadTraceId).not.toEqual(navigation2TraceId); |
| 66 | +}); |
| 67 | + |
| 68 | +sentryTest("doesn't link between hard page reloads by default", async ({ getLocalTestUrl, page }) => { |
| 69 | + if (shouldSkipTracingTest()) { |
| 70 | + sentryTest.skip(); |
| 71 | + } |
| 72 | + |
| 73 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 74 | + |
| 75 | + await sentryTest.step('First pageload', async () => { |
| 76 | + const pageloadRequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'pageload'); |
| 77 | + await page.goto(url); |
| 78 | + const pageload1Event = envelopeRequestParser(await pageloadRequestPromise); |
| 79 | + |
| 80 | + expect(pageload1Event.contexts?.trace).toBeDefined(); |
| 81 | + expect(pageload1Event.contexts?.trace?.links).toBeUndefined(); |
| 82 | + }); |
| 83 | + |
| 84 | + await sentryTest.step('Second pageload', async () => { |
| 85 | + const pageload2RequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'pageload'); |
| 86 | + await page.reload(); |
| 87 | + const pageload2Event = envelopeRequestParser(await pageload2RequestPromise); |
| 88 | + |
| 89 | + expect(pageload2Event.contexts?.trace).toBeDefined(); |
| 90 | + expect(pageload2Event.contexts?.trace?.links).toBeUndefined(); |
| 91 | + }); |
| 92 | +}); |
0 commit comments