React Quick Start
It adds the Traceway React SDK and the source map upload to your release build, and checks that data arrives. How the setup skill works
Integrate Traceway into your React application with the @tracewayapp/react package.
Upgrading from 2.0 or 1.x? See Upgrading.
Installation
npm install @tracewayapp/reactSetup
Wrap your application with TracewayProvider and give it the project token:
import { TracewayProvider } from "@tracewayapp/react";
function App() {
return (
<TracewayProvider token={import.meta.env.VITE_TRACEWAY_TOKEN}>
<YourApp />
</TracewayProvider>
);
}
export default App;# .env
VITE_TRACEWAY_TOKEN=YOUR_TOKENThe project's Connection page in Traceway shows the token. Next.js reads it from NEXT_PUBLIC_TRACEWAY_TOKEN (see Next.js App Router). The SDK sends to Traceway Cloud; for a self-hosted server, also pass its address as baseUrl={import.meta.env.VITE_TRACEWAY_URL}.
The provider runs init() once, which installs the handlers for uncaught errors and unhandled rejections, instruments console.*, fetch / XHR, the History API and clicks, and starts the replay recorder. It also acts as an error boundary: render-time exceptions thrown anywhere in the tree are captured and re-thrown, so your app behaves exactly as it would without Traceway installed.
A provider that cannot start the SDK, such as a build without its token, does not break the render: the app renders as usual, the SDK stays off, and the console shows one warning that says what is missing.
Custom fallback UI? If you want to replace a crashed subtree with a fallback view instead of letting the error propagate, wrap the relevant section in
TracewayErrorBoundary. It's still exported for that purpose, but is no longer required for capture.
React StrictMode double-invokes the provider's constructor in development. That is harmless: the second init() is a no-op, so there is still one SDK client. See A note on StrictMode.
Session capture
Errors and messages are sent as they happen, and session start and end are reported for every visit. Console output, requests, navigation, clicks and the session replay stay on the device until they are needed: a captured error uploads a 30-second replay clip and up to 10 minutes of those breadcrumbs. Configure Session Capture shows how to hide private content, record whole sessions or journeys, and capture one user from the dashboard.
Capture Errors Manually
Use the useTraceway hook in components:
import { useTraceway } from "@tracewayapp/react";
function MyComponent() {
const { captureException } = useTraceway();
async function handleSubmit() {
try {
await submitForm();
} catch (error) {
captureException(error);
}
}
return <button onClick={handleSubmit}>Submit</button>;
}Every other function of the browser SDK (log, track, recordNavigation, startInteraction, tracer, flush, …) is exported from @tracewayapp/react too; see Without a Hook.
With Options
Every option of the browser SDK goes in options:
<TracewayProvider
token={import.meta.env.VITE_TRACEWAY_TOKEN}
options={{
debug: true,
version: "1.0.0",
}}
>
<YourApp />
</TracewayProvider>Next.js App Router
@tracewayapp/react ships with the "use client" directive, so TracewayProvider goes straight into app/layout.tsx, a Server Component, with no wrapper file:
// app/layout.tsx
import { TracewayProvider } from "@tracewayapp/react";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<TracewayProvider token={process.env.NEXT_PUBLIC_TRACEWAY_TOKEN}>
{children}
</TracewayProvider>
</body>
</html>
);
}During server rendering the provider renders its children and the SDK does not start (there is no window), so server-side errors are not reported by it. Server code (route handlers, server actions, a util shared by server and client) imports the plain functions from @tracewayapp/frontend, which do nothing on the server. To name pages by their route, render the TracewayRoute component from useTracewayRoute in the same layout. For the server half of the app, see Next.js.
Test Your Integration
import { useTraceway } from "@tracewayapp/react";
function TestButton() {
const { captureException } = useTraceway();
return (
<button onClick={() => captureException(new Error("Test error"))}>
Send Test Error
</button>
);
}Click the button and check your Traceway dashboard to verify the error appears. With debug: true in options, the browser console shows Traceway: started (https://cloud.tracewayapp.com/api/otel/v1/logs), session … when the SDK starts.
Distributed Tracing
The SDK records fetch and XMLHttpRequest calls as OpenTelemetry CLIENT spans and sends the W3C traceparent header on same-origin requests, which a backend instrumented with OpenTelemetry picks up with no extra middleware. The browser request and the backend work it caused then show up in one trace. For an API on another origin, list it in the propagateTraceHeaderCorsUrls option. See Distributed Tracing.
Platform Support
| Environment | Error Tracking | Session Replay |
|---|---|---|
| React 18+ in any modern browser | Yes | Yes |
| Next.js (App and Pages Router) | Yes | Yes |
| Vite, Create React App, Remix | Yes | Yes |
| React Native, Expo | Use @tracewayapp/react-native | No |
Next Steps
- Configure Session Capture - Masks, images, which sessions upload, captures and rules
- TracewayProvider - Configuration options
- Error Boundary - Custom fallback UI for a subtree
- Hooks - Manual error capture, route names, attributes
- Initialization - Every SDK option
- Session Replay - What is recorded and when it uploads
- Distributed Tracing - Frontend ↔ backend correlation
- Next.js - Next.js and Remix apps: this SDK covers the browser half, OpenTelemetry covers the server half
- Project Structure - Why the browser half and the server half are two separate Traceway projects