@mastra/datadog 1.2.3 → 1.2.4-alpha.0
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 +15 -0
- package/dist/bridge.d.ts +2 -1
- package/dist/bridge.d.ts.map +1 -1
- package/dist/index.cjs +50 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -6
- package/dist/index.js.map +1 -1
- package/dist/tracing.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -124,8 +124,8 @@ function toDatadogMessages(messages) {
|
|
|
124
124
|
role: m.role,
|
|
125
125
|
content: m.content == null ? "" : toMessageContent(m.content)
|
|
126
126
|
};
|
|
127
|
-
if (m.toolCalls) {
|
|
128
|
-
message.toolCalls = m.toolCalls;
|
|
127
|
+
if (Array.isArray(m.toolCalls) && m.toolCalls.length > 0) {
|
|
128
|
+
message.toolCalls = toDatadogToolCalls(m.toolCalls);
|
|
129
129
|
}
|
|
130
130
|
return message;
|
|
131
131
|
}).filter((m) => !(m.role === "user" && m.content.trim().length === 0));
|
|
@@ -148,7 +148,7 @@ function parseToolArguments(args) {
|
|
|
148
148
|
function toDatadogToolCalls(toolCalls) {
|
|
149
149
|
return toolCalls.map((c) => ({
|
|
150
150
|
name: c?.toolName ?? c?.name ?? c?.function?.name ?? "unknown",
|
|
151
|
-
arguments: parseToolArguments(c?.args ?? c?.input ?? c?.function?.arguments),
|
|
151
|
+
arguments: parseToolArguments(c?.args ?? c?.input ?? c?.arguments ?? c?.function?.arguments),
|
|
152
152
|
toolId: c?.toolCallId ?? c?.toolId ?? c?.id,
|
|
153
153
|
type: c?.type === "function" ? c.type : "function"
|
|
154
154
|
}));
|
|
@@ -271,7 +271,14 @@ var DatadogBridge = class extends BaseExporter {
|
|
|
271
271
|
this.config = config;
|
|
272
272
|
return;
|
|
273
273
|
}
|
|
274
|
-
this.config = {
|
|
274
|
+
this.config = {
|
|
275
|
+
...config,
|
|
276
|
+
mlApp,
|
|
277
|
+
site,
|
|
278
|
+
apiKey,
|
|
279
|
+
agentless,
|
|
280
|
+
env
|
|
281
|
+
};
|
|
275
282
|
ensureTracer({
|
|
276
283
|
mlApp,
|
|
277
284
|
site,
|
|
@@ -343,6 +350,37 @@ var DatadogBridge = class extends BaseExporter {
|
|
|
343
350
|
executeInContextSync(spanId, fn) {
|
|
344
351
|
return this.executeWithSpanContext(spanId, fn);
|
|
345
352
|
}
|
|
353
|
+
async onScoreEvent(event) {
|
|
354
|
+
if (this.isDisabled || !tracer3.llmobs?.submitEvaluation) return;
|
|
355
|
+
const { score } = event;
|
|
356
|
+
if (!score.traceId || !score.spanId) {
|
|
357
|
+
this.logger.warn("Datadog bridge: dropping score with no traceId/spanId", {
|
|
358
|
+
scorerId: score.scorerId
|
|
359
|
+
});
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
tracer3.llmobs.submitEvaluation(
|
|
364
|
+
{ traceId: score.traceId, spanId: toDatadogSpanId(score.spanId) },
|
|
365
|
+
{
|
|
366
|
+
label: score.scorerName ?? score.scorerId,
|
|
367
|
+
value: score.score,
|
|
368
|
+
metricType: "score",
|
|
369
|
+
mlApp: this.config.mlApp,
|
|
370
|
+
timestampMs: score.timestamp instanceof Date ? score.timestamp.getTime() : Date.now(),
|
|
371
|
+
...score.reason ? { reasoning: score.reason } : {},
|
|
372
|
+
...score.metadata ? { metadata: score.metadata } : {}
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
} catch (error) {
|
|
376
|
+
this.logger.error("Datadog bridge: Failed to submit evaluation", {
|
|
377
|
+
error,
|
|
378
|
+
traceId: score.traceId,
|
|
379
|
+
spanId: score.spanId,
|
|
380
|
+
scorerId: score.scorerId
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
346
384
|
executeWithSpanContext(spanId, fn) {
|
|
347
385
|
const ddSpan = this.ddSpanMap.get(spanId);
|
|
348
386
|
if (ddSpan) {
|
|
@@ -514,7 +552,7 @@ var DatadogBridge = class extends BaseExporter {
|
|
|
514
552
|
annotations.metrics = metrics;
|
|
515
553
|
}
|
|
516
554
|
}
|
|
517
|
-
const knownFields = ["usage", "model", "provider"
|
|
555
|
+
const knownFields = ["usage", "model", "provider"];
|
|
518
556
|
const otherAttributes = omitKeys(span.attributes ?? {}, knownFields);
|
|
519
557
|
const contextKeySet = new Set(this.config.requestContextKeys ?? []);
|
|
520
558
|
const flatContextTags = {};
|
|
@@ -646,6 +684,12 @@ function fillRandomBytes(bytes) {
|
|
|
646
684
|
bytes[i] = Math.floor(Math.random() * 256);
|
|
647
685
|
}
|
|
648
686
|
}
|
|
687
|
+
function toDatadogSpanId(spanId) {
|
|
688
|
+
if (/^[0-9a-f]{16}$/i.test(spanId)) {
|
|
689
|
+
return BigInt(`0x${spanId}`).toString(10);
|
|
690
|
+
}
|
|
691
|
+
return spanId;
|
|
692
|
+
}
|
|
649
693
|
function generateSpanId() {
|
|
650
694
|
const bytes = new Uint8Array(8);
|
|
651
695
|
fillRandomBytes(bytes);
|
|
@@ -781,7 +825,7 @@ var DatadogExporter = class extends BaseExporter {
|
|
|
781
825
|
annotations.metrics = metrics;
|
|
782
826
|
}
|
|
783
827
|
}
|
|
784
|
-
const knownFields = ["usage", "model", "provider"
|
|
828
|
+
const knownFields = ["usage", "model", "provider"];
|
|
785
829
|
const otherAttributes = omitKeys(span.attributes ?? {}, knownFields);
|
|
786
830
|
const contextKeySet = new Set(this.config.requestContextKeys ?? []);
|
|
787
831
|
const flatContextTags = {};
|