@mastra/datadog 1.0.22 → 1.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # @mastra/datadog
2
2
 
3
+ ## 1.1.0-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d), [`39a3768`](https://github.com/mastra-ai/mastra/commit/39a3768a980c31ee689c675aa0015609f76191c4)]:
8
+ - @mastra/core@1.32.0-alpha.1
9
+ - @mastra/observability@1.11.1-alpha.1
10
+
11
+ ## 1.1.0-alpha.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Added a new `DatadogBridge` integration for Mastra tracing so Datadog can keep auto-instrumented HTTP, database, and framework spans nested under the agent, workflow, model, and tool spans that triggered them. ([#15716](https://github.com/mastra-ai/mastra/pull/15716))
16
+
17
+ ```typescript
18
+ import tracer from 'dd-trace';
19
+
20
+ tracer.init({
21
+ service: process.env.DD_SERVICE || 'my-mastra-app',
22
+ env: process.env.DD_ENV || 'production',
23
+ });
24
+
25
+ import { Mastra } from '@mastra/core';
26
+ import { Observability } from '@mastra/observability';
27
+ import { DatadogBridge } from '@mastra/datadog';
28
+
29
+ const mastra = new Mastra({
30
+ observability: new Observability({
31
+ configs: {
32
+ default: {
33
+ serviceName: 'my-mastra-app',
34
+ bridge: new DatadogBridge({
35
+ mlApp: process.env.DD_LLMOBS_ML_APP!,
36
+ }),
37
+ },
38
+ },
39
+ }),
40
+ });
41
+ ```
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [[`6dcd65f`](https://github.com/mastra-ai/mastra/commit/6dcd65f2a34069e6dc43ba35f1d11119b9b40bef), [`1c2dda8`](https://github.com/mastra-ai/mastra/commit/1c2dda805fbfccc0abf55d4cb20cc34402dc3f0c), [`568777e`](https://github.com/mastra-ai/mastra/commit/568777ea8af77a672270b448dfd3996f9e75a964)]:
46
+ - @mastra/core@1.31.1-alpha.0
47
+ - @mastra/observability@1.11.1-alpha.0
48
+
3
49
  ## 1.0.22
4
50
 
5
51
  ### Patch Changes
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Datadog Bridge for Mastra Observability
3
+ *
4
+ * This bridge enables bidirectional integration with dd-trace:
5
+ * 1. Creates real dd-trace APM spans eagerly when Mastra spans are created
6
+ * 2. Activates spans in dd-trace's scope so auto-instrumented operations
7
+ * (HTTP requests, database queries, etc.) have correct parent spans
8
+ * 3. Registers those same spans with Datadog LLMObs and annotates them
9
+ * before finish, avoiding a second synthetic APM span tree
10
+ *
11
+ * This fixes the core problem with the DatadogExporter: because the exporter
12
+ * creates LLMObs spans retroactively (after execution completes), there is no
13
+ * active dd-trace span in scope when tools and processors make outbound calls.
14
+ * dd-trace's auto-instrumentation can't find the correct parent, so APM spans
15
+ * fall back to the nearest active span (typically the request handler).
16
+ */
17
+ import type { TracingEvent, ObservabilityBridge, CreateSpanOptions, SpanType, SpanIds } from '@mastra/core/observability';
18
+ import { BaseExporter } from '@mastra/observability';
19
+ import type { BaseExporterConfig } from '@mastra/observability';
20
+ /**
21
+ * Configuration options for the Datadog Bridge.
22
+ */
23
+ export interface DatadogBridgeConfig extends BaseExporterConfig {
24
+ /**
25
+ * Datadog API key. Required in agentless mode.
26
+ * Falls back to DD_API_KEY environment variable.
27
+ */
28
+ apiKey?: string;
29
+ /**
30
+ * ML application name for grouping traces.
31
+ * Required - falls back to DD_LLMOBS_ML_APP environment variable.
32
+ */
33
+ mlApp?: string;
34
+ /**
35
+ * Datadog site (e.g., 'datadoghq.com', 'datadoghq.eu').
36
+ * Falls back to DD_SITE environment variable, defaults to 'datadoghq.com'.
37
+ */
38
+ site?: string;
39
+ /**
40
+ * Service name for the application.
41
+ * Falls back to mlApp if not specified.
42
+ */
43
+ service?: string;
44
+ /**
45
+ * Environment name (e.g., 'production', 'staging').
46
+ * Falls back to DD_ENV environment variable.
47
+ */
48
+ env?: string;
49
+ /**
50
+ * Use agentless mode (direct HTTPS intake without a local Datadog Agent).
51
+ *
52
+ * Defaults to `false` for the bridge — most users running dd-trace
53
+ * auto-instrumentation already have a local Datadog Agent (required for
54
+ * APM data). Agentless mode only routes LLMObs data directly to Datadog
55
+ * intake, which would split your APM and LLMObs telemetry across two
56
+ * paths.
57
+ *
58
+ * Set to `true` if you only want LLMObs data (no APM auto-instrumentation)
59
+ * and don't have a local Datadog Agent. Falls back to the
60
+ * `DD_LLMOBS_AGENTLESS_ENABLED` environment variable.
61
+ */
62
+ agentless?: boolean;
63
+ /**
64
+ * Enable dd-trace automatic integrations (HTTP, database, etc.).
65
+ * Defaults to true since the bridge is designed for APM integration.
66
+ */
67
+ integrationsEnabled?: boolean;
68
+ /**
69
+ * Keys from the request context that should be promoted to flat Datadog
70
+ * LLM Observability tags instead of being nested in annotations.metadata.
71
+ */
72
+ requestContextKeys?: string[];
73
+ }
74
+ /**
75
+ * Datadog Bridge for Mastra Observability.
76
+ *
77
+ * Creates native dd-trace spans in real time during execution for proper APM
78
+ * context propagation, and uses the same live dd span for Datadog LLMObs
79
+ * tagging and annotations.
80
+ */
81
+ export declare class DatadogBridge extends BaseExporter implements ObservabilityBridge {
82
+ name: string;
83
+ private config;
84
+ private ddSpanMap;
85
+ private traceContext;
86
+ private openSpanCounts;
87
+ constructor(config?: DatadogBridgeConfig);
88
+ /**
89
+ * Create a dd-trace span eagerly when a Mastra span is constructed.
90
+ */
91
+ createSpan(options: CreateSpanOptions<SpanType>): SpanIds | undefined;
92
+ /**
93
+ * Execute an async function within the dd-trace context of a Mastra span.
94
+ */
95
+ executeInContext<T>(spanId: string, fn: () => Promise<T>): Promise<T>;
96
+ /**
97
+ * Execute a synchronous function within the dd-trace context of a Mastra span.
98
+ */
99
+ executeInContextSync<T>(spanId: string, fn: () => T): T;
100
+ private executeWithSpanContext;
101
+ /**
102
+ * Handle tracing events from the observability bus.
103
+ */
104
+ protected _exportTracingEvent(event: TracingEvent): Promise<void>;
105
+ private registerLlmObsSpan;
106
+ private getLlmObsTagger;
107
+ /**
108
+ * Annotate the eagerly-created dd span and finish it using the final Mastra
109
+ * span state.
110
+ */
111
+ private annotateAndFinishSpan;
112
+ private captureTraceContext;
113
+ private resolveTraceContext;
114
+ private releaseTraceContext;
115
+ private buildAnnotations;
116
+ private setErrorTags;
117
+ flush(): Promise<void>;
118
+ shutdown(): Promise<void>;
119
+ }
120
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,YAAY,EAIZ,mBAAmB,EACnB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACR,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAuB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AA8DhE;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OA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