@mastra/otel-exporter 0.0.0-remove-unused-model-providers-api-20251030210744 → 0.0.0-remove-ai-peer-dep-from-evals-20260105220639
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 +397 -4
- package/README.md +57 -13
- package/dist/gen-ai-messages.d.ts +26 -0
- package/dist/gen-ai-messages.d.ts.map +1 -0
- package/dist/gen-ai-semantics.d.ts +40 -0
- package/dist/gen-ai-semantics.d.ts.map +1 -0
- package/dist/index.cjs +448 -373
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +447 -374
- package/dist/index.js.map +1 -1
- package/dist/span-converter.d.ts +28 -30
- package/dist/span-converter.d.ts.map +1 -1
- package/dist/{ai-tracing.d.ts → tracing.d.ts} +8 -8
- package/dist/tracing.d.ts.map +1 -0
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +17 -12
- package/dist/ai-tracing.d.ts.map +0 -1
- package/dist/mastra-span.d.ts +0 -38
- package/dist/mastra-span.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { SpanType, TracingEventType } from '@mastra/core/observability';
|
|
2
|
+
import { BaseExporter } from '@mastra/observability';
|
|
3
|
+
import { TraceFlags, SpanKind, SpanStatusCode, diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
|
|
4
4
|
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
5
8
|
import { ATTR_TELEMETRY_SDK_LANGUAGE, ATTR_TELEMETRY_SDK_VERSION, ATTR_TELEMETRY_SDK_NAME, ATTR_SERVICE_VERSION, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
9
|
+
import { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_INPUT_MESSAGES, ATTR_GEN_AI_OUTPUT_MESSAGES, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_PROVIDER_NAME, ATTR_GEN_AI_AGENT_ID, ATTR_GEN_AI_AGENT_NAME, ATTR_GEN_AI_REQUEST_TEMPERATURE, ATTR_GEN_AI_REQUEST_MAX_TOKENS, ATTR_GEN_AI_REQUEST_TOP_P, ATTR_GEN_AI_REQUEST_TOP_K, ATTR_GEN_AI_REQUEST_PRESENCE_PENALTY, ATTR_GEN_AI_REQUEST_FREQUENCY_PENALTY, ATTR_GEN_AI_REQUEST_STOP_SEQUENCES, ATTR_GEN_AI_REQUEST_SEED, ATTR_GEN_AI_RESPONSE_FINISH_REASONS, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_RESPONSE_ID, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_TOOL_DESCRIPTION, ATTR_GEN_AI_CONVERSATION_ID, ATTR_GEN_AI_SYSTEM_INSTRUCTIONS, ATTR_ERROR_TYPE, ATTR_ERROR_MESSAGE, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS } from '@opentelemetry/semantic-conventions/incubating';
|
|
6
10
|
|
|
7
|
-
// src/
|
|
11
|
+
// src/tracing.ts
|
|
8
12
|
|
|
9
13
|
// src/loadExporter.ts
|
|
10
14
|
var OTLPHttpExporter;
|
|
@@ -202,399 +206,478 @@ function resolveCustomConfig(config) {
|
|
|
202
206
|
protocol: config.protocol || "http/json"
|
|
203
207
|
};
|
|
204
208
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
ended;
|
|
219
|
-
resource;
|
|
220
|
-
instrumentationLibrary;
|
|
221
|
-
instrumentationScope;
|
|
222
|
-
droppedAttributesCount = 0;
|
|
223
|
-
droppedEventsCount = 0;
|
|
224
|
-
droppedLinksCount = 0;
|
|
225
|
-
constructor(aiSpan, attributes, kind, parentSpanId, resource, instrumentationLibrary) {
|
|
226
|
-
this.name = aiSpan.name;
|
|
227
|
-
this.kind = kind;
|
|
228
|
-
this.attributes = attributes;
|
|
229
|
-
this.parentSpanId = parentSpanId;
|
|
230
|
-
this.links = [];
|
|
231
|
-
this.events = [];
|
|
232
|
-
this.startTime = this.dateToHrTime(aiSpan.startTime);
|
|
233
|
-
this.endTime = aiSpan.endTime ? this.dateToHrTime(aiSpan.endTime) : this.startTime;
|
|
234
|
-
this.ended = !!aiSpan.endTime;
|
|
235
|
-
if (aiSpan.endTime) {
|
|
236
|
-
const durationMs = aiSpan.endTime.getTime() - aiSpan.startTime.getTime();
|
|
237
|
-
this.duration = [Math.floor(durationMs / 1e3), durationMs % 1e3 * 1e6];
|
|
238
|
-
} else {
|
|
239
|
-
this.duration = [0, 0];
|
|
209
|
+
|
|
210
|
+
// src/gen-ai-messages.ts
|
|
211
|
+
var isMastraMessagePart = (p) => {
|
|
212
|
+
return typeof p === "object" && p != null && "type" in p && (p.type === "text" || p.type === "tool-call" || p.type === "tool-result") && (p.type === "text" && "text" in p || p.type === "tool-call" && "toolCallId" in p && "toolName" in p && "input" in p || p.type === "tool-result" && "toolCallId" in p && "toolName" in p && "output" in p);
|
|
213
|
+
};
|
|
214
|
+
var isMastraMessage = (m) => {
|
|
215
|
+
return typeof m === "object" && m != null && "role" in m && "content" in m && (typeof m.content === "string" || Array.isArray(m.content) && m.content.every(isMastraMessagePart));
|
|
216
|
+
};
|
|
217
|
+
var convertMastraMessagesToGenAIMessages = (inputOutputString) => {
|
|
218
|
+
try {
|
|
219
|
+
const parsedIO = JSON.parse(inputOutputString);
|
|
220
|
+
if (typeof parsedIO !== "object" || parsedIO == null || !("messages" in parsedIO) && !("text" in parsedIO)) {
|
|
221
|
+
return inputOutputString;
|
|
240
222
|
}
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
attributes: {
|
|
249
|
-
"exception.message": aiSpan.errorInfo.message,
|
|
250
|
-
"exception.type": "Error",
|
|
251
|
-
...aiSpan.errorInfo.details?.stack && {
|
|
252
|
-
"exception.stacktrace": aiSpan.errorInfo.details.stack
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
time: this.startTime,
|
|
256
|
-
droppedAttributesCount: 0
|
|
257
|
-
});
|
|
258
|
-
} else if (aiSpan.endTime) {
|
|
259
|
-
this.status = { code: SpanStatusCode.OK };
|
|
260
|
-
} else {
|
|
261
|
-
this.status = { code: SpanStatusCode.UNSET };
|
|
262
|
-
}
|
|
263
|
-
if (aiSpan.isEvent) {
|
|
264
|
-
this.events.push({
|
|
265
|
-
name: "instant_event",
|
|
266
|
-
attributes: {},
|
|
267
|
-
time: this.startTime,
|
|
268
|
-
droppedAttributesCount: 0
|
|
269
|
-
});
|
|
223
|
+
if ("text" in parsedIO) {
|
|
224
|
+
return JSON.stringify([
|
|
225
|
+
{
|
|
226
|
+
role: "assistant",
|
|
227
|
+
parts: [{ type: "text", content: parsedIO.text }]
|
|
228
|
+
}
|
|
229
|
+
]);
|
|
270
230
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
231
|
+
if (Array.isArray(parsedIO.messages)) {
|
|
232
|
+
return JSON.stringify(
|
|
233
|
+
parsedIO.messages.map((m) => {
|
|
234
|
+
if (!isMastraMessage(m)) {
|
|
235
|
+
return m;
|
|
236
|
+
}
|
|
237
|
+
const role = m.role;
|
|
238
|
+
let parts = [];
|
|
239
|
+
if (Array.isArray(m.content)) {
|
|
240
|
+
parts = m.content.map((c) => {
|
|
241
|
+
switch (c.type) {
|
|
242
|
+
case "text":
|
|
243
|
+
return {
|
|
244
|
+
type: "text",
|
|
245
|
+
content: c.text
|
|
246
|
+
};
|
|
247
|
+
case "tool-call":
|
|
248
|
+
return {
|
|
249
|
+
type: "tool_call",
|
|
250
|
+
id: c.toolCallId,
|
|
251
|
+
name: c.toolName,
|
|
252
|
+
arguments: JSON.stringify(c.input)
|
|
253
|
+
};
|
|
254
|
+
case "tool-result":
|
|
255
|
+
return {
|
|
256
|
+
type: "tool_call_response",
|
|
257
|
+
id: c.toolCallId,
|
|
258
|
+
name: c.toolName,
|
|
259
|
+
response: JSON.stringify(c.output.value)
|
|
260
|
+
};
|
|
261
|
+
default:
|
|
262
|
+
return c;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
} else {
|
|
266
|
+
parts = [
|
|
267
|
+
{
|
|
268
|
+
type: "text",
|
|
269
|
+
content: m.content
|
|
270
|
+
}
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
role,
|
|
275
|
+
parts
|
|
276
|
+
};
|
|
277
|
+
})
|
|
278
|
+
);
|
|
284
279
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
version: "1.0.0"
|
|
289
|
-
};
|
|
290
|
-
this.instrumentationScope = this.instrumentationLibrary;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Convert JavaScript Date to hrtime format
|
|
294
|
-
*/
|
|
295
|
-
dateToHrTime(date) {
|
|
296
|
-
const ms = date.getTime();
|
|
297
|
-
const seconds = Math.floor(ms / 1e3);
|
|
298
|
-
const nanoseconds = ms % 1e3 * 1e6;
|
|
299
|
-
return [seconds, nanoseconds];
|
|
280
|
+
return inputOutputString;
|
|
281
|
+
} catch {
|
|
282
|
+
return inputOutputString;
|
|
300
283
|
}
|
|
301
284
|
};
|
|
302
285
|
|
|
303
|
-
// src/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
[AISpanType.MCP_TOOL_CALL]: SpanKind.CLIENT,
|
|
310
|
-
// Root spans for agent/workflow are SERVER (entry points)
|
|
311
|
-
[AISpanType.AGENT_RUN]: SpanKind.SERVER,
|
|
312
|
-
[AISpanType.WORKFLOW_RUN]: SpanKind.SERVER
|
|
313
|
-
};
|
|
314
|
-
var SpanConverter = class {
|
|
315
|
-
resource;
|
|
316
|
-
instrumentationLibrary;
|
|
317
|
-
constructor(resource) {
|
|
318
|
-
this.resource = resource;
|
|
319
|
-
this.instrumentationLibrary = {
|
|
320
|
-
name: "@mastra/otel",
|
|
321
|
-
version: "1.0.0"
|
|
322
|
-
};
|
|
286
|
+
// src/gen-ai-semantics.ts
|
|
287
|
+
function formatUsageMetrics(usage) {
|
|
288
|
+
if (!usage) return {};
|
|
289
|
+
const metrics = {};
|
|
290
|
+
if (usage.inputTokens !== void 0) {
|
|
291
|
+
metrics[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = usage.inputTokens;
|
|
323
292
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
* This preserves Mastra's trace and span IDs
|
|
327
|
-
*/
|
|
328
|
-
convertSpan(aiSpan) {
|
|
329
|
-
const spanKind = this.getSpanKind(aiSpan);
|
|
330
|
-
const attributes = this.buildAttributes(aiSpan);
|
|
331
|
-
const spanName = this.buildSpanName(aiSpan);
|
|
332
|
-
const otelSpan = { ...aiSpan, name: spanName };
|
|
333
|
-
return new MastraReadableSpan(
|
|
334
|
-
otelSpan,
|
|
335
|
-
attributes,
|
|
336
|
-
spanKind,
|
|
337
|
-
aiSpan.parentSpanId,
|
|
338
|
-
// Use the parentSpanId from the Mastra span directly
|
|
339
|
-
this.resource,
|
|
340
|
-
this.instrumentationLibrary
|
|
341
|
-
);
|
|
293
|
+
if (usage.outputTokens !== void 0) {
|
|
294
|
+
metrics[ATTR_GEN_AI_USAGE_OUTPUT_TOKENS] = usage.outputTokens;
|
|
342
295
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
296
|
+
if (usage.outputDetails?.reasoning !== void 0) {
|
|
297
|
+
metrics["gen_ai.usage.reasoning_tokens"] = usage.outputDetails.reasoning;
|
|
298
|
+
}
|
|
299
|
+
if (usage.inputDetails?.cacheRead !== void 0) {
|
|
300
|
+
metrics["gen_ai.usage.cached_input_tokens"] = usage.inputDetails.cacheRead;
|
|
301
|
+
}
|
|
302
|
+
if (usage.inputDetails?.cacheWrite !== void 0) {
|
|
303
|
+
metrics["gen_ai.usage.cache_write_tokens"] = usage.inputDetails.cacheWrite;
|
|
304
|
+
}
|
|
305
|
+
if (usage.inputDetails?.audio !== void 0) {
|
|
306
|
+
metrics["gen_ai.usage.audio_input_tokens"] = usage.inputDetails.audio;
|
|
307
|
+
}
|
|
308
|
+
if (usage.outputDetails?.audio !== void 0) {
|
|
309
|
+
metrics["gen_ai.usage.audio_output_tokens"] = usage.outputDetails.audio;
|
|
310
|
+
}
|
|
311
|
+
return metrics;
|
|
312
|
+
}
|
|
313
|
+
function getOperationName(span) {
|
|
314
|
+
switch (span.type) {
|
|
315
|
+
case SpanType.MODEL_GENERATION:
|
|
316
|
+
return "chat";
|
|
317
|
+
case SpanType.TOOL_CALL:
|
|
318
|
+
case SpanType.MCP_TOOL_CALL:
|
|
319
|
+
return "execute_tool";
|
|
320
|
+
case SpanType.AGENT_RUN:
|
|
321
|
+
return "invoke_agent";
|
|
322
|
+
case SpanType.WORKFLOW_RUN:
|
|
323
|
+
return "invoke_workflow";
|
|
324
|
+
default:
|
|
325
|
+
return span.type.toLowerCase();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function sanitizeSpanName(name) {
|
|
329
|
+
return name.replace(/[^\p{L}\p{N}._ -]/gu, "");
|
|
330
|
+
}
|
|
331
|
+
function getSpanIdentifier(span) {
|
|
332
|
+
switch (span.type) {
|
|
333
|
+
case SpanType.MODEL_GENERATION: {
|
|
334
|
+
const attrs = span.attributes;
|
|
335
|
+
return attrs?.model ?? "unknown";
|
|
351
336
|
}
|
|
352
|
-
|
|
337
|
+
default:
|
|
338
|
+
return span.entityName ?? span.entityId ?? "unknown";
|
|
353
339
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
case AISpanType.WORKFLOW_RUN: {
|
|
377
|
-
const workflowAttrs = aiSpan.attributes;
|
|
378
|
-
const workflowId = workflowAttrs?.workflowId || "unknown";
|
|
379
|
-
return `workflow.${workflowId}`;
|
|
380
|
-
}
|
|
381
|
-
case AISpanType.WORKFLOW_STEP:
|
|
382
|
-
return aiSpan.name;
|
|
383
|
-
default:
|
|
384
|
-
return aiSpan.name;
|
|
340
|
+
}
|
|
341
|
+
function getSpanName(span) {
|
|
342
|
+
const identifier = getSpanIdentifier(span);
|
|
343
|
+
if (identifier) {
|
|
344
|
+
const operation = getOperationName(span);
|
|
345
|
+
return `${operation} ${identifier}`;
|
|
346
|
+
}
|
|
347
|
+
return sanitizeSpanName(span.name);
|
|
348
|
+
}
|
|
349
|
+
function getAttributes(span) {
|
|
350
|
+
const attributes = {};
|
|
351
|
+
const spanType = span.type.toLowerCase();
|
|
352
|
+
attributes[ATTR_GEN_AI_OPERATION_NAME] = getOperationName(span);
|
|
353
|
+
attributes["mastra.span.type"] = span.type;
|
|
354
|
+
if (span.input !== void 0) {
|
|
355
|
+
const inputStr = typeof span.input === "string" ? span.input : JSON.stringify(span.input);
|
|
356
|
+
if (span.type === SpanType.MODEL_GENERATION) {
|
|
357
|
+
attributes[ATTR_GEN_AI_INPUT_MESSAGES] = convertMastraMessagesToGenAIMessages(inputStr);
|
|
358
|
+
} else if (span.type === SpanType.TOOL_CALL || span.type === SpanType.MCP_TOOL_CALL) {
|
|
359
|
+
attributes["gen_ai.tool.call.arguments"] = inputStr;
|
|
360
|
+
} else {
|
|
361
|
+
attributes[`mastra.${spanType}.input`] = inputStr;
|
|
385
362
|
}
|
|
386
363
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
attributes["mastra.span.type"] = aiSpan.type;
|
|
396
|
-
attributes["mastra.trace_id"] = aiSpan.traceId;
|
|
397
|
-
attributes["mastra.span_id"] = aiSpan.id;
|
|
398
|
-
if (aiSpan.parentSpanId) {
|
|
399
|
-
attributes["mastra.parent_span_id"] = aiSpan.parentSpanId;
|
|
400
|
-
}
|
|
401
|
-
if (aiSpan.input !== void 0) {
|
|
402
|
-
const inputStr = typeof aiSpan.input === "string" ? aiSpan.input : JSON.stringify(aiSpan.input);
|
|
403
|
-
attributes["input"] = inputStr;
|
|
404
|
-
if (aiSpan.type === AISpanType.MODEL_GENERATION) {
|
|
405
|
-
attributes["gen_ai.prompt"] = inputStr;
|
|
406
|
-
} else if (aiSpan.type === AISpanType.TOOL_CALL || aiSpan.type === AISpanType.MCP_TOOL_CALL) {
|
|
407
|
-
attributes["gen_ai.tool.input"] = inputStr;
|
|
408
|
-
}
|
|
364
|
+
if (span.output !== void 0) {
|
|
365
|
+
const outputStr = typeof span.output === "string" ? span.output : JSON.stringify(span.output);
|
|
366
|
+
if (span.type === SpanType.MODEL_GENERATION) {
|
|
367
|
+
attributes[ATTR_GEN_AI_OUTPUT_MESSAGES] = convertMastraMessagesToGenAIMessages(outputStr);
|
|
368
|
+
} else if (span.type === SpanType.TOOL_CALL || span.type === SpanType.MCP_TOOL_CALL) {
|
|
369
|
+
attributes["gen_ai.tool.call.result"] = outputStr;
|
|
370
|
+
} else {
|
|
371
|
+
attributes[`mastra.${spanType}.output`] = outputStr;
|
|
409
372
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
373
|
+
}
|
|
374
|
+
if (span.type === SpanType.MODEL_GENERATION && span.attributes) {
|
|
375
|
+
const modelAttrs = span.attributes;
|
|
376
|
+
if (modelAttrs.model) {
|
|
377
|
+
attributes[ATTR_GEN_AI_REQUEST_MODEL] = modelAttrs.model;
|
|
378
|
+
}
|
|
379
|
+
if (modelAttrs.provider) {
|
|
380
|
+
attributes[ATTR_GEN_AI_PROVIDER_NAME] = normalizeProvider(modelAttrs.provider);
|
|
381
|
+
}
|
|
382
|
+
if (span.entityId) {
|
|
383
|
+
attributes[ATTR_GEN_AI_AGENT_ID] = span.entityId;
|
|
418
384
|
}
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
385
|
+
if (span.entityName) {
|
|
386
|
+
attributes[ATTR_GEN_AI_AGENT_NAME] = span.entityName;
|
|
387
|
+
}
|
|
388
|
+
Object.assign(attributes, formatUsageMetrics(modelAttrs.usage));
|
|
389
|
+
if (modelAttrs.parameters) {
|
|
390
|
+
if (modelAttrs.parameters.temperature !== void 0) {
|
|
391
|
+
attributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = modelAttrs.parameters.temperature;
|
|
423
392
|
}
|
|
424
|
-
if (modelAttrs.
|
|
425
|
-
attributes[
|
|
393
|
+
if (modelAttrs.parameters.maxOutputTokens !== void 0) {
|
|
394
|
+
attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = modelAttrs.parameters.maxOutputTokens;
|
|
426
395
|
}
|
|
427
|
-
if (modelAttrs.
|
|
428
|
-
|
|
429
|
-
const outputTokens = modelAttrs.usage.outputTokens ?? modelAttrs.usage.completionTokens;
|
|
430
|
-
if (inputTokens !== void 0) {
|
|
431
|
-
attributes["gen_ai.usage.input_tokens"] = inputTokens;
|
|
432
|
-
}
|
|
433
|
-
if (outputTokens !== void 0) {
|
|
434
|
-
attributes["gen_ai.usage.output_tokens"] = outputTokens;
|
|
435
|
-
}
|
|
436
|
-
if (modelAttrs.usage.totalTokens !== void 0) {
|
|
437
|
-
attributes["gen_ai.usage.total_tokens"] = modelAttrs.usage.totalTokens;
|
|
438
|
-
}
|
|
439
|
-
if (modelAttrs.usage.reasoningTokens !== void 0) {
|
|
440
|
-
attributes["gen_ai.usage.reasoning_tokens"] = modelAttrs.usage.reasoningTokens;
|
|
441
|
-
}
|
|
442
|
-
if (modelAttrs.usage.cachedInputTokens !== void 0) {
|
|
443
|
-
attributes["gen_ai.usage.cached_input_tokens"] = modelAttrs.usage.cachedInputTokens;
|
|
444
|
-
}
|
|
396
|
+
if (modelAttrs.parameters.topP !== void 0) {
|
|
397
|
+
attributes[ATTR_GEN_AI_REQUEST_TOP_P] = modelAttrs.parameters.topP;
|
|
445
398
|
}
|
|
446
|
-
if (modelAttrs.parameters) {
|
|
447
|
-
|
|
448
|
-
attributes["gen_ai.request.temperature"] = modelAttrs.parameters.temperature;
|
|
449
|
-
}
|
|
450
|
-
if (modelAttrs.parameters.maxOutputTokens !== void 0) {
|
|
451
|
-
attributes["gen_ai.request.max_tokens"] = modelAttrs.parameters.maxOutputTokens;
|
|
452
|
-
}
|
|
453
|
-
if (modelAttrs.parameters.topP !== void 0) {
|
|
454
|
-
attributes["gen_ai.request.top_p"] = modelAttrs.parameters.topP;
|
|
455
|
-
}
|
|
456
|
-
if (modelAttrs.parameters.topK !== void 0) {
|
|
457
|
-
attributes["gen_ai.request.top_k"] = modelAttrs.parameters.topK;
|
|
458
|
-
}
|
|
459
|
-
if (modelAttrs.parameters.presencePenalty !== void 0) {
|
|
460
|
-
attributes["gen_ai.request.presence_penalty"] = modelAttrs.parameters.presencePenalty;
|
|
461
|
-
}
|
|
462
|
-
if (modelAttrs.parameters.frequencyPenalty !== void 0) {
|
|
463
|
-
attributes["gen_ai.request.frequency_penalty"] = modelAttrs.parameters.frequencyPenalty;
|
|
464
|
-
}
|
|
465
|
-
if (modelAttrs.parameters.stopSequences) {
|
|
466
|
-
attributes["gen_ai.request.stop_sequences"] = JSON.stringify(modelAttrs.parameters.stopSequences);
|
|
467
|
-
}
|
|
399
|
+
if (modelAttrs.parameters.topK !== void 0) {
|
|
400
|
+
attributes[ATTR_GEN_AI_REQUEST_TOP_K] = modelAttrs.parameters.topK;
|
|
468
401
|
}
|
|
469
|
-
if (modelAttrs.
|
|
470
|
-
attributes[
|
|
402
|
+
if (modelAttrs.parameters.presencePenalty !== void 0) {
|
|
403
|
+
attributes[ATTR_GEN_AI_REQUEST_PRESENCE_PENALTY] = modelAttrs.parameters.presencePenalty;
|
|
471
404
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const toolAttrs = aiSpan.attributes;
|
|
475
|
-
if (toolAttrs.toolId) {
|
|
476
|
-
attributes["gen_ai.tool.name"] = toolAttrs.toolId;
|
|
405
|
+
if (modelAttrs.parameters.frequencyPenalty !== void 0) {
|
|
406
|
+
attributes[ATTR_GEN_AI_REQUEST_FREQUENCY_PENALTY] = modelAttrs.parameters.frequencyPenalty;
|
|
477
407
|
}
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
if (mcpAttrs.mcpServer) {
|
|
481
|
-
attributes["mcp.server"] = mcpAttrs.mcpServer;
|
|
482
|
-
}
|
|
483
|
-
if (mcpAttrs.serverVersion) {
|
|
484
|
-
attributes["mcp.server.version"] = mcpAttrs.serverVersion;
|
|
485
|
-
}
|
|
486
|
-
} else {
|
|
487
|
-
if (toolAttrs.toolDescription) {
|
|
488
|
-
attributes["gen_ai.tool.description"] = toolAttrs.toolDescription;
|
|
489
|
-
}
|
|
408
|
+
if (modelAttrs.parameters.stopSequences) {
|
|
409
|
+
attributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = JSON.stringify(modelAttrs.parameters.stopSequences);
|
|
490
410
|
}
|
|
491
|
-
if (
|
|
492
|
-
attributes[
|
|
411
|
+
if (modelAttrs.parameters.seed) {
|
|
412
|
+
attributes[ATTR_GEN_AI_REQUEST_SEED] = modelAttrs.parameters.seed;
|
|
493
413
|
}
|
|
494
414
|
}
|
|
495
|
-
if (
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
415
|
+
if (modelAttrs.finishReason) {
|
|
416
|
+
attributes[ATTR_GEN_AI_RESPONSE_FINISH_REASONS] = JSON.stringify([modelAttrs.finishReason]);
|
|
417
|
+
}
|
|
418
|
+
if (modelAttrs.responseModel) {
|
|
419
|
+
attributes[ATTR_GEN_AI_RESPONSE_MODEL] = modelAttrs.responseModel;
|
|
420
|
+
}
|
|
421
|
+
if (modelAttrs.responseId) {
|
|
422
|
+
attributes[ATTR_GEN_AI_RESPONSE_ID] = modelAttrs.responseId;
|
|
423
|
+
}
|
|
424
|
+
if (modelAttrs.serverAddress) {
|
|
425
|
+
attributes[ATTR_SERVER_ADDRESS] = modelAttrs.serverAddress;
|
|
426
|
+
}
|
|
427
|
+
if (modelAttrs.serverPort !== void 0) {
|
|
428
|
+
attributes[ATTR_SERVER_PORT] = modelAttrs.serverPort;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if ((span.type === SpanType.TOOL_CALL || span.type === SpanType.MCP_TOOL_CALL) && span.attributes) {
|
|
432
|
+
attributes[ATTR_GEN_AI_TOOL_NAME] = span.entityName ?? span.entityId;
|
|
433
|
+
if (span.type === SpanType.MCP_TOOL_CALL) {
|
|
434
|
+
const mcpAttrs = span.attributes;
|
|
435
|
+
if (mcpAttrs.mcpServer) {
|
|
436
|
+
attributes[ATTR_SERVER_ADDRESS] = mcpAttrs.mcpServer;
|
|
500
437
|
}
|
|
501
|
-
|
|
502
|
-
|
|
438
|
+
} else {
|
|
439
|
+
const toolAttrs = span.attributes;
|
|
440
|
+
if (toolAttrs.toolDescription) {
|
|
441
|
+
attributes[ATTR_GEN_AI_TOOL_DESCRIPTION] = toolAttrs.toolDescription;
|
|
503
442
|
}
|
|
504
|
-
if (
|
|
505
|
-
attributes["
|
|
443
|
+
if (toolAttrs.toolType) {
|
|
444
|
+
attributes["gen_ai.tool.type"] = toolAttrs.toolType;
|
|
506
445
|
}
|
|
507
446
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if (workflowAttrs.status) {
|
|
514
|
-
attributes["workflow.status"] = workflowAttrs.status;
|
|
515
|
-
}
|
|
447
|
+
}
|
|
448
|
+
if (span.type === SpanType.AGENT_RUN && span.attributes) {
|
|
449
|
+
const agentAttrs = span.attributes;
|
|
450
|
+
if (span.entityId) {
|
|
451
|
+
attributes[ATTR_GEN_AI_AGENT_ID] = span.entityId;
|
|
516
452
|
}
|
|
517
|
-
if (
|
|
518
|
-
attributes[
|
|
519
|
-
attributes["error.type"] = aiSpan.errorInfo.id || "unknown";
|
|
520
|
-
attributes["error.message"] = aiSpan.errorInfo.message;
|
|
521
|
-
if (aiSpan.errorInfo.domain) {
|
|
522
|
-
attributes["error.domain"] = aiSpan.errorInfo.domain;
|
|
523
|
-
}
|
|
524
|
-
if (aiSpan.errorInfo.category) {
|
|
525
|
-
attributes["error.category"] = aiSpan.errorInfo.category;
|
|
526
|
-
}
|
|
453
|
+
if (span.entityName) {
|
|
454
|
+
attributes[ATTR_GEN_AI_AGENT_NAME] = span.entityName;
|
|
527
455
|
}
|
|
528
|
-
if (
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
} else {
|
|
537
|
-
attributes[key] = value;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
});
|
|
456
|
+
if (agentAttrs.conversationId) {
|
|
457
|
+
attributes[ATTR_GEN_AI_CONVERSATION_ID] = agentAttrs.conversationId;
|
|
458
|
+
}
|
|
459
|
+
if (agentAttrs.maxSteps) {
|
|
460
|
+
attributes[`mastra.${spanType}.max_steps`] = agentAttrs.maxSteps;
|
|
461
|
+
}
|
|
462
|
+
if (agentAttrs.availableTools) {
|
|
463
|
+
attributes[`gen_ai.tool.definitions`] = JSON.stringify(agentAttrs.availableTools);
|
|
541
464
|
}
|
|
542
|
-
|
|
543
|
-
|
|
465
|
+
attributes[ATTR_GEN_AI_SYSTEM_INSTRUCTIONS] = agentAttrs.instructions;
|
|
466
|
+
}
|
|
467
|
+
if (span.errorInfo) {
|
|
468
|
+
attributes[ATTR_ERROR_TYPE] = span.errorInfo.id || "unknown";
|
|
469
|
+
attributes[ATTR_ERROR_MESSAGE] = span.errorInfo.message;
|
|
470
|
+
if (span.errorInfo.domain) {
|
|
471
|
+
attributes["error.domain"] = span.errorInfo.domain;
|
|
544
472
|
}
|
|
545
|
-
if (
|
|
546
|
-
attributes["
|
|
547
|
-
const duration = aiSpan.endTime.getTime() - aiSpan.startTime.getTime();
|
|
548
|
-
attributes["mastra.duration_ms"] = duration;
|
|
473
|
+
if (span.errorInfo.category) {
|
|
474
|
+
attributes["error.category"] = span.errorInfo.category;
|
|
549
475
|
}
|
|
550
|
-
return attributes;
|
|
551
476
|
}
|
|
477
|
+
return attributes;
|
|
478
|
+
}
|
|
479
|
+
var PROVIDER_ALIASES = {
|
|
480
|
+
anthropic: ["anthropic", "claude"],
|
|
481
|
+
"aws.bedrock": ["awsbedrock", "bedrock", "amazonbedrock"],
|
|
482
|
+
"azure.ai.inference": ["azureaiinference", "azureinference"],
|
|
483
|
+
"azure.ai.openai": ["azureaiopenai", "azureopenai", "msopenai", "microsoftopenai"],
|
|
484
|
+
cohere: ["cohere"],
|
|
485
|
+
deepseek: ["deepseek"],
|
|
486
|
+
"gcp.gemini": ["gcpgemini", "gemini"],
|
|
487
|
+
"gcp.gen_ai": ["gcpgenai", "googlegenai", "googleai"],
|
|
488
|
+
"gcp.vertex_ai": ["gcpvertexai", "vertexai"],
|
|
489
|
+
groq: ["groq"],
|
|
490
|
+
"ibm.watsonx.ai": ["ibmwatsonxai", "watsonx", "watsonxai"],
|
|
491
|
+
mistral_ai: ["mistral", "mistralai"],
|
|
492
|
+
openai: ["openai", "oai"],
|
|
493
|
+
perplexity: ["perplexity", "pplx"],
|
|
494
|
+
x_ai: ["xai", "x-ai", "x_ai", "x.com ai"]
|
|
495
|
+
};
|
|
496
|
+
function normalizeProviderString(input) {
|
|
497
|
+
return input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
498
|
+
}
|
|
499
|
+
function normalizeProvider(providerName) {
|
|
500
|
+
const normalized = normalizeProviderString(providerName);
|
|
501
|
+
for (const [canonical, aliases] of Object.entries(PROVIDER_ALIASES)) {
|
|
502
|
+
for (const alias of aliases) {
|
|
503
|
+
if (normalized === alias) {
|
|
504
|
+
return canonical;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return providerName.toLowerCase();
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/span-converter.ts
|
|
512
|
+
var SpanConverter = class {
|
|
513
|
+
constructor(params) {
|
|
514
|
+
this.params = params;
|
|
515
|
+
this.format = params.format;
|
|
516
|
+
}
|
|
517
|
+
resource;
|
|
518
|
+
scope;
|
|
519
|
+
initPromise;
|
|
520
|
+
format;
|
|
552
521
|
/**
|
|
553
|
-
*
|
|
522
|
+
* Lazily initialize resource & scope on first use.
|
|
523
|
+
* Subsequent calls reuse the same promise (no races).
|
|
554
524
|
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const attrs = aiSpan.attributes;
|
|
559
|
-
return attrs?.resultType === "tool_selection" ? "tool_selection" : "chat";
|
|
560
|
-
}
|
|
561
|
-
case AISpanType.TOOL_CALL:
|
|
562
|
-
case AISpanType.MCP_TOOL_CALL:
|
|
563
|
-
return "tool.execute";
|
|
564
|
-
case AISpanType.AGENT_RUN:
|
|
565
|
-
return "agent.run";
|
|
566
|
-
case AISpanType.WORKFLOW_RUN:
|
|
567
|
-
return "workflow.run";
|
|
568
|
-
default:
|
|
569
|
-
return aiSpan.type.replace(/_/g, ".");
|
|
525
|
+
async initIfNeeded() {
|
|
526
|
+
if (this.initPromise) {
|
|
527
|
+
return this.initPromise;
|
|
570
528
|
}
|
|
529
|
+
this.initPromise = (async () => {
|
|
530
|
+
const packageVersion = await getPackageVersion(this.params.packageName) ?? "unknown";
|
|
531
|
+
const serviceVersion = await getPackageVersion("@mastra/core") ?? "unknown";
|
|
532
|
+
let resource = resourceFromAttributes({
|
|
533
|
+
[ATTR_SERVICE_NAME]: this.params.serviceName || "mastra-service",
|
|
534
|
+
[ATTR_SERVICE_VERSION]: serviceVersion,
|
|
535
|
+
[ATTR_TELEMETRY_SDK_NAME]: this.params.packageName,
|
|
536
|
+
[ATTR_TELEMETRY_SDK_VERSION]: packageVersion,
|
|
537
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: "nodejs"
|
|
538
|
+
});
|
|
539
|
+
if (this.params.config?.resourceAttributes) {
|
|
540
|
+
resource = resource.merge(
|
|
541
|
+
// Duplicate attributes from config will override defaults above
|
|
542
|
+
resourceFromAttributes(this.params.config.resourceAttributes)
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
this.resource = resource;
|
|
546
|
+
this.scope = {
|
|
547
|
+
name: this.params.packageName,
|
|
548
|
+
version: packageVersion
|
|
549
|
+
};
|
|
550
|
+
})();
|
|
551
|
+
return this.initPromise;
|
|
571
552
|
}
|
|
572
553
|
/**
|
|
573
|
-
*
|
|
554
|
+
* Convert a Mastra Span to an OpenTelemetry ReadableSpan
|
|
574
555
|
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
return "server";
|
|
580
|
-
case SpanKind.CLIENT:
|
|
581
|
-
return "client";
|
|
582
|
-
case SpanKind.INTERNAL:
|
|
583
|
-
return "internal";
|
|
584
|
-
case SpanKind.PRODUCER:
|
|
585
|
-
return "producer";
|
|
586
|
-
case SpanKind.CONSUMER:
|
|
587
|
-
return "consumer";
|
|
588
|
-
default:
|
|
589
|
-
return "internal";
|
|
556
|
+
async convertSpan(span) {
|
|
557
|
+
await this.initIfNeeded();
|
|
558
|
+
if (!this.resource || !this.scope) {
|
|
559
|
+
throw new Error("SpanConverter not initialized correctly");
|
|
590
560
|
}
|
|
561
|
+
const name = getSpanName(span);
|
|
562
|
+
const kind = getSpanKind(span.type);
|
|
563
|
+
const attributes = getAttributes(span);
|
|
564
|
+
if (span.metadata) {
|
|
565
|
+
for (const [k, v] of Object.entries(span.metadata)) {
|
|
566
|
+
if (v === null || v === void 0) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
attributes[`mastra.metadata.${k}`] = typeof v === "object" ? JSON.stringify(v) : v;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (span.isRootSpan && span.tags?.length) {
|
|
573
|
+
attributes["mastra.tags"] = JSON.stringify(span.tags);
|
|
574
|
+
}
|
|
575
|
+
const startTime = dateToHrTime(span.startTime);
|
|
576
|
+
const endTime = span.endTime ? dateToHrTime(span.endTime) : startTime;
|
|
577
|
+
const duration = computeDuration(span.startTime, span.endTime);
|
|
578
|
+
const { status, events } = buildStatusAndEvents(span, startTime);
|
|
579
|
+
const spanContext = {
|
|
580
|
+
traceId: span.traceId,
|
|
581
|
+
spanId: span.id,
|
|
582
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
583
|
+
isRemote: false
|
|
584
|
+
};
|
|
585
|
+
const parentSpanContext = span.parentSpanId ? {
|
|
586
|
+
traceId: span.traceId,
|
|
587
|
+
spanId: span.parentSpanId,
|
|
588
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
589
|
+
isRemote: false
|
|
590
|
+
} : void 0;
|
|
591
|
+
const links = [];
|
|
592
|
+
const readable = {
|
|
593
|
+
name,
|
|
594
|
+
kind,
|
|
595
|
+
spanContext: () => spanContext,
|
|
596
|
+
parentSpanContext,
|
|
597
|
+
startTime,
|
|
598
|
+
endTime,
|
|
599
|
+
status,
|
|
600
|
+
attributes,
|
|
601
|
+
links,
|
|
602
|
+
events,
|
|
603
|
+
duration,
|
|
604
|
+
ended: !!span.endTime,
|
|
605
|
+
resource: this.resource,
|
|
606
|
+
instrumentationScope: this.scope,
|
|
607
|
+
droppedAttributesCount: 0,
|
|
608
|
+
droppedEventsCount: 0,
|
|
609
|
+
droppedLinksCount: 0
|
|
610
|
+
};
|
|
611
|
+
return readable;
|
|
591
612
|
}
|
|
592
613
|
};
|
|
614
|
+
async function getPackageVersion(pkgName) {
|
|
615
|
+
try {
|
|
616
|
+
const manifestUrl = new URL(await import.meta.resolve(`${pkgName}/package.json`));
|
|
617
|
+
const path = fileURLToPath(manifestUrl);
|
|
618
|
+
const pkgJson = JSON.parse(readFileSync(path, "utf8"));
|
|
619
|
+
return pkgJson.version;
|
|
620
|
+
} catch {
|
|
621
|
+
return void 0;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function getSpanKind(type) {
|
|
625
|
+
switch (type) {
|
|
626
|
+
case SpanType.MODEL_GENERATION:
|
|
627
|
+
case SpanType.MCP_TOOL_CALL:
|
|
628
|
+
return SpanKind.CLIENT;
|
|
629
|
+
default:
|
|
630
|
+
return SpanKind.INTERNAL;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function dateToHrTime(date) {
|
|
634
|
+
const ms = date.getTime();
|
|
635
|
+
const seconds = Math.floor(ms / 1e3);
|
|
636
|
+
const nanoseconds = ms % 1e3 * 1e6;
|
|
637
|
+
return [seconds, nanoseconds];
|
|
638
|
+
}
|
|
639
|
+
function computeDuration(start, end) {
|
|
640
|
+
if (!end) return [0, 0];
|
|
641
|
+
const diffMs = end.getTime() - start.getTime();
|
|
642
|
+
return [Math.floor(diffMs / 1e3), diffMs % 1e3 * 1e6];
|
|
643
|
+
}
|
|
644
|
+
function buildStatusAndEvents(span, defaultTime) {
|
|
645
|
+
const events = [];
|
|
646
|
+
if (span.errorInfo) {
|
|
647
|
+
const status = {
|
|
648
|
+
code: SpanStatusCode.ERROR,
|
|
649
|
+
message: span.errorInfo.message
|
|
650
|
+
};
|
|
651
|
+
events.push({
|
|
652
|
+
name: "exception",
|
|
653
|
+
attributes: {
|
|
654
|
+
"exception.message": span.errorInfo.message,
|
|
655
|
+
"exception.type": "Error",
|
|
656
|
+
...span.errorInfo.details?.stack && {
|
|
657
|
+
"exception.stacktrace": span.errorInfo.details.stack
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
time: defaultTime,
|
|
661
|
+
droppedAttributesCount: 0
|
|
662
|
+
});
|
|
663
|
+
return { status, events };
|
|
664
|
+
}
|
|
665
|
+
if (span.endTime) {
|
|
666
|
+
return {
|
|
667
|
+
status: { code: SpanStatusCode.OK },
|
|
668
|
+
events
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
status: { code: SpanStatusCode.UNSET },
|
|
673
|
+
events
|
|
674
|
+
};
|
|
675
|
+
}
|
|
593
676
|
|
|
594
|
-
// src/
|
|
677
|
+
// src/tracing.ts
|
|
595
678
|
var OtelExporter = class extends BaseExporter {
|
|
596
679
|
config;
|
|
597
|
-
|
|
680
|
+
observabilityConfig;
|
|
598
681
|
spanConverter;
|
|
599
682
|
processor;
|
|
600
683
|
exporter;
|
|
@@ -603,7 +686,6 @@ var OtelExporter = class extends BaseExporter {
|
|
|
603
686
|
constructor(config) {
|
|
604
687
|
super(config);
|
|
605
688
|
this.config = config;
|
|
606
|
-
this.spanConverter = new SpanConverter();
|
|
607
689
|
if (config.logLevel === "debug") {
|
|
608
690
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
|
|
609
691
|
}
|
|
@@ -611,8 +693,8 @@ var OtelExporter = class extends BaseExporter {
|
|
|
611
693
|
/**
|
|
612
694
|
* Initialize with tracing configuration
|
|
613
695
|
*/
|
|
614
|
-
init(
|
|
615
|
-
this.
|
|
696
|
+
init(options) {
|
|
697
|
+
this.observabilityConfig = options.config;
|
|
616
698
|
}
|
|
617
699
|
async setupExporter() {
|
|
618
700
|
if (this.isSetup || this.exporter) return;
|
|
@@ -690,21 +772,12 @@ var OtelExporter = class extends BaseExporter {
|
|
|
690
772
|
}
|
|
691
773
|
async setupProcessor() {
|
|
692
774
|
if (this.processor || this.isSetup) return;
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
[ATTR_TELEMETRY_SDK_VERSION]: "1.0.0",
|
|
699
|
-
[ATTR_TELEMETRY_SDK_LANGUAGE]: "nodejs"
|
|
775
|
+
this.spanConverter = new SpanConverter({
|
|
776
|
+
packageName: "@mastra/otel-exporter",
|
|
777
|
+
serviceName: this.observabilityConfig?.serviceName,
|
|
778
|
+
config: this.config,
|
|
779
|
+
format: "GenAI_v1_38_0"
|
|
700
780
|
});
|
|
701
|
-
if (this.config.resourceAttributes) {
|
|
702
|
-
resource = resource.merge(
|
|
703
|
-
// Duplicate attributes from config will override defaults above
|
|
704
|
-
resourceFromAttributes(this.config.resourceAttributes)
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
this.spanConverter = new SpanConverter(resource);
|
|
708
781
|
this.processor = new BatchSpanProcessor(this.exporter, {
|
|
709
782
|
maxExportBatchSize: this.config.batchSize || 512,
|
|
710
783
|
// Default batch size
|
|
@@ -725,8 +798,8 @@ var OtelExporter = class extends BaseExporter {
|
|
|
725
798
|
await this.setupProcessor();
|
|
726
799
|
this.isSetup = true;
|
|
727
800
|
}
|
|
728
|
-
async
|
|
729
|
-
if (event.type !==
|
|
801
|
+
async _exportTracingEvent(event) {
|
|
802
|
+
if (event.type !== TracingEventType.SPAN_ENDED) {
|
|
730
803
|
return;
|
|
731
804
|
}
|
|
732
805
|
const span = event.exportedSpan;
|
|
@@ -740,9 +813,9 @@ var OtelExporter = class extends BaseExporter {
|
|
|
740
813
|
return;
|
|
741
814
|
}
|
|
742
815
|
try {
|
|
743
|
-
const
|
|
816
|
+
const otelSpan = await this.spanConverter.convertSpan(span);
|
|
744
817
|
await new Promise((resolve) => {
|
|
745
|
-
this.processor.onEnd(
|
|
818
|
+
this.processor.onEnd(otelSpan);
|
|
746
819
|
resolve();
|
|
747
820
|
});
|
|
748
821
|
this.logger.debug(
|
|
@@ -759,6 +832,6 @@ var OtelExporter = class extends BaseExporter {
|
|
|
759
832
|
}
|
|
760
833
|
};
|
|
761
834
|
|
|
762
|
-
export { OtelExporter };
|
|
835
|
+
export { OtelExporter, SpanConverter, getSpanKind };
|
|
763
836
|
//# sourceMappingURL=index.js.map
|
|
764
837
|
//# sourceMappingURL=index.js.map
|