Configure your Mastra instance with OpenTelemetry exporter pointing to LangWatch:
import { Agent } from "@mastra/core/agent";import { Mastra } from "@mastra/core";import { openai } from "@ai-sdk/openai";import { Observability } from "@mastra/observability";import { OtelExporter } from "@mastra/otel-exporter";import { LibSQLStore } from "@mastra/libsql";export const mastra = new Mastra({ agents: { assistant: new Agent({ name: "assistant", instructions: "You are a helpful assistant.", model: openai("gpt-6-luna"), }), }, storage: new LibSQLStore({ id: "mastra-storage", url: "file:./mastra.db" }), observability: new Observability({ configs: { langwatch: { serviceName: "<project_name>", exporters: [ new OtelExporter({ provider: { custom: { endpoint: "https://app.langwatch.ai/api/otel/v1/traces", headers: { Authorization: `Bearer ${process.env.LANGWATCH_API_KEY}` }, }, }, }), ], }, }, }),});
Mastra automatically sends traces to LangWatch through the OpenTelemetry exporter. All agent interactions, tool calls, and workflow executions will be captured.
Run the example. The SDK flushes pending spans when the process exits. Then open your project in LangWatch: a new trace appears in the traces list within a few seconds. Open it to see the Mastra agent run and its model calls.If no trace appears, check that LANGWATCH_API_KEY is set in the environment the process runs in.