The route middleware of this page redirects before the page renders.
+ diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts index b30ebd221644..b40c961dc867 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts @@ -1,6 +1,11 @@ -import { HTTP_RESPONSE_STATUS_CODE, URL_PATH } from '@sentry/conventions/attributes'; +import { HTTP_RESPONSE_STATUS_CODE, SENTRY_ORIGIN, URL_PATH } from '@sentry/conventions/attributes'; import { expect, test } from '@playwright/test'; -import { waitForEnvelopeItem, waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils'; +import { + collectStreamedSpansUntilSegment, + waitForEnvelopeItem, + waitForError, + waitForStreamedSpan, +} from '@sentry-internal/test-utils'; import type { SerializedStreamedSpan } from '@sentry-internal/test-utils'; import { isViteServer, NITRO_ONLY } from './isViteServer'; @@ -84,6 +89,33 @@ test.describe('page that fails during SSR', () => { expect(rootSpan.attributes[HTTP_RESPONSE_STATUS_CODE]).toEqual({ type: 'integer', value: 500 }); }); + test('sends a span for the failed render and a `renderErrorPage` span for the render of the error page', async ({ + request, + }) => { + const spansPromise = collectStreamedSpansUntilSegment( + 'nuxt-4', + span => span.attributes[URL_PATH]?.value === SSR_ERROR_PATH, + span => span.name === 'renderErrorPage', + ); + + await request.get(SSR_ERROR_PATH); + + const spans = await spansPromise; + const rootSpan = spans.find(span => span.is_segment); + const renderSpans = spans + .filter(span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.function.nuxt.render') + .map(span => ({ + name: span.name, + status: span.status, + isChildOfRoot: span.parent_span_id === rootSpan?.span_id, + })); + + expect(renderSpans).toEqual([ + { name: 'renderPage', status: 'error', isChildOfRoot: true }, + { name: 'renderErrorPage', status: 'ok', isChildOfRoot: true }, + ]); + }); + test('names the root span after the page route', async ({ request }) => { test.fail( true, diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.static-lifecycle.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.static-lifecycle.test.ts index 451ab2f1a4d9..c3227bf94a43 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.static-lifecycle.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.static-lifecycle.test.ts @@ -1,4 +1,5 @@ -import { SENTRY_OP, SENTRY_ORIGIN, URL_PATH } from '@sentry/conventions/attributes'; +import { HTTP_ROUTE, SENTRY_OP, SENTRY_ORIGIN, URL_PATH } from '@sentry/conventions/attributes'; +import { FUNCTION } from '@sentry/conventions/op'; import { expect, test } from '@playwright/test'; import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; @@ -21,6 +22,23 @@ test('sends a server action transaction on pageload', async ({ page }) => { ); }); +test('sends a `renderPage` span for the page render as a child of the server transaction', async ({ request }) => { + const transactionPromise = waitForTransaction('nuxt-4', transactionEvent => { + return transactionEvent.contexts?.trace?.data?.[URL_PATH] === '/test-param/render-span'; + }); + + await request.get('/test-param/render-span'); + + const transaction = await transactionPromise; + const renderSpans = transaction.spans?.filter(span => span.origin === 'auto.function.nuxt.render'); + + expect(renderSpans).toHaveLength(1); + expect(renderSpans?.[0]?.description).toBe('renderPage'); + expect(renderSpans?.[0]?.op).toBe(FUNCTION); + expect(renderSpans?.[0]?.parent_span_id).toBe(transaction.contexts?.trace?.span_id); + expect(renderSpans?.[0]?.data[HTTP_ROUTE]).toBe('/test-param/:param()'); +}); + [ // Nuxt build output that the HTTP integration does not ignore. '/_nuxt/builds/latest.json', diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.streaming-lifecycle.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.streaming-lifecycle.test.ts index 5523bced86b5..31164c4c08f1 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.streaming-lifecycle.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.server.streaming-lifecycle.test.ts @@ -1,7 +1,9 @@ -import { URL_PATH } from '@sentry/conventions/attributes'; +import { CODE_FUNCTION_NAME, ERROR_TYPE, HTTP_ROUTE, SENTRY_ORIGIN, URL_PATH } from '@sentry/conventions/attributes'; +import { FUNCTION } from '@sentry/conventions/op'; import { expect, test } from '@playwright/test'; import { collectStreamedSpans, + collectStreamedSpansUntilSegment, getSpanOp, waitForStreamedSpan, waitForStreamedSpans, @@ -10,6 +12,8 @@ import { IMPORT_SURFACES } from './importSurfaces'; import { isViteServer, NITRO_ONLY } from './isViteServer'; import { SERVER_ORIGIN } from './runtime'; +const RENDER_ORIGIN = 'auto.function.nuxt.render'; + test('sends a server root span on pageload', async ({ page }) => { const serverSpanPromise = waitForStreamedSpan('nuxt-4', span => { return span.is_segment && span.name.includes('GET /test-param/'); @@ -23,6 +27,61 @@ test('sends a server root span on pageload', async ({ page }) => { expect(serverSpan.attributes['sentry.origin']?.value).toBe(SERVER_ORIGIN); }); +test('sends a `renderPage` span for the page render as a child of the server root span', async ({ request }) => { + const spansPromise = collectStreamedSpansUntilSegment( + 'nuxt-4', + span => span.attributes[URL_PATH]?.value === '/test-param/render-span', + span => span.name === 'renderPage', + ); + + await request.get('/test-param/render-span'); + + const spans = await spansPromise; + const rootSpan = spans.find(span => span.is_segment); + const renderSpans = spans.filter(span => span.attributes[SENTRY_ORIGIN]?.value === RENDER_ORIGIN); + + expect(renderSpans).toHaveLength(1); + expect(renderSpans[0]?.name).toBe('renderPage'); + expect(renderSpans[0]?.status).toBe('ok'); + expect(renderSpans[0]?.parent_span_id).toBe(rootSpan?.span_id); + expect(getSpanOp(renderSpans[0]!)).toBe(FUNCTION); + expect(renderSpans[0]?.attributes[CODE_FUNCTION_NAME]).toEqual({ type: 'string', value: 'renderPage' }); + expect(renderSpans[0]?.attributes[HTTP_ROUTE]).toEqual({ type: 'string', value: '/test-param/:param()' }); +}); + +test('keeps the ok status of the render span when a route middleware redirects', async ({ request }) => { + const spansPromise = collectStreamedSpansUntilSegment( + 'nuxt-4', + span => span.attributes[URL_PATH]?.value === '/redirect-in-route-middleware', + span => span.name === 'renderPage', + ); + + const response = await request.get('/redirect-in-route-middleware', { maxRedirects: 0 }); + + const renderSpan = (await spansPromise).find(span => span.name === 'renderPage'); + + expect(response.status()).toBe(302); + expect(renderSpan?.status).toBe('ok'); + expect(renderSpan?.attributes[ERROR_TYPE]).toBeUndefined(); + // The router is already at the target of the redirect, so the span has no route. + expect(renderSpan?.attributes[HTTP_ROUTE]).toBeUndefined(); +}); + +test('keeps the ok status of the render span for a URL that matches no page', async ({ request }) => { + const spansPromise = collectStreamedSpansUntilSegment( + 'nuxt-4', + span => span.attributes[URL_PATH]?.value === '/no-page-for-this-url', + span => span.name === 'renderPage', + ); + + const response = await request.get('/no-page-for-this-url'); + + const renderSpan = (await spansPromise).find(span => span.name === 'renderPage'); + + expect(response.status()).toBe(404); + expect(renderSpan?.status).toBe('ok'); +}); + [ // Nuxt build output that the HTTP integration does not ignore. '/_nuxt/builds/latest.json', diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/app/middleware/redirect-to-param-page.ts b/dev-packages/e2e-tests/test-applications/nuxt-5/app/middleware/redirect-to-param-page.ts new file mode 100644 index 000000000000..3d68c7427df1 --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/app/middleware/redirect-to-param-page.ts @@ -0,0 +1,3 @@ +import { defineNuxtRouteMiddleware, navigateTo } from '#imports'; + +export default defineNuxtRouteMiddleware(() => navigateTo('/test-param/redirect-target')); diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/app/pages/redirect-in-route-middleware.vue b/dev-packages/e2e-tests/test-applications/nuxt-5/app/pages/redirect-in-route-middleware.vue new file mode 100644 index 000000000000..4efd556135d3 --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/app/pages/redirect-in-route-middleware.vue @@ -0,0 +1,9 @@ + + + +The route middleware of this page redirects before the page renders.
+ diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts index 8b3e573b116a..34501279299c 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts @@ -1,6 +1,11 @@ -import { HTTP_RESPONSE_STATUS_CODE, URL_PATH } from '@sentry/conventions/attributes'; +import { HTTP_RESPONSE_STATUS_CODE, SENTRY_ORIGIN, URL_PATH } from '@sentry/conventions/attributes'; import { expect, test } from '@playwright/test'; -import { waitForEnvelopeItem, waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils'; +import { + collectStreamedSpansUntilSegment, + waitForEnvelopeItem, + waitForError, + waitForStreamedSpan, +} from '@sentry-internal/test-utils'; import type { SerializedStreamedSpan } from '@sentry-internal/test-utils'; type EnvelopeItem = Parameters