Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b188e0a
feat(react-router): Add support for React Router instrumentation API
onurtemizkan Dec 18, 2025
95721fc
Move instrumentation API functions to serverGlobals not to break hydr…
onurtemizkan Dec 19, 2025
fa71e6b
Update hydrogen server transaction tests with better parameterization
onurtemizkan Dec 19, 2025
75374f3
Address copilot review
onurtemizkan Dec 22, 2025
8281d63
Improve E2E test coverage
onurtemizkan Dec 23, 2025
7aa2d67
Use snake_case for span ops
onurtemizkan Dec 23, 2025
e3064e2
Move navigate hook flag inside client check
onurtemizkan Dec 23, 2025
23514b7
Move data inside `mechanism` object
onurtemizkan Dec 23, 2025
9b756ae
Merge remote-tracking branch 'origin/develop' into react-router-8-ins…
onurtemizkan Dec 29, 2025
0c84709
Prevent Framework Mode navigation span regression
onurtemizkan Dec 29, 2025
681eb3e
Enhance navigation with popstate listener and numeric navigation hand…
onurtemizkan Dec 30, 2025
1571025
Lint
onurtemizkan Dec 30, 2025
7c9148e
Set span status on request handler errors
onurtemizkan Dec 30, 2025
3ad323c
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Dec 30, 2025
f1aab54
Clean up
onurtemizkan Jan 8, 2026
7ab179a
Move `captureInstrumentationError` calls inside error check blocks
onurtemizkan Jan 8, 2026
4cc4af8
Move error capture inside check
onurtemizkan Jan 8, 2026
46aee15
Merge branch 'develop' into react-router-8-instrumentation-api
onurtemizkan Jan 8, 2026
9cf02d8
Merge branch 'develop' into react-router-8-instrumentation-api
chargome Jan 26, 2026
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 numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {
const transaction = await transactionPromise;

expect(transaction).toBeDefined();
expect(transaction.transaction).toBe('GET /user/123');
// Transaction name should be parameterized (route pattern, not actual URL)
expect(transaction.transaction).toBe('GET /user/:id');
});

test('Sends two linked transactions (server & client) to Sentry', async ({ page }) => {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/test-results/
/playwright-report/
/playwright/.cache/

!*.d.ts

# react router
.react-router
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
body {
font-family: system-ui, sans-serif;
margin: 0;
padding: 20px;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';

// Create the tracing integration with useInstrumentationAPI enabled
// This must be set BEFORE Sentry.init() to prepare the instrumentation
const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://username@domain/123',
tunnel: `http://localhost:3031/`, // proxy server
integrations: [tracing],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\//],
});

// Get the client instrumentation from the Sentry integration
// NOTE: As of React Router 7.x, HydratedRouter does NOT invoke these hooks in Framework Mode.
// The client-side instrumentation is prepared for when React Router adds support.
// Client-side navigation is currently handled by the legacy instrumentHydratedRouter() approach.
const sentryClientInstrumentation = [tracing.clientInstrumentation];

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
{/* unstable_instrumentations is React Router 7.x's prop name (will become `instrumentations` in v8) */}
<HydratedRouter unstable_instrumentations={sentryClientInstrumentation} />
</StrictMode>,
);
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import { renderToPipeableStream } from 'react-dom/server';
import { ServerRouter } from 'react-router';
import { type HandleErrorFunction } from 'react-router';

const ABORT_DELAY = 5_000;

const handleRequest = Sentry.createSentryHandleRequest({
streamTimeout: ABORT_DELAY,
ServerRouter,
renderToPipeableStream,
createReadableStreamFromReadable,
});

export default handleRequest;

export const handleError: HandleErrorFunction = Sentry.createSentryHandleError({ logErrors: true });

// Use Sentry's instrumentation API for server-side tracing
// `unstable_instrumentations` is React Router 7.x's export name (will become `instrumentations` in v8)
export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import * as Sentry from '@sentry/react-router';
import { Links, Meta, Outlet, Scripts, ScrollRestoration, isRouteErrorResponse } from 'react-router';
import type { Route } from './+types/root';
import stylesheet from './app.css?url';

export const links: Route.LinksFunction = () => [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossOrigin: 'anonymous',
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap',
},
{ rel: 'stylesheet', href: stylesheet },
];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
let message = 'Oops!';
let details = 'An unexpected error occurred.';
let stack: string | undefined;

if (isRouteErrorResponse(error)) {
message = error.status === 404 ? '404' : 'Error';
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details;
} else if (error && error instanceof Error) {
Sentry.captureException(error);
if (import.meta.env.DEV) {
details = error.message;
stack = error.stack;
}
}

