|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { Event } from '@sentry/core'; |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest('creates fetch spans with http timing', async ({ browserName, getLocalTestUrl, page }) => { |
| 7 | + const supportedBrowsers = ['chromium', 'firefox']; |
| 8 | + |
| 9 | + if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { |
| 10 | + sentryTest.skip(); |
| 11 | + } |
| 12 | + await page.route('http://sentry-test-site.example/*', async route => { |
| 13 | + const request = route.request(); |
| 14 | + const postData = await request.postDataJSON(); |
| 15 | + |
| 16 | + await route.fulfill({ |
| 17 | + status: 200, |
| 18 | + contentType: 'application/json', |
| 19 | + body: JSON.stringify(Object.assign({ id: 1 }, postData)), |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 24 | + |
| 25 | + const envelopes = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url, timeout: 10000 }); |
| 26 | + const tracingEvent = envelopes[envelopes.length - 1]; // last envelope contains tracing data on all browsers |
| 27 | + |
| 28 | + const requestSpans = tracingEvent.spans?.filter(({ op }) => op === 'http.client'); |
| 29 | + |
| 30 | + expect(requestSpans).toHaveLength(3); |
| 31 | + |
| 32 | + await page.pause(); |
| 33 | + requestSpans?.forEach((span, index) => |
| 34 | + expect(span).toMatchObject({ |
| 35 | + description: `GET http://sentry-test-site.example/${index}`, |
| 36 | + parent_span_id: tracingEvent.contexts?.trace?.span_id, |
| 37 | + span_id: expect.stringMatching(/[a-f\d]{16}/), |
| 38 | + start_timestamp: expect.any(Number), |
| 39 | + timestamp: expect.any(Number), |
| 40 | + trace_id: tracingEvent.contexts?.trace?.trace_id, |
| 41 | + data: expect.objectContaining({ |
| 42 | + 'http.request.redirect_start': expect.any(Number), |
| 43 | + 'http.request.redirect_end': expect.any(Number), |
| 44 | + 'http.request.worker_start': expect.any(Number), |
| 45 | + 'http.request.fetch_start': expect.any(Number), |
| 46 | + 'http.request.domain_lookup_start': expect.any(Number), |
| 47 | + 'http.request.domain_lookup_end': expect.any(Number), |
| 48 | + 'http.request.connect_start': expect.any(Number), |
| 49 | + 'http.request.secure_connection_start': expect.any(Number), |
| 50 | + 'http.request.connection_end': expect.any(Number), |
| 51 | + 'http.request.request_start': expect.any(Number), |
| 52 | + 'http.request.response_start': expect.any(Number), |
| 53 | + 'http.request.response_end': expect.any(Number), |
| 54 | + 'http.request.time_to_first_byte': expect.any(Number), |
| 55 | + 'network.protocol.version': expect.any(String), |
| 56 | + }), |
| 57 | + }), |
| 58 | + ); |
| 59 | +}); |
0 commit comments