Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function GET() {
throw new Error('Route handler error');
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export const dynamic = 'force-dynamic';
export async function GET() {
return NextResponse.json({ message: 'Hello Node Route Handler' });
}

export async function POST() {
return NextResponse.json({ name: 'Boop' }, { status: 400 });
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';

export async function GET(request: Request) {
export async function GET() {
return NextResponse.json({ name: 'Static' });
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ const nextConfig = {};

module.exports = withSentryConfig(nextConfig, {
silent: true,
release: {
name: 'foobar123',
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function Page() {
<p>Hello World!</p>;
return <p>Hello World!</p>;
}

// getServerSideProps makes this page dynamic and allows tracing data to be inserted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { parseSemver } from '@sentry/core';

const packageJson = require('../../package.json');
const packageJson = require('../package.json');
const nextjsVersion = packageJson.dependencies.next;
const { major, minor } = parseSemver(nextjsVersion);

test('Should propagate traces from server to client in pages router', async ({ page }) => {
// TODO: Remove this skippage when Next.js 15.3.0 is released and bump version in package json to 15.3.0
test.skip(
major === 15 && minor !== undefined && minor < 3,
'Next.js version does not support clientside instrumentation',
);

const serverTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => {
return transactionEvent?.transaction === 'GET /[param]/pages-router-client-trace-propagation';
const serverTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
return transactionEvent?.transaction === 'GET /[locale]/pages-router-client-trace-propagation';
});

const pageloadTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => {
return transactionEvent?.transaction === '/[param]/pages-router-client-trace-propagation';
const pageloadTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
return transactionEvent?.transaction === '/[locale]/pages-router-client-trace-propagation';
});

await page.goto(`/123/pages-router-client-trace-propagation`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test, { expect } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';

test('Should create a transaction for node route handlers', async ({ request }) => {
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
Expand Down Expand Up @@ -37,3 +37,59 @@ test('Should create a transaction for edge route handlers', async ({ request })
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
expect(routehandlerTransaction.contexts?.trace?.data?.['http.request.header.x_charly']).toBe('gomez');
});

test('Should create a transaction for static route handlers', async ({ request }) => {
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
return transactionEvent?.transaction === 'GET /route-handler/static';
});

const response = await request.get('/route-handler/static');
expect(await response.json()).toStrictEqual({ name: 'Static' });

const routehandlerTransaction = await routehandlerTransactionPromise;

expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
});

test('Should create a transaction for route handlers and correctly set span status depending on http status', async ({
request,
}) => {
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
return transactionEvent?.transaction === 'POST /route-handler/[xoxo]/node';
});

const response = await request.post('/route-handler/123/node');
expect(await response.json()).toStrictEqual({ name: 'Boop' });

const routehandlerTransaction = await routehandlerTransactionPromise;

expect(routehandlerTransaction.contexts?.trace?.status).toBe('invalid_argument');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
});

test('Should record exceptions and transactions for faulty route handlers', async ({ request }) => {
const errorEventPromise = waitForError('nextjs-15', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Route handler error';
});

const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/error';
});

await request.get('/route-handler/123/error').catch(() => {});

const routehandlerTransaction = await routehandlerTransactionPromise;
const routehandlerError = await errorEventPromise;

expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
expect(routehandlerTransaction.contexts?.trace?.origin).toContain('auto');

expect(routehandlerError.exception?.values?.[0].value).toBe('Route handler error');

expect(routehandlerError.request?.method).toBe('GET');
expect(routehandlerError.request?.url).toContain('/route-handler/123/error');

expect(routehandlerError.transaction).toContain('/route-handler/[xoxo]/error');
});
46 changes: 0 additions & 46 deletions dev-packages/e2e-tests/test-applications/nextjs-turbo/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions dev-packages/e2e-tests/test-applications/nextjs-turbo/.npmrc

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

46 changes: 0 additions & 46 deletions dev-packages/e2e-tests/test-applications/nextjs-turbo/package.json

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading