|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('errors on frontend and backend are connected by the same trace', async ({ page }) => { |
| 5 | + const clientErrorPromise = waitForError('sveltekit-2-twp', evt => { |
| 6 | + return evt.exception?.values?.[0].value === 'Client Error'; |
| 7 | + }); |
| 8 | + |
| 9 | + const serverErrorPromise = waitForError('sveltekit-2-twp', evt => { |
| 10 | + return evt.exception?.values?.[0].value === 'No search query provided'; |
| 11 | + }); |
| 12 | + |
| 13 | + await page.goto('/errors'); |
| 14 | + |
| 15 | + const clientError = await clientErrorPromise; |
| 16 | + const serverError = await serverErrorPromise; |
| 17 | + |
| 18 | + expect(clientError).toMatchObject({ |
| 19 | + contexts: { |
| 20 | + trace: { |
| 21 | + parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 22 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 23 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 24 | + }, |
| 25 | + }, |
| 26 | + environment: 'qa', |
| 27 | + exception: { |
| 28 | + values: [ |
| 29 | + { |
| 30 | + mechanism: { |
| 31 | + handled: false, |
| 32 | + type: 'onunhandledrejection', |
| 33 | + }, |
| 34 | + stacktrace: expect.any(Object), |
| 35 | + type: 'Error', |
| 36 | + value: 'Client Error', |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + level: 'error', |
| 41 | + platform: 'javascript', |
| 42 | + release: '1.0.0', |
| 43 | + timestamp: expect.any(Number), |
| 44 | + transaction: '/errors', |
| 45 | + }); |
| 46 | + |
| 47 | + expect(serverError).toMatchObject({ |
| 48 | + contexts: { |
| 49 | + trace: { |
| 50 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 51 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 52 | + }, |
| 53 | + }, |
| 54 | + environment: 'qa', |
| 55 | + exception: { |
| 56 | + values: [ |
| 57 | + { |
| 58 | + mechanism: { |
| 59 | + handled: true, |
| 60 | + type: 'generic', |
| 61 | + }, |
| 62 | + stacktrace: {}, |
| 63 | + }, |
| 64 | + ], |
| 65 | + }, |
| 66 | + platform: 'node', |
| 67 | + timestamp: expect.any(Number), |
| 68 | + transaction: 'GET /errors', |
| 69 | + }); |
| 70 | + |
| 71 | + const clientTraceId = clientError.contexts?.trace?.trace_id; |
| 72 | + const serverTraceId = serverError.contexts?.trace?.trace_id; |
| 73 | + |
| 74 | + expect(clientTraceId).toBe(serverTraceId); |
| 75 | +}); |
0 commit comments