Overview

Also see the Next.js guide for a step-by-step guide with a small example app.

Next.js is a popular React framework for building web applications.

Getting Started

1. Install Laminar

npm add @lmnr-ai/lmnr

2. Initialize Laminar

To instrument your entire Next.js app, place Laminar initialization in instrumentation.{ts,js} file. Learn more about instrumentation.{ts,js} here.

instrumentation.ts
export async function register() {
  // prevent this from running in the edge runtime
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    const { Laminar } = await import('@lmnr-ai/lmnr');
    const { OpenAI } = await import('openai');
    const anthropic = await import('@anthropic-ai/sdk');

    Laminar.initialize({
      projectApiKey: process.env.LMNR_API_KEY,
      instrumentModules: {
        openAI: OpenAI,
        anthropic: anthropic
      }
    });
  }
}

instrumentation.ts is experimental in Next.js < 15.

If you use Next.js < 15, add the following to your next.config.js:

next.config.js
module.exports = {
    experimental: { instrumentationHook: true }
};