|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { waitForTransaction, waitForError } from '../event-proxy-server'; |
| 3 | + |
| 4 | +test('Should create a transaction for route handlers', async ({ request }) => { |
| 5 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { |
| 6 | + return transactionEvent?.transaction === 'GET /route-handlers/[param]'; |
| 7 | + }); |
| 8 | + |
| 9 | + const response = await request.get('/route-handlers/foo'); |
| 10 | + expect(await response.json()).toStrictEqual({ name: 'John Doe' }); |
| 11 | + |
| 12 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 13 | + |
| 14 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); |
| 15 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 16 | +}); |
| 17 | + |
| 18 | +test('Should create a transaction for route handlers and correctly set span status depending on http status', async ({ |
| 19 | + request, |
| 20 | +}) => { |
| 21 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { |
| 22 | + return transactionEvent?.transaction === 'POST /route-handlers/[param]'; |
| 23 | + }); |
| 24 | + |
| 25 | + const response = await request.post('/route-handlers/bar'); |
| 26 | + expect(await response.json()).toStrictEqual({ name: 'John Doe' }); |
| 27 | + |
| 28 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 29 | + |
| 30 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('not_found'); |
| 31 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 32 | +}); |
| 33 | + |
| 34 | +test('Should record exceptions and transactions for faulty route handlers', async ({ request }) => { |
| 35 | + const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => { |
| 36 | + return errorEvent?.exception?.values?.[0]?.value === 'route-handler-error'; |
| 37 | + }); |
| 38 | + |
| 39 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { |
| 40 | + return transactionEvent?.transaction === 'PUT /route-handlers/[param]/error'; |
| 41 | + }); |
| 42 | + |
| 43 | + await request.put('/route-handlers/baz/error').catch(() => { |
| 44 | + // noop |
| 45 | + }); |
| 46 | + |
| 47 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 48 | + const routehandlerError = await errorEventPromise; |
| 49 | + |
| 50 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error'); |
| 51 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 52 | + |
| 53 | + expect(routehandlerError.exception?.values?.[0].value).toBe('route-handler-error'); |
| 54 | + expect(routehandlerError.tags?.transaction).toBe('PUT /route-handlers/[param]/error'); |
| 55 | +}); |
| 56 | + |
| 57 | +test.describe('Edge runtime', () => { |
| 58 | + test('should create a transaction for route handlers', async ({ request }) => { |
| 59 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { |
| 60 | + return transactionEvent?.transaction === 'PATCH /route-handlers/[param]/edge'; |
| 61 | + }); |
| 62 | + |
| 63 | + const response = await request.patch('/route-handlers/bar/edge'); |
| 64 | + expect(await response.json()).toStrictEqual({ name: 'John Doe' }); |
| 65 | + |
| 66 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 67 | + |
| 68 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('unauthenticated'); |
| 69 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 70 | + }); |
| 71 | + |
| 72 | + test('should record exceptions and transactions for faulty route handlers', async ({ request }) => { |
| 73 | + const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => { |
| 74 | + return errorEvent?.exception?.values?.[0]?.value === 'route-handler-edge-error'; |
| 75 | + }); |
| 76 | + |
| 77 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { |
| 78 | + return transactionEvent?.transaction === 'DELETE /route-handlers/[param]/edge'; |
| 79 | + }); |
| 80 | + |
| 81 | + await request.delete('/route-handlers/baz/edge').catch(() => { |
| 82 | + // noop |
| 83 | + }); |
| 84 | + |
| 85 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 86 | + const routehandlerError = await errorEventPromise; |
| 87 | + |
| 88 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error'); |
| 89 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 90 | + expect(routehandlerTransaction.contexts?.runtime?.name).toBe('edge'); |
| 91 | + |
| 92 | + expect(routehandlerError.exception?.values?.[0].value).toBe('route-handler-edge-error'); |
| 93 | + expect(routehandlerError.contexts?.runtime?.name).toBe('edge'); |
| 94 | + }); |
| 95 | +}); |
0 commit comments