/** * Datadog Bridge for Mastra Observability * * This bridge enables bidirectional integration with dd-trace: * 1. Creates real dd-trace APM spans eagerly when Mastra spans are created * 2. Activates spans in dd-trace's scope so auto-instrumented operations * (HTTP requests, database queries, etc.) have correct parent spans * 3. Registers those same spans with Datadog LLMObs and annotates them * before finish, avoiding a second synthetic APM span tree * * This fixes the core problem with the DatadogExporter: because the exporter * creates LLMObs spans retroactively (after execution completes), there is no * active dd-trace span in scope when tools and processors make outbound calls. * dd-trace's auto-instrumentation can't find the correct parent, so APM spans * fall back to the nearest active span (typically the request handler). */ import type { TracingEvent, ObservabilityBridge, CreateSpanOptions, ScoreEvent, SpanType, SpanIds } from '@mastra/core/observability'; import { BaseExporter } from '@mastra/observability'; import type { BaseExporterConfig } from '@mastra/observability'; /** * Configuration options for the Datadog Bridge. */ export interface DatadogBridgeConfig extends BaseExporterConfig { /** * Datadog API key. Required in agentless mode. * Falls back to DD_API_KEY environment variable. */ apiKey?: string; /** * ML application name for grouping traces. * Required - falls back to DD_LLMOBS_ML_APP environment variable. */ mlApp?: string; /** * Datadog site (e.g., 'datadoghq.com', 'datadoghq.eu'). * Falls back to DD_SITE environment variable, defaults to 'datadoghq.com'. */ site?: string; /** * Service name for the application. * Falls back to mlApp if not specified. */ service?: string; /** * Environment name (e.g., 'production', 'staging'). * Falls back to DD_ENV environment variable. */ env?: string; /** * Use agentless mode (direct HTTPS intake without a local Datadog Agent). * * Defaults to `false` for the bridge — most users running dd-trace * auto-instrumentation already have a local Datadog Agent (required for * APM data). Agentless mode only routes LLMObs data directly to Datadog * intake, which would split your APM and LLMObs telemetry across two * paths. * * Set to `true` if you only want LLMObs data (no APM auto-instrumentation) * and don't have a local Datadog Agent. Falls back to the * `DD_LLMOBS_AGENTLESS_ENABLED` environment variable. */ agentless?: boolean; /** * Enable dd-trace automatic integrations (HTTP, database, etc.). * Defaults to true since the bridge is designed for APM integration. */ integrationsEnabled?: boolean; /** * Keys from the request context that should be promoted to flat Datadog * LLM Observability tags instead of being nested in annotations.metadata. */ requestContextKeys?: string[]; } /** * Datadog Bridge for Mastra Observability. * * Creates native dd-trace spans in real time during execution for proper APM * context propagation, and uses the same live dd span for Datadog LLMObs * tagging and annotations. */ export declare class DatadogBridge extends BaseExporter implements ObservabilityBridge { name: string; private config; private ddSpanMap; private traceContext; private openSpanCounts; constructor(config?: DatadogBridgeConfig); /** * Create a dd-trace span eagerly when a Mastra span is constructed. */ createSpan(options: CreateSpanOptions): SpanIds | undefined; /** * Execute an async function within the dd-trace context of a Mastra span. */ executeInContext(spanId: string, fn: () => Promise): Promise; /** * Execute a synchronous function within the dd-trace context of a Mastra span. */ executeInContextSync(spanId: string, fn: () => T): T; onScoreEvent(event: ScoreEvent): Promise; private executeWithSpanContext; /** * Handle tracing events from the observability bus. */ protected _exportTracingEvent(event: TracingEvent): Promise; private registerLlmObsSpan; private getLlmObsTagger; /** * Annotate the eagerly-created dd span and finish it using the final Mastra * span state. */ private annotateAndFinishSpan; private captureTraceContext; private resolveTraceContext; private releaseTraceContext; private buildAnnotations; private setErrorTags; flush(): Promise; shutdown(): Promise; } //# sourceMappingURL=bridge.d.ts.map