Skip to main content

DatadogExporter

将追踪数据发送到 Datadog 的 LLM 可观察性产品,用于监控和分析。

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

构造函数
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;
}

扩展自 BaseExporterConfig,包括:

🌐 Extends BaseExporterConfig, which includes:

  • logger?: IMastraLogger - 记录器实例
  • logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error' - 日志级别(默认:INFO)

方法
Direct link to 方法

🌐 Methods

exportTracingEvent
Direct link to exportTracingEvent

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

将跟踪事件导出到 Datadog LLM 可观测性。

🌐 Exports a tracing event to Datadog LLM Observability.

flush
Direct link to flush

async flush(): Promise<void>

强制将任何缓冲的跨度刷新到 Datadog,而不关闭导出器。在无服务器环境中非常有用,可以确保在运行时终止之前导出跨度。

🌐 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>

刷新挂起的数据并关闭导出器。取消任何挂起的清理计时器并禁用 LLM 可观测性。

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

用法
Direct link to 用法

🌐 Usage

零配置(使用环境变量)
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();

显式配置
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",
});

使用本地 Datadog 代理
Direct link to 使用本地 Datadog 代理

🌐 With Local Datadog Agent

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

跨度映射
Direct link to 跨度映射

🌐 Span Mapping

Mastra跨度类型映射到Datadog LLMObs跨度种类:

🌐 Mastra span types are mapped to Datadog LLMObs span kinds:

Mastra Span 类型Datadog 类型
AGENT_RUNagent
MODEL_GENERATIONworkflow
MODEL_STEPllm
TOOL_CALLtool
MCP_TOOL_CALLtool
WORKFLOW_RUNworkflow
所有其他类型task

所有未映射的跨度类型(包括 MODEL_CHUNKWORKFLOW_STEPGENERIC 以及未来的跨度类型)都会自动默认为 task

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

环境变量
Direct link to 环境变量

🌐 Environment Variables

导出器从这些环境变量中读取配置:

🌐 The exporter reads configuration from these environment variables:

变量描述
DD_API_KEYDatadog API 密钥
DD_LLMOBS_ML_APPML 应用名称
DD_SITEDatadog 站点
DD_ENV环境名称
DD_LLMOBS_AGENTLESS_ENABLED设置为 'false' 或 '0' 以使用本地代理