Datadog Exporter
Datadog is a comprehensive monitoring platform with dedicated LLM Observability features. The Datadog exporter sends your traces to Datadog's LLM Observability product, providing insights into model performance, token usage, and conversation flows.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/datadog@latest
pnpm add @mastra/datadog@latest
yarn add @mastra/datadog@latest
bun add @mastra/datadog@latest
ConfigurationDirect link to Configuration
PrerequisitesDirect link to Prerequisites
- Datadog Account: Sign up at datadoghq.com with LLM Observability enabled
- API Key: Get your API key from Datadog Organization Settings → API Keys
- Environment Variables: Set your credentials
DD_API_KEY=your-datadog-api-key
DD_LLMOBS_ML_APP=my-llm-app
DD_SITE=datadoghq.com # Optional: defaults to datadoghq.com
DD_ENV=production # Optional: environment name
Zero-Config SetupDirect link to Zero-Config Setup
With environment variables set, use the exporter with no configuration:
import { Mastra } from "@mastra/core";
import { Observability } from "@mastra/observability";
import { DatadogExporter } from "@mastra/datadog";
export const mastra = new Mastra({
observability: new Observability({
configs: {
datadog: {
serviceName: "my-service",
exporters: [new DatadogExporter()],
},
},
}),
});
Explicit ConfigurationDirect link to Explicit Configuration
You can also pass credentials directly (takes precedence over environment variables):
import { Mastra } from "@mastra/core";
import { Observability } from "@mastra/observability";
import { DatadogExporter } from "@mastra/datadog";
export const mastra = new Mastra({
observability: new Observability({
configs: {
datadog: {
serviceName: "my-service",
exporters: [
new DatadogExporter({
mlApp: process.env.DD_LLMOBS_ML_APP!,
apiKey: process.env.DD_API_KEY!,
}),
],
},
},
}),
});
Configuration OptionsDirect link to Configuration Options
Complete ConfigurationDirect link to Complete Configuration
new DatadogExporter({
// Required settings
mlApp: process.env.DD_LLMOBS_ML_APP!, // Groups traces under this ML app name
apiKey: process.env.DD_API_KEY!, // Required for agentless mode (default)
// Optional settings
site: "datadoghq.com", // Datadog site (datadoghq.eu, us3.datadoghq.com, etc.)
service: "my-service", // Service name (defaults to mlApp)
env: "production", // Environment name
agentless: true, // true = direct HTTPS, false = local Datadog Agent
// Advanced settings
integrationsEnabled: false, // Enable dd-trace auto-instrumentation
// Diagnostic logging
logLevel: "info", // debug | info | warn | error
});
With Local Datadog AgentDirect link to With Local Datadog Agent
If you have a Datadog Agent running locally, you can route traces through it instead of direct HTTPS:
new DatadogExporter({
mlApp: process.env.DD_LLMOBS_ML_APP!,
agentless: false, // Use local Datadog Agent
env: "production",
});
Note: When using agent mode, the API key is read from the local agent's configuration.
Span Type MappingDirect link to Span Type Mapping
Mastra span types are automatically mapped to Datadog LLMObs span kinds:
| Mastra SpanType | Datadog Kind |
|---|---|
AGENT_RUN | agent |
MODEL_GENERATION | workflow |
MODEL_STEP | llm |
TOOL_CALL | tool |
MCP_TOOL_CALL | tool |
WORKFLOW_RUN | workflow |
| Other workflow types | task |
GENERIC | task |
Other/future Mastra span types will default to 'task' when mapped unless specified.
TroubleshootingDirect link to Troubleshooting
Native module ABI mismatchDirect link to Native module ABI mismatch
If you see errors like:
Error: No native build was found for runtime=node abi=137 platform=linuxglibc arch=x64
This indicates a Node.js version compatibility issue with dd-trace's native modules. These native modules are optional and provide performance monitoring features.
Solutions:
-
Use Node.js 22.x: Native modules have the best compatibility with Node.js 22.x.
-
Ignore native module warnings: The native modules (
@datadog/native-metrics,@datadog/native-appsec, etc.) are optional. If they fail to load, core tracing functionality still works.
Bundler externals configurationDirect link to Bundler externals configuration
When using bundlers like esbuild, webpack, or the Mastra CLI bundler, you may need to mark dd-trace and its dependencies as external:
export const mastra = new Mastra({
bundler: {
externals: [
"dd-trace",
"@datadog/native-metrics",
"@datadog/native-appsec",
"@datadog/native-iast-taint-tracking",
"@datadog/pprof",
],
},
});