Next.js Setup
Add DeepTracer to your Next.js app in under 5 minutes.
Install the package
npm install @deeptracer/nextjspnpm add @deeptracer/nextjsyarn add @deeptracer/nextjsbun add @deeptracer/nextjsGet your API key
- Sign up at app.deeptracer.dev
- Create a project
- Copy your API key (starts with
dt_)
Add environment variables
Create or update your .env.local file:
DEEPTRACER_KEY=dt_your_api_key_here
DEEPTRACER_ENDPOINT=https://ingest.deeptracer.dev
# Client-side (for browser error tracking)
NEXT_PUBLIC_DEEPTRACER_KEY=dt_your_api_key_here
NEXT_PUBLIC_DEEPTRACER_ENDPOINT=https://ingest.deeptracer.devUse the same API key for both server and client. DeepTracer uses a single key per project — no public/secret split needed.
Add server-side monitoring
Create instrumentation.ts in your project root (next to package.json):
import { init } from "@deeptracer/nextjs"
export const { register, onRequestError, logger } = init()That's it. This single file:
- Captures all server errors automatically
- Traces every request through your app
- Gives you a
loggeryou can import anywhere for custom logging
Add client-side monitoring
Update your root layout to wrap your app with DeepTracerProvider:
import { DeepTracerProvider } from "@deeptracer/nextjs/client"
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<DeepTracerProvider>
{children}
</DeepTracerProvider>
</body>
</html>
)
}This captures browser errors (crashes, unhandled promise rejections) and sends them to your dashboard.
Add error pages (optional but recommended)
These give your users a nice error page while automatically reporting the error to DeepTracer.
"use client"
export { DeepTracerErrorPage as default } from "@deeptracer/react""use client"
export { DeepTracerErrorPage as default } from "@deeptracer/react"Deploy and verify
Deploy your app (or run npm run dev locally). Then check your DeepTracer dashboard — you should see data appearing within seconds.
Tip: Throw a test error to verify everything works:
// In any server component or API route:
throw new Error("Testing DeepTracer!")You'll see it appear in your dashboard's Errors tab within seconds.
Optional: Source maps
Source maps let DeepTracer show you the original source code in stack traces instead of minified code.
import { withDeepTracer } from "@deeptracer/nextjs/config"
export default withDeepTracer({
// your existing Next.js config
})Source maps are uploaded automatically during next build when running on Vercel or CI.
What's next?
- Log custom events — Add
logger.info()andlogger.error()calls to your code - Track AI costs — Monitor your OpenAI/Anthropic spend
- Set up alerts — Get Slack notifications when something breaks
- AI investigations — Let DeepTracer explain your errors