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_KEYmust be server-only (noNEXT_PUBLIC_)- Use static
routepatterns to avoid high cardinality - For Server Actions calling external APIs, use manual
client.track()
