Skip to content

Next.js (App Router)

Instrument Route Handlers only — not Client Components.

typescript
// app/api/hello/route.ts
import { AmlexiaClient } from '@amlexiahq/node';
import { withAmlexia } from '@amlexiahq/node/next';

const client = new AmlexiaClient({
  sdkKey: process.env.AMLEXIA_SDK_KEY!,
});

export const GET = withAmlexia(
  client,
  async () => Response.json({ ok: true }),
  { route: '/api/hello', serviceName: 'nextjs' },
);

Rules

  • AMLEXIA_SDK_KEY must be server-only (no NEXT_PUBLIC_)
  • Use static route patterns to avoid high cardinality
  • For Server Actions calling external APIs, use manual client.track()

← Node overview