return (
<main className="pt-16 p-4 container mx-auto">
<h1>{message}</h1>
<p>{details}</p>
{stack && (
<pre className="w-full p-4 overflow-x-auto">
<code>{stack}</code>
</pre>
)}
</main>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { type RouteConfig, index, prefix, route } from '@react-router/dev/routes';

export default [
index('routes/home.tsx'),
...prefix('performance', [
index('routes/performance/index.tsx'),
route('ssr', 'routes/performance/ssr.tsx'),
route('with/:param', 'routes/performance/dynamic-param.tsx'),
route('static', 'routes/performance/static.tsx'),
route('server-loader', 'routes/performance/server-loader.tsx'),
route('server-action', 'routes/performance/server-action.tsx'),
route('with-middleware', 'routes/performance/with-middleware.tsx'),
route('error-loader', 'routes/performance/error-loader.tsx'),
route('error-action', 'routes/performance/error-action.tsx'),
route('error-middleware', 'routes/performance/error-middleware.tsx'),
route('lazy-route', 'routes/performance/lazy-route.tsx'),
route('fetcher-test', 'routes/performance/fetcher-test.tsx'),
]),
] satisfies RouteConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
export function meta() {
return [
{ title: 'React Router Instrumentation API Test' },
{ name: 'description', content: 'Testing React Router instrumentation API' },
];
}

export default function Home() {
return <div>home</div>;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import type { Route } from './+types/dynamic-param';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function DynamicParamPage({ params }: Route.ComponentProps) {
return (
<div>
<h1>Dynamic Param Page</h1>
<div>Param: {params.param}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { Form } from 'react-router';

export async function action(): Promise<never> {
throw new Error('Action error for testing');
}

export default function ErrorActionPage() {
return (
<div>
<h1>Error Action Page</h1>
<Form method="post">
<button type="submit">Trigger Error</button>
</Form>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function loader(): never {
throw new Error('Loader error for testing');
}

export default function ErrorLoaderPage() {
return (
<div>
<h1>Error Loader Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/error-middleware';

export const middleware: Route.MiddlewareFunction[] = [
async function errorMiddleware() {
throw new Error('Middleware error for testing');
},
];

export default function ErrorMiddlewarePage() {
return (
<div>
<h1>Error Middleware Page</h1>
<p>This should not render</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import { useFetcher } from 'react-router';
import type { Route } from './+types/fetcher-test';

export async function loader() {
return { message: 'Fetcher test page loaded' };
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const value = formData.get('value')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 50));
return { success: true, value };
}

export default function FetcherTestPage() {
const fetcher = useFetcher();

return (
<div>
<h1 id="fetcher-test-title">Fetcher Test Page</h1>
<fetcher.Form method="post">
<input type="hidden" name="value" value="test-value" />
<button type="submit" id="fetcher-submit">
Submit via Fetcher
</button>
</fetcher.Form>
{fetcher.data?.success && <div id="fetcher-result">Fetcher result: {fetcher.data.value}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import { Link } from 'react-router';

// Minimal loader to trigger Sentry's route instrumentation
export function loader() {
return null;
}

export default function PerformancePage() {
return (
<div>
<h1>Performance Page</h1>
<nav>
<Link to="/performance/ssr">SSR Page</Link>
<Link to="/performance/with/sentry">With Param Page</Link>
<Link to="/performance/server-loader">Server Loader</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
export async function loader() {
// Simulate a slow lazy load
await new Promise(resolve => setTimeout(resolve, 100));
return { message: 'Lazy loader data' };
}

export default function LazyRoute() {
return (
<div>
<h1 id="lazy-route-title">Lazy Route</h1>
<p id="lazy-route-content">This route was lazily loaded</p>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { Form } from 'react-router';
import type { Route } from './+types/server-action';

export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
const name = formData.get('name')?.toString() || '';
await new Promise(resolve => setTimeout(resolve, 100));
return { success: true, name };
}

export default function ServerActionPage({ actionData }: Route.ComponentProps) {
return (
<div>
<h1>Server Action Page</h1>
<Form method="post">
<input type="text" name="name" defaultValue="sentry" />
<button type="submit">Submit</button>
</Form>
{actionData?.success && <div>Action completed for: {actionData.name}</div>}
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import type { Route } from './+types/server-loader';

export async function loader() {
await new Promise(resolve => setTimeout(resolve, 100));
return { data: 'burritos' };
}

export default function ServerLoaderPage({ loaderData }: Route.ComponentProps) {
const { data } = loaderData;
return (
<div>
<h1>Server Loader Page</h1>
<div>{data}</div>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import { Link } from 'react-router';

export default function SsrPage() {
return (
<div>
<h1>SSR Page</h1>
<nav>
<Link to="/performance">Back to Performance</Link>
</nav>
</div>
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
export default function StaticPage() {
return (
<div>
<h1>Static Page</h1>
</div>
);
}
Loading
Loading