DatadogExporter
将追踪数据发送到 Datadog 的 LLM 可观察性产品,用于监控和分析。
🌐 Sends Tracing data to Datadog's LLM Observability product for monitoring and analytics.
构造函数Direct link to 构造函数
🌐 Constructor
new DatadogExporter(config: DatadogExporterConfig)
DatadogExporterConfigDirect 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
exportTracingEventDirect link to exportTracingEvent
async exportTracingEvent(event: TracingEvent): Promise<void>
将跟踪事件导出到 Datadog LLM 可观测性。
🌐 Exports a tracing event to Datadog LLM Observability.
flushDirect 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.
shutdownDirect 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_RUN | agent |
MODEL_GENERATION | workflow |
MODEL_STEP | llm |
TOOL_CALL | tool |
MCP_TOOL_CALL | tool |
WORKFLOW_RUN | workflow |
| 所有其他类型 | task |
所有未映射的跨度类型(包括 MODEL_CHUNK、WORKFLOW_STEP、GENERIC 以及未来的跨度类型)都会自动默认为 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_KEY | Datadog API 密钥 |
DD_LLMOBS_ML_APP | ML 应用名称 |
DD_SITE | Datadog 站点 |
DD_ENV | 环境名称 |
DD_LLMOBS_AGENTLESS_ENABLED | 设置为 'false' 或 '0' 以使用本地代理 |