Datadog Agent Observability
Datadog Agent Observability helps AI engineers, data scientists, and application developers quickly develop, evaluate, and monitor agentic applications. Confidently improve output quality, performance, costs, and overall risk with structured experiments, end-to-end tracing across AI agents, and evaluations.
Datadog Agent Observability fully supports:
- Cost tracking
- Prompt tracking and management
- Online and offline evaluations
- Experiments
Setup
1. Account setup and API key
Create a Datadog account if you do not have one, and provision an API key.
2. Choose a way to send traces
- Use OpenTelemetry to send the AI SDK's GenAI spans to Datadog through an OTLP exporter.
- Use
dd-trace, the Datadog Agent Observability SDK to send directly to Datadog Agent Observability.
On top of these setup steps, there are no changes necessary when using the ai SDK.
OpenTelemetry
Datadog accepts spans that follow the OpenTelemetry GenAI semantic conventions. Use the AI SDK's OpenTelemetry integration from @ai-sdk/otel.
Next.jsNode.js
Install the OpenTelemetry packages:
npm install @ai-sdk/otel @opentelemetry/api @vercel/otelRegister the OpenTelemetry provider before the AI SDK OpenTelemetry integration:
import { OpenTelemetry } from '@ai-sdk/otel';
import { registerTelemetry } from 'ai';
import { OTLPHttpProtoTraceExporter, registerOTel } from '@vercel/otel';
export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
const ddSite = process.env.DD_SITE || 'datadoghq.com';
registerOTel({
serviceName: 'my-ai-app',
traceExporter: new OTLPHttpProtoTraceExporter({
url: `https://otlp.${ddSite}/v1/traces`,
headers: {
'dd-api-key': process.env.DD_API_KEY!,
'dd-otlp-source': 'llmobs',
},
}),
});
registerTelemetry(new OpenTelemetry());
}
}Install the OpenTelemetry SDK and HTTP/protobuf exporter:
npm install @ai-sdk/otel @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-protoCreate an instrumentation module that starts the Node.js OpenTelemetry SDK before registering the AI SDK integration:
import { OpenTelemetry } from '@ai-sdk/otel';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { registerTelemetry } from 'ai';
const ddSite = process.env.DD_SITE || 'datadoghq.com';
export const sdk = new NodeSDK({
serviceName: 'my-ai-app',
traceExporter: new OTLPTraceExporter({
url: `https://otlp.${ddSite}/v1/traces`,
headers: {
'dd-api-key': process.env.DD_API_KEY,
'dd-otlp-source': 'llmobs',
},
}),
});
sdk.start();
registerTelemetry(new OpenTelemetry());Set DD_API_KEY and DD_SITE in your shell environment, then load the instrumentation module before your application starts:
node --import ./instrumentation.mjs your-app.mjsFor scripts, import sdk from the instrumentation module and call await sdk.shutdown() after all AI SDK calls and streams finish. See the OpenTelemetry NodeSDK reference.
Set DD_SITE to the datacenter configured for your Datadog account.
The serviceName identifies the application in OpenTelemetry. Datadog uses the root span's service to set the ml_app value in Agent Observability.
Datadog Agent Observability SDK (dd-trace)
Note
The tracer does not support Edge runtime routes; use the Node.js runtime for routes that make AI SDK calls.
npm install dd-traceNext.jsNode.js
Add dd-trace and ai to serverExternalPackages in next.config.ts so they can be properly auto-instrumented.
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
serverExternalPackages: ['dd-trace', 'ai'],
};
export default nextConfig;Set these variables before the Next.js process starts:
DD_LLMOBS_ENABLED=1
DD_LLMOBS_ML_APP=my-ai-app
DD_SITE=<YOUR_DATADOG_SITE>
DD_API_KEY=<YOUR_DATADOG_API_KEY>Create instrumentation.ts alongside the application's app or pages directory:
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
const initializeImportName = 'dd-trace/initialize.mjs';
await import(initializeImportName as string);
}
}If you can set NODE_OPTIONS in your environment, it is recommended to use it instead of the instrumentation.ts setup:
NODE_OPTIONS="--import dd-trace/initialize.mjs"Set this option and the other Datadog variables in the same environment before starting the Next.js process. This loads dd-trace early enough to instrument server-side calls.
Set these variables in your shell before starting the Node.js process:
export DD_LLMOBS_ENABLED=1
export DD_LLMOBS_AGENTLESS_ENABLED=true
export DD_LLMOBS_ML_APP=my-ai-app
export DD_SITE='<YOUR_DATADOG_SITE>'
export DD_API_KEY='<YOUR_DATADOG_API_KEY>'DD_LLMOBS_AGENTLESS_ENABLED sends traces directly to Datadog without a Datadog Agent. This follows Datadog's AI SDK integration setup.
Load dd-trace before your application imports the AI SDK:
node --import dd-trace/initialize.mjs app.mjsSee the Datadog Node.js quickstart.
Troubleshooting
Not seeing traces? Try one of the following options to help debug:
- If using
dd-trace, enable debug logs (DD_TRACE_DEBUG=true) to see detailed tracer execution logs - Double-check your API and Datadog site are set correctly
- Ensure all environment variables are set before the Datadog Agent Observability or OpenTelemetry SDK is initialized
Open a GitHub issue or a support ticket for more assistance.