Skip to main content
Mastra 1.0 is available 🎉 Read announcement

DatadogExporter

Sends Tracing data to Datadog's LLM Observability product for monitoring and analytics.

Constructor
Direct link to Constructor

new DatadogExporter(config: DatadogExporterConfig)

DatadogExporterConfig
Direct link to DatadogExporterConfig

interface DatadogExporterConfig extends BaseExporterConfig {
apiKey?: string;
mlApp?: string;
site?: string;
service?: string;
env?: string;
agentless?: boolean;
integrationsEnabled?: boolean;
}

Extends BaseExporterConfig, which includes:

  • logger?: IMastraLogger - Logger instance
  • logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error' - Log level (default: INFO)

Methods
Direct link to Methods

exportTracingEvent
Direct link to exportTracingEvent

async exportTracingEvent(event: TracingEvent): Promise<void>

Exports a tracing event to Datadog LLM Observability.

flush
Direct link to flush

async flush(): Promise<void>

Force flushes any buffered spans to Datadog without shutting down the exporter. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.

shutdown
Direct link to shutdown

async shutdown(): Promise<void>

Flushes pending data and shuts down the exporter. Cancels any pending cleanup timers and disables LLM Observability.

Usage
Direct link to Usage

Zero-Config (using environment variables)
Direct link to Zero-Config (using environment variables)

import { DatadogExporter } from "@mastra/datadog";

// Reads from DD_LLMOBS_ML_APP, DD_API_KEY, DD_SITE, DD_ENV
const exporter = new DatadogExporter();

Explicit Configuration
Direct link to Explicit Configuration

import { DatadogExporter } from "@mastra/datadog";

const exporter = new DatadogExporter({
mlApp: "my-llm-app",
apiKey: process.env.DD_API_KEY,
site: "datadoghq.com",
env: "production",
});

With Local Datadog Agent
Direct link to With Local Datadog Agent

const exporter = new DatadogExporter({
mlApp: "my-llm-app",
agentless: false, // Use local Datadog Agent
env: "production",
});

Span Mapping
Direct link to Span Mapping

Mastra span types are mapped to Datadog LLMObs span kinds:

Mastra SpanTypeDatadog Kind
AGENT_RUNagent
MODEL_GENERATIONworkflow
MODEL_STEPllm
TOOL_CALLtool
MCP_TOOL_CALLtool
WORKFLOW_RUNworkflow
All other typestask

All unmapped span types (including MODEL_CHUNK, WORKFLOW_STEP, GENERIC, and future span types) automatically default to task.

Environment Variables
Direct link to Environment Variables

The exporter reads configuration from these environment variables:

VariableDescription
DD_API_KEYDatadog API key
DD_LLMOBS_ML_APPML application name
DD_SITEDatadog site
DD_ENVEnvironment name
DD_LLMOBS_AGENTLESS_ENABLEDSet to 'false' or '0' to use local agent