Protip: wanna to get started even faster? Copy our llms.txt and ask an AI to do this integration
Prerequisites
- Create an API key from Settings → API Keys. See the API Keys guide for details.
Installation
Configuration
EnsureLANGWATCH_API_KEY is set:
- Environment variable
- Client parameters
.env
If you are using a service API key (e.g. for CI/CD or multi-project setups), you must also set
LANGWATCH_PROJECT_ID so the SDK knows which project to send traces to. You can find the project ID in your project settings. Project API keys obtained via npx langwatch login or from the project settings page already have the project context built in.Basic Concepts
- Each message triggering your LLM pipeline as a whole is captured with a Trace.
- A Trace contains multiple Spans, which are the steps inside your pipeline.
- Traces can be grouped together on LangWatch Dashboard by having the same
thread_idin their metadata, making the individual messages become part of a conversation.- It is also recommended to provide the
user_idmetadata to track user analytics.
- It is also recommended to provide the
Installation
Usage
The LangWatch API key is configured by default via the
LANGWATCH_API_KEY environment variable.experimental_telemetry.isEnabled is set to true. For Next.js applications, configure OpenTelemetry in your instrumentation.ts file using LangWatchExporter.
Metadata
Passexperimental_telemetry.metadata to tag the call. LangWatch reads these
keys from it:
Any other key becomes custom metadata on the trace, filterable by its own name.
experimental_telemetry is the AI SDK’s own experimental API, and its shape
can change between AI SDK versions.
It accepts strings, numbers, booleans and arrays of them as metadata values. It
does not accept a nested object, so flatten anything deeper into separate keys.
A null inside a labels array is dropped.
A thread_id, user_id, customer_id or metadata.<key> you also set as a
span attribute wins over the one you pass here. Labels are the exception: the
two sets are combined, so the trace keeps both. See
Capturing Metadata and Attributes
for the attribute names.
Related
- Capturing RAG - Learn how to capture RAG data from retrievers and tools
- Capturing Metadata and Attributes - Add custom metadata and attributes to your traces and spans
- Capturing Evaluations & Guardrails - Log evaluations and implement guardrails in your Vercel AI SDK applications