|
| 1 | +import { nextTestSetup } from 'e2e-utils' |
| 2 | +import { retry } from 'next-test-utils' |
| 3 | +import { getOutputLogJson } from '../_testing/utils' |
| 4 | + |
| 5 | +describe('on-request-error - otel', () => { |
| 6 | + const { next, skipped } = nextTestSetup({ |
| 7 | + files: __dirname, |
| 8 | + skipDeployment: true, |
| 9 | + packageJson: { |
| 10 | + dependencies: { |
| 11 | + '@vercel/otel': '^1.13.0', |
| 12 | + }, |
| 13 | + }, |
| 14 | + }) |
| 15 | + |
| 16 | + if (skipped) { |
| 17 | + return |
| 18 | + } |
| 19 | + |
| 20 | + const outputLogPath = 'output-log.json' |
| 21 | + |
| 22 | + async function validateErrorRecord({ |
| 23 | + errorMessage, |
| 24 | + url, |
| 25 | + renderSource, |
| 26 | + }: { |
| 27 | + errorMessage: string |
| 28 | + url: string |
| 29 | + renderSource: string | undefined |
| 30 | + }) { |
| 31 | + // Assert the instrumentation is called |
| 32 | + await retry(async () => { |
| 33 | + const recordLogLines = next.cliOutput |
| 34 | + .split('\n') |
| 35 | + .filter((log) => log.includes('[instrumentation] write-log')) |
| 36 | + expect(recordLogLines).toEqual( |
| 37 | + expect.arrayContaining([expect.stringContaining(errorMessage)]) |
| 38 | + ) |
| 39 | + // TODO: remove custom duration in case we increase the default. |
| 40 | + }, 5000) |
| 41 | + |
| 42 | + const json = await getOutputLogJson(next, outputLogPath) |
| 43 | + const record = json[errorMessage] |
| 44 | + |
| 45 | + const { payload } = record |
| 46 | + const { request } = payload |
| 47 | + |
| 48 | + expect(request.path).toBe(url) |
| 49 | + expect(record).toMatchObject({ |
| 50 | + count: 1, |
| 51 | + payload: { |
| 52 | + message: errorMessage, |
| 53 | + request: { method: 'GET', headers: { accept: '*/*' } }, |
| 54 | + ...(renderSource ? { context: { renderSource } } : undefined), |
| 55 | + }, |
| 56 | + }) |
| 57 | + } |
| 58 | + |
| 59 | + beforeAll(async () => { |
| 60 | + await next.patchFile(outputLogPath, '{}') |
| 61 | + }) |
| 62 | + |
| 63 | + describe('app router', () => { |
| 64 | + it('should catch server component page error in node runtime', async () => { |
| 65 | + await next.fetch('/server-page') |
| 66 | + await validateErrorRecord({ |
| 67 | + errorMessage: 'server-page-node-error', |
| 68 | + url: '/server-page', |
| 69 | + renderSource: 'react-server-components', |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + it('should catch app routes error in node runtime', async () => { |
| 74 | + await next.fetch('/app-route') |
| 75 | + |
| 76 | + await validateErrorRecord({ |
| 77 | + errorMessage: 'route-node-error', |
| 78 | + url: '/app-route', |
| 79 | + renderSource: undefined, |
| 80 | + }) |
| 81 | + }) |
| 82 | + }) |
| 83 | +}) |
0 commit comments