Skip to content

feat(react-router): Ensure http.server route handling is consistent #16986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
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
Expand Up @@ -5,9 +5,4 @@ Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
tracesSampleRate: 1.0,
tunnel: `http://localhost:3031/`, // proxy server
integrations: function (integrations) {
return integrations.filter(integration => {
return integration.name !== 'ReactRouterServer';
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { APP_NAME } from '../constants';

test.describe('servery - performance', () => {
test.describe('server - performance', () => {
test('should send server transaction on pageload', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'GET /performance';
Expand All @@ -19,11 +19,11 @@ test.describe('servery - performance', () => {
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto.http.react-router.request-handler',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto.http.react-router.request-handler',
},
},
spans: expect.any(Array),
Expand Down Expand Up @@ -70,11 +70,11 @@ test.describe('servery - performance', () => {
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto.http.react-router.request-handler',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto.http.react-router.request-handler',
},
},
spans: expect.any(Array),
Expand Down Expand Up @@ -107,21 +107,52 @@ test.describe('servery - performance', () => {

test('should instrument wrapped server loader', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
console.log(110, transactionEvent.transaction);
return transactionEvent.transaction === 'GET /performance/server-loader';
return transactionEvent.transaction === 'GET /performance/server-loader.data';
});

await page.goto(`/performance`);
await page.waitForTimeout(500);
await page.getByRole('link', { name: 'Server Loader' }).click();

const transaction = await txPromise;

expect(transaction?.spans?.[transaction.spans?.length - 1]).toMatchObject({
expect(transaction).toEqual(
expect.objectContaining({
contexts: expect.objectContaining({
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
op: 'http.server',
origin: 'auto.http.react-router.loader',
parent_span_id: expect.any(String),
status: 'ok',
data: expect.objectContaining({
'http.method': 'GET',
'http.response.status_code': 200,
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/performance/server-loader.data',
'http.url': 'http://localhost:3030/performance/server-loader.data',
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.react-router.loader',
'sentry.source': 'url',
url: 'http://localhost:3030/performance/server-loader.data',
}),
},
}),
transaction: 'GET /performance/server-loader.data',
type: 'transaction',
transaction_info: { source: 'url' },
platform: 'node',
}),
);
// ensure we do not have a stray, bogus route attribute
expect(transaction.contexts?.trace?.data?.['http.route']).not.toBeDefined();

expect(transaction?.spans).toContainEqual({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'auto.http.react-router',
'sentry.origin': 'auto.http.react-router.loader',
'sentry.op': 'function.react-router.loader',
},
description: 'Executing Server Loader',
Expand All @@ -130,25 +161,58 @@ test.describe('servery - performance', () => {
timestamp: expect.any(Number),
status: 'ok',
op: 'function.react-router.loader',
origin: 'auto.http.react-router',
origin: 'auto.http.react-router.loader',
});
});

test('should instrument a wrapped server action', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'POST /performance/server-action';
return transactionEvent.transaction === 'POST /performance/server-action.data';
});

await page.goto(`/performance/server-action`);
await page.getByRole('button', { name: 'Submit' }).click();

const transaction = await txPromise;

expect(transaction?.spans?.[transaction.spans?.length - 1]).toMatchObject({
expect(transaction).toEqual(
expect.objectContaining({
contexts: expect.objectContaining({
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
op: 'http.server',
origin: 'auto.http.react-router.action',
parent_span_id: expect.any(String),
status: 'ok',
data: expect.objectContaining({
'http.method': 'POST',
'http.response.status_code': 200,
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/performance/server-action.data',
'http.url': 'http://localhost:3030/performance/server-action.data',
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.react-router.action',
'sentry.source': 'url',
url: 'http://localhost:3030/performance/server-action.data',
}),
},
}),
transaction: 'POST /performance/server-action.data',
type: 'transaction',
transaction_info: { source: 'url' },
platform: 'node',
}),
);
// ensure we do not have a stray, bogus route attribute
expect(transaction.contexts?.trace?.data?.['http.route']).not.toBeDefined();

expect(transaction?.spans).toContainEqual({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'auto.http.react-router',
'sentry.origin': 'auto.http.react-router.action',
'sentry.op': 'function.react-router.action',
},
description: 'Executing Server Action',
Expand All @@ -157,7 +221,7 @@ test.describe('servery - performance', () => {
timestamp: expect.any(Number),
status: 'ok',
op: 'function.react-router.action',
origin: 'auto.http.react-router',
origin: 'auto.http.react-router.action',
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Sentry from '@sentry/react-router';

Sentry.init({
// todo: grab from env
dsn: 'https://username@domain/123',
environment: 'qa', // dynamic sampling bias to keep transactions
tracesSampleRate: 1.0,
tunnel: `http://localhost:3031/`, // proxy server
tunnel: `http://localhost:3031/`, // proxy server,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { APP_NAME } from '../constants';

test.describe('servery - performance', () => {
test.describe('server - performance', () => {
test('should send server transaction on pageload', async ({ page }) => {
const txPromise = waitForTransaction(APP_NAME, async transactionEvent => {
return transactionEvent.transaction === 'GET /performance';
Expand All @@ -19,11 +19,11 @@ test.describe('servery - performance', () => {
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto.http.react-router.request-handler',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto.http.react-router.request-handler',
},
},
spans: expect.any(Array),
Expand Down Expand Up @@ -70,11 +70,11 @@ test.describe('servery - performance', () => {
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto.http.react-router.request-handler',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto.http.react-router.request-handler',
},
},
spans: expect.any(Array),
Expand Down Expand Up @@ -110,26 +110,59 @@ test.describe('servery - performance', () => {
return transactionEvent.transaction === 'GET /performance/server-loader.data';
});

await page.goto(`/performance`); // initial ssr pageloads do not contain .data requests
await page.waitForTimeout(500); // quick breather before navigation
await page.goto('/performance'); // initial ssr pageloads do not contain .data requests
await page.getByRole('link', { name: 'Server Loader' }).click(); // this will actually trigger a .data request

const transaction = await txPromise;

expect(transaction?.spans?.[transaction.spans?.length - 1]).toMatchObject({
expect(transaction).toEqual(
expect.objectContaining({
contexts: expect.objectContaining({
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
op: 'http.server',
origin: 'auto.http.react-router.server',
parent_span_id: expect.any(String),
status: 'ok',
data: expect.objectContaining({
'http.method': 'GET',
'http.response.status_code': 200,
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/performance/server-loader.data',
'http.url': 'http://localhost:3030/performance/server-loader.data',
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.react-router.server',
'sentry.source': 'url',
url: 'http://localhost:3030/performance/server-loader.data',
}),
},
}),
transaction: 'GET /performance/server-loader.data',
type: 'transaction',
transaction_info: { source: 'url' },
platform: 'node',
}),
);

// ensure we do not have a stray, bogus route attribute
expect(transaction.contexts?.trace?.data?.['http.route']).not.toBeDefined();

expect(transaction.spans).toContainEqual({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'auto.http.react-router',
'sentry.op': 'function.react-router.loader',
'sentry.origin': 'auto.http.react-router.server',
},
description: 'Executing Server Loader',
op: 'function.react-router.loader',
origin: 'auto.http.react-router.server',
parent_span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'function.react-router.loader',
origin: 'auto.http.react-router',
timestamp: expect.any(Number),
});
});

Expand All @@ -143,20 +176,53 @@ test.describe('servery - performance', () => {

const transaction = await txPromise;

expect(transaction?.spans?.[transaction.spans?.length - 1]).toMatchObject({
expect(transaction).toEqual(
expect.objectContaining({
contexts: expect.objectContaining({
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
op: 'http.server',
origin: 'auto.http.react-router.server',
parent_span_id: expect.any(String),
status: 'ok',
data: expect.objectContaining({
'http.method': 'POST',
'http.response.status_code': 200,
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/performance/server-action.data',
'http.url': 'http://localhost:3030/performance/server-action.data',
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.react-router.server',
'sentry.source': 'url',
url: 'http://localhost:3030/performance/server-action.data',
}),
},
}),
transaction: 'POST /performance/server-action.data',
type: 'transaction',
transaction_info: { source: 'url' },
platform: 'node',
}),
);
// ensure we do not have a stray, bogus route attribute
expect(transaction.contexts?.trace?.data?.['http.route']).not.toBeDefined();

expect(transaction.spans).toContainEqual({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'auto.http.react-router',
'sentry.op': 'function.react-router.action',
'sentry.origin': 'auto.http.react-router.server',
},
description: 'Executing Server Action',
op: 'function.react-router.action',
origin: 'auto.http.react-router.server',
parent_span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'function.react-router.action',
origin: 'auto.http.react-router',
timestamp: expect.any(Number),
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Sentry from '@sentry/react-router';

Sentry.init({
// todo: grab from env
dsn: 'https://username@domain/123',
environment: 'qa', // dynamic sampling bias to keep transactions
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ test.describe('server - performance', () => {
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto.http.react-router.request-handler',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto.http.react-router.request-handler',
},
},
spans: expect.any(Array),
Expand Down Expand Up @@ -70,11 +70,11 @@ test.describe('server - performance', () => {
trace_id: expect.any(String),
data: {
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto.http.react-router.request-handler',
'sentry.source': 'route',
},
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto.http.react-router.request-handler',
},
},
spans: expect.any(Array),
Expand Down
Loading
Loading