|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { Event } from '@sentry/core'; |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest('should update spans for GraphQL persisted query fetch requests', async ({ getLocalTestUrl, page }) => { |
| 7 | + if (shouldSkipTracingTest()) { |
| 8 | + return; |
| 9 | + } |
| 10 | + |
| 11 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 12 | + |
| 13 | + await page.route('**/graphql', route => { |
| 14 | + return route.fulfill({ |
| 15 | + status: 200, |
| 16 | + body: JSON.stringify({ |
| 17 | + data: { |
| 18 | + user: { |
| 19 | + id: '123', |
| 20 | + name: 'Test User', |
| 21 | + }, |
| 22 | + }, |
| 23 | + }), |
| 24 | + headers: { |
| 25 | + 'Content-Type': 'application/json', |
| 26 | + }, |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); |
| 31 | + const requestSpans = eventData.spans?.filter(({ op }) => op === 'http.client'); |
| 32 | + |
| 33 | + expect(requestSpans).toHaveLength(1); |
| 34 | + |
| 35 | + expect(requestSpans![0]).toMatchObject({ |
| 36 | + description: 'POST http://sentry-test.io/graphql (persisted GetUser)', |
| 37 | + parent_span_id: eventData.contexts?.trace?.span_id, |
| 38 | + span_id: expect.any(String), |
| 39 | + start_timestamp: expect.any(Number), |
| 40 | + timestamp: expect.any(Number), |
| 41 | + trace_id: eventData.contexts?.trace?.trace_id, |
| 42 | + status: 'ok', |
| 43 | + data: expect.objectContaining({ |
| 44 | + type: 'fetch', |
| 45 | + 'http.method': 'POST', |
| 46 | + 'http.url': 'http://sentry-test.io/graphql', |
| 47 | + url: 'http://sentry-test.io/graphql', |
| 48 | + 'server.address': 'sentry-test.io', |
| 49 | + 'sentry.op': 'http.client', |
| 50 | + 'sentry.origin': 'auto.http.browser', |
| 51 | + 'graphql.persisted_query.hash.sha256': 'ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38', |
| 52 | + 'graphql.persisted_query.version': 1, |
| 53 | + }), |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +sentryTest( |
| 58 | + 'should update breadcrumbs for GraphQL persisted query fetch requests', |
| 59 | + async ({ getLocalTestUrl, page }) => { |
| 60 | + if (shouldSkipTracingTest()) { |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 65 | + |
| 66 | + await page.route('**/graphql', route => { |
| 67 | + return route.fulfill({ |
| 68 | + status: 200, |
| 69 | + body: JSON.stringify({ |
| 70 | + data: { |
| 71 | + user: { |
| 72 | + id: '123', |
| 73 | + name: 'Test User', |
| 74 | + }, |
| 75 | + }, |
| 76 | + }), |
| 77 | + headers: { |
| 78 | + 'Content-Type': 'application/json', |
| 79 | + }, |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); |
| 84 | + |
| 85 | + expect(eventData?.breadcrumbs?.length).toBe(1); |
| 86 | + |
| 87 | + expect(eventData.breadcrumbs![0]).toEqual({ |
| 88 | + timestamp: expect.any(Number), |
| 89 | + category: 'fetch', |
| 90 | + type: 'http', |
| 91 | + data: { |
| 92 | + method: 'POST', |
| 93 | + status_code: 200, |
| 94 | + url: 'http://sentry-test.io/graphql', |
| 95 | + __span: expect.any(String), |
| 96 | + 'graphql.operation': 'persisted GetUser', |
| 97 | + 'graphql.persisted_query.hash.sha256': 'ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38', |
| 98 | + 'graphql.persisted_query.version': 1, |
| 99 | + }, |
| 100 | + }); |
| 101 | + }, |
| 102 | +); |
0 commit comments