Next.js

The Sophonz Next.js SDK gives App Router apps one config for browser and server monitoring — SophonzProvider on the client, register() on the server, sharing a single trace.

@sophonz/nextjs wires up both halves of a Next.js app from one config: @sophonz/browser-sdk on the client and @sophonz/node-sdk on the server. Because both read the same SophonzNextConfig, a page's browser span and the Route Handler that served it land on the same trace.

When to use it

  • App Router apps that want browser and server telemetry joined into a single trace, from one config instead of two.
  • Projects that would otherwise wire up @sophonz/browser-sdk and @sophonz/node-sdk by hand and keep their app name and key in sync manually.
  • If you only need one side — or you're on the Pages Router, or a non-Next Node server — use the Web SDK or Node.js SDK directly instead.

What you get

  • SophonzProvider — a Client Component you mount once in app/layout.tsx. It initializes @sophonz/browser-sdk on mount, dynamically imported so it costs nothing until after hydration.
  • register() — a server entry point wired through instrumentation.ts. It starts @sophonz/node-sdk before any request is handled, so auto-instrumentation can patch modules in time. It no-ops on the Edge runtime.
  • Shared config resolution — both halves call the same resolveConfig(), so appName, appVersion, appKey, project, and deploymentEnvironment come from one set of NEXT_PUBLIC_SOPHONZ_* environment variables, or the same config object if you configure in code.
  • A joined trace — the browser attaches traceparent to same-origin requests by default, so a page load and the API route it calls show up on one trace.

How it works

  1. Client — SophonzProvider resolves SophonzNextConfig against the environment and dynamically imports @sophonz/browser-sdk on mount.
  2. Server — register(), called once per server process from instrumentation.ts, resolves the same config, points the server SDK's OTLP endpoints at collectorUrl, and calls @sophonz/node-sdk's initSDK().
  3. Both sides apply Sophonz-recommended defaults on top: the server turns on betaMode (needed for setTraceAttributes()) and disables its startup banner; the browser disables Intercom-presence polling.

Next steps

  • Installation — install the package and wire up both halves.
  • Configuration — the full SophonzNextConfig option reference.