Next.js
Vercel provides a comprehensive OpenTelemetry integration through the
@vercel/otel package. After following
Vercel’s integration instructions, add the
following environment variables to your project:
OTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-api.pydantic.dev
OTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token'
This configuration directs the OpenTelemetry instrumentation to send data to Logfire.
A working example can be found in the examples/nextjs directory.
Client-side instrumentation can be implemented using the @pydantic/logfire-browser package. To set it up, you need to complete the following steps:
- Add a proxy to the Logfire traces endpoint in
proxy.tsto prevent exposing your Logfire write token. - Wrap the browser instrumentation in a client-only React component. Use
next/dynamicto ensure the component renders only in the browser (see example).
A complete working example can be found in the examples/nextjs-client-side-instrumentation directory.