Configuration

Full reference for @sophonz/nextjs configuration — the shared SophonzNextConfig options, environment variables, the defaults it sets, and reaching the underlying browser and Node.js SDK options.

Both halves of the app share one SophonzNextConfig, resolved by resolveConfig(). Pass it to register() on the server and to <SophonzProvider> on the client — or set nothing and let both sides read the same NEXT_PUBLIC_SOPHONZ_* environment variables.

Config passed in wins

import { resolveConfig } from '@sophonz/nextjs';

resolveConfig(input?) merges an explicit config object over the environment: any field you pass wins, and anything you omit falls back to the matching NEXT_PUBLIC_SOPHONZ_* variable. register() and SophonzProvider both call it internally, so configuring only the environment — or passing the same object to each — keeps the two sides in sync.

SophonzNextConfig

OptionTypeEnv varDescription
collectorUrlstringNEXT_PUBLIC_SOPHONZ_COLLECTOR_URLOTLP collector base URL.
appNamestringNEXT_PUBLIC_SOPHONZ_APP_NAMESent as service.name from both sides.
appVersionstringNEXT_PUBLIC_SOPHONZ_APP_VERSIONSent as service.version.
appKeystringNEXT_PUBLIC_SOPHONZ_APP_KEYSophonz ingestion key, sent as service.key. An ingestion key rather than an access token, so it reaches the browser.
projectstring (optional)NEXT_PUBLIC_SOPHONZ_PROJECTSent as service.namespace.
deploymentEnvironmentstring (optional)NEXT_PUBLIC_SOPHONZ_ENVIRONMENTe.g. production.
tracePropagationTargets(string | RegExp)[] (optional)—Origins the browser attaches traceparent to. Unset means same-origin only.
debugboolean (optional)NEXT_PUBLIC_SOPHONZ_DEBUGVerbose logging on both sides.
browserRecord<string, unknown> (optional)—Passed through to @sophonz/browser-sdk's init().
serverRecord<string, unknown> (optional)—Passed through to @sophonz/node-sdk's initSDK().

collectorUrl, appName, appVersion, and appKey are required. register() and SophonzProvider both warn and skip initialization if any is missing — see Checking what is missing below.

NOTE — How debug is parsed

NEXT_PUBLIC_SOPHONZ_DEBUG is read as true for any value except "false" or "0", so a string like "no" turns it on. Leave it unset to keep it off.

Defaults this package sets

These apply on top of whatever you pass through server / browser. Your values win where they overlap with the underlying SDK's own defaults.

  • tracePropagationTargets — current origin only, when you don't set one. Add the origin of any separate API you also instrument; that origin's CORS config needs to allow the traceparent header.
  • Server betaMode: true — required for @sophonz/node-sdk's setTraceAttributes() to work.
  • Server disableStartupLogs: true — suppresses the Node.js SDK's startup spinner, which is noise in a server or serverless log stream.
  • Browser disableIntercom: true — otherwise the browser SDK polls for a global Intercom and logs an error when your app doesn't use it. Opt back in with browser: { disableIntercom: false }.

Reaching underlying SDK options

Anything @sophonz/browser-sdk or @sophonz/node-sdk accepts is reachable through browser / server:

// instrumentation.ts
import { register as sophonz } from '@sophonz/nextjs/server';
 
export const register = () =>
  sophonz({
    appName: 'my-app',
    server: { advancedNetworkCapture: true },
  });
// app/layout.tsx
<SophonzProvider
  appName="my-app"
  tracePropagationTargets={[/^https:\/\/api\.example\.com/]}
  browser={{ disableReplay: false }}
/>

See the Node.js SDK configuration and the Web SDK configuration reference for the full option lists each underlying SDK accepts.

Checking what is missing

import { resolveConfig, missingFields } from '@sophonz/nextjs';
 
const config = resolveConfig({ appName: 'my-app' });
missingFields(config); // e.g. ['collectorUrl', 'appVersion', 'appKey']

missingFields() reports which of collectorUrl, appName, appVersion, and appKey are still empty — the same check register() and SophonzProvider run before starting anything.

register() result

import { register } from '@sophonz/nextjs/server';
 
const result = await register();
// { started: boolean, reason?: 'edge-runtime' | 'already-started' | 'incomplete-config', missing?: string[] }

reason explains why started is false: the call happened in the Edge runtime, the server SDK was already running in this process, or required config was missing (in which case missing lists the field names).

Setting request attributes

Next.js has no middleware chain, so the Node.js SDK's Express/Koa/Fastify helpers don't apply. Call setTraceAttributes() from @sophonz/node-sdk inside a Route Handler instead:

import { setTraceAttributes } from '@sophonz/node-sdk';
 
export async function GET() {
  setTraceAttributes({ 'user.id': userId });
}

This reaches the active span only while server.betaMode is on, which Defaults this package sets turns on for you.