@mastra/otel-exporter 0.0.0-fix-backport-setserver-20251201151948 → 0.0.0-fix-request-context-as-query-key-20251209093005
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 +182 -47
- 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 +22 -0
- package/dist/gen-ai-semantics.d.ts.map +1 -0
- package/dist/index.cjs +447 -371
- 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 +446 -372
- 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 +15 -16
- 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_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, 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 } 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,479 @@ 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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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 getOperationName(span) {
|
|
288
|
+
switch (span.type) {
|
|
289
|
+
case SpanType.MODEL_GENERATION:
|
|
290
|
+
return "chat";
|
|
291
|
+
case SpanType.TOOL_CALL:
|
|
292
|
+
case SpanType.MCP_TOOL_CALL:
|
|
293
|
+
return "execute_tool";
|
|
294
|
+
case SpanType.AGENT_RUN:
|
|
295
|
+
return "invoke_agent";
|
|
296
|
+
case SpanType.WORKFLOW_RUN:
|
|
297
|
+
return "invoke_workflow";
|
|
298
|
+
default:
|
|
299
|
+
return span.type.toLowerCase();
|
|
323
300
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
301
|
+
}
|
|
302
|
+
function sanitizeSpanName(name) {
|
|
303
|
+
return name.replace(/[^\p{L}\p{N}._ -]/gu, "");
|
|
304
|
+
}
|
|
305
|
+
function getSpanIdentifier(span) {
|
|
306
|
+
switch (span.type) {
|
|
307
|
+
case SpanType.MODEL_GENERATION: {
|
|
308
|
+
const attrs = span.attributes;
|
|
309
|
+
return attrs?.model ?? "unknown";
|
|
310
|
+
}
|
|
311
|
+
case SpanType.TOOL_CALL:
|
|
312
|
+
case SpanType.MCP_TOOL_CALL: {
|
|
313
|
+
const attrs = span.attributes;
|
|
314
|
+
return attrs?.toolId ?? "unknown";
|
|
315
|
+
}
|
|
316
|
+
case SpanType.AGENT_RUN: {
|
|
317
|
+
const attrs = span.attributes;
|
|
318
|
+
return attrs?.agentName ?? attrs?.agentId ?? "unknown";
|
|
319
|
+
}
|
|
320
|
+
case SpanType.WORKFLOW_RUN: {
|
|
321
|
+
const attrs = span.attributes;
|
|
322
|
+
return attrs?.workflowId ?? "unknown";
|
|
323
|
+
}
|
|
324
|
+
default:
|
|
325
|
+
return null;
|
|
342
326
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
327
|
+
}
|
|
328
|
+
function getSpanName(span) {
|
|
329
|
+
const identifier = getSpanIdentifier(span);
|
|
330
|
+
if (identifier) {
|
|
331
|
+
const operation = getOperationName(span);
|
|
332
|
+
return `${operation} ${identifier}`;
|
|
333
|
+
}
|
|
334
|
+
return sanitizeSpanName(span.name);
|
|
335
|
+
}
|
|
336
|
+
function getAttributes(span) {
|
|
337
|
+
const attributes = {};
|
|
338
|
+
const spanType = span.type.toLowerCase();
|
|
339
|
+
attributes[ATTR_GEN_AI_OPERATION_NAME] = getOperationName(span);
|
|
340
|
+
attributes["mastra.span.type"] = span.type;
|
|
341
|
+
if (span.input !== void 0) {
|
|
342
|
+
const inputStr = typeof span.input === "string" ? span.input : JSON.stringify(span.input);
|
|
343
|
+
if (span.type === SpanType.MODEL_GENERATION) {
|
|
344
|
+
attributes[ATTR_GEN_AI_INPUT_MESSAGES] = convertMastraMessagesToGenAIMessages(inputStr);
|
|
345
|
+
} else if (span.type === SpanType.TOOL_CALL || span.type === SpanType.MCP_TOOL_CALL) {
|
|
346
|
+
attributes["gen_ai.tool.call.arguments"] = inputStr;
|
|
347
|
+
} else {
|
|
348
|
+
attributes[`mastra.${spanType}.input`] = inputStr;
|
|
351
349
|
}
|
|
352
|
-
return SPAN_KIND_MAPPING[aiSpan.type] || SpanKind.INTERNAL;
|
|
353
350
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const model = attrs?.model || "unknown";
|
|
363
|
-
return `${operation} ${model}`;
|
|
364
|
-
}
|
|
365
|
-
case AISpanType.TOOL_CALL:
|
|
366
|
-
case AISpanType.MCP_TOOL_CALL: {
|
|
367
|
-
const toolAttrs = aiSpan.attributes;
|
|
368
|
-
const toolName = toolAttrs?.toolId || "unknown";
|
|
369
|
-
return `tool.execute ${toolName}`;
|
|
370
|
-
}
|
|
371
|
-
case AISpanType.AGENT_RUN: {
|
|
372
|
-
const agentAttrs = aiSpan.attributes;
|
|
373
|
-
const agentId = agentAttrs?.agentId || "unknown";
|
|
374
|
-
return `agent.${agentId}`;
|
|
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;
|
|
351
|
+
if (span.output !== void 0) {
|
|
352
|
+
const outputStr = typeof span.output === "string" ? span.output : JSON.stringify(span.output);
|
|
353
|
+
if (span.type === SpanType.MODEL_GENERATION) {
|
|
354
|
+
attributes[ATTR_GEN_AI_OUTPUT_MESSAGES] = convertMastraMessagesToGenAIMessages(outputStr);
|
|
355
|
+
} else if (span.type === SpanType.TOOL_CALL || span.type === SpanType.MCP_TOOL_CALL) {
|
|
356
|
+
attributes["gen_ai.tool.call.result"] = outputStr;
|
|
357
|
+
} else {
|
|
358
|
+
attributes[`mastra.${spanType}.output`] = outputStr;
|
|
385
359
|
}
|
|
386
360
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
buildAttributes(aiSpan) {
|
|
392
|
-
const attributes = {};
|
|
393
|
-
attributes["gen_ai.operation.name"] = this.getOperationName(aiSpan);
|
|
394
|
-
attributes["span.kind"] = this.getSpanKindString(aiSpan);
|
|
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
|
-
}
|
|
361
|
+
if (span.type === SpanType.MODEL_GENERATION && span.attributes) {
|
|
362
|
+
const modelAttrs = span.attributes;
|
|
363
|
+
if (modelAttrs.model) {
|
|
364
|
+
attributes[ATTR_GEN_AI_REQUEST_MODEL] = modelAttrs.model;
|
|
409
365
|
}
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
attributes["output"] = outputStr;
|
|
413
|
-
if (aiSpan.type === AISpanType.MODEL_GENERATION) {
|
|
414
|
-
attributes["gen_ai.completion"] = outputStr;
|
|
415
|
-
} else if (aiSpan.type === AISpanType.TOOL_CALL || aiSpan.type === AISpanType.MCP_TOOL_CALL) {
|
|
416
|
-
attributes["gen_ai.tool.output"] = outputStr;
|
|
417
|
-
}
|
|
366
|
+
if (modelAttrs.provider) {
|
|
367
|
+
attributes[ATTR_GEN_AI_PROVIDER_NAME] = normalizeProvider(modelAttrs.provider);
|
|
418
368
|
}
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
369
|
+
if (modelAttrs.agentId) {
|
|
370
|
+
attributes[ATTR_GEN_AI_AGENT_ID] = modelAttrs.agentId;
|
|
371
|
+
}
|
|
372
|
+
if (modelAttrs.agentName) {
|
|
373
|
+
attributes[ATTR_GEN_AI_AGENT_NAME] = modelAttrs.agentName;
|
|
374
|
+
}
|
|
375
|
+
if (modelAttrs.usage) {
|
|
376
|
+
const inputTokens = modelAttrs.usage.inputTokens ?? modelAttrs.usage.promptTokens;
|
|
377
|
+
const outputTokens = modelAttrs.usage.outputTokens ?? modelAttrs.usage.completionTokens;
|
|
378
|
+
if (inputTokens !== void 0) {
|
|
379
|
+
attributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = inputTokens;
|
|
423
380
|
}
|
|
424
|
-
if (
|
|
425
|
-
attributes[
|
|
381
|
+
if (outputTokens !== void 0) {
|
|
382
|
+
attributes[ATTR_GEN_AI_USAGE_OUTPUT_TOKENS] = outputTokens;
|
|
426
383
|
}
|
|
427
|
-
if (modelAttrs.usage) {
|
|
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
|
-
}
|
|
384
|
+
if (modelAttrs.usage.reasoningTokens !== void 0) {
|
|
385
|
+
attributes["gen_ai.usage.reasoning_tokens"] = modelAttrs.usage.reasoningTokens;
|
|
445
386
|
}
|
|
446
|
-
if (modelAttrs.
|
|
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
|
-
}
|
|
468
|
-
}
|
|
469
|
-
if (modelAttrs.finishReason) {
|
|
470
|
-
attributes["gen_ai.response.finish_reasons"] = modelAttrs.finishReason;
|
|
387
|
+
if (modelAttrs.usage.cachedInputTokens !== void 0) {
|
|
388
|
+
attributes["gen_ai.usage.cached_input_tokens"] = modelAttrs.usage.cachedInputTokens;
|
|
471
389
|
}
|
|
472
390
|
}
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
attributes["gen_ai.tool.name"] = toolAttrs.toolId;
|
|
391
|
+
if (modelAttrs.parameters) {
|
|
392
|
+
if (modelAttrs.parameters.temperature !== void 0) {
|
|
393
|
+
attributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = modelAttrs.parameters.temperature;
|
|
477
394
|
}
|
|
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
|
-
}
|
|
395
|
+
if (modelAttrs.parameters.maxOutputTokens !== void 0) {
|
|
396
|
+
attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = modelAttrs.parameters.maxOutputTokens;
|
|
490
397
|
}
|
|
491
|
-
if (
|
|
492
|
-
attributes[
|
|
398
|
+
if (modelAttrs.parameters.topP !== void 0) {
|
|
399
|
+
attributes[ATTR_GEN_AI_REQUEST_TOP_P] = modelAttrs.parameters.topP;
|
|
493
400
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const agentAttrs = aiSpan.attributes;
|
|
497
|
-
if (agentAttrs.agentId) {
|
|
498
|
-
attributes["agent.id"] = agentAttrs.agentId;
|
|
499
|
-
attributes["gen_ai.agent.id"] = agentAttrs.agentId;
|
|
401
|
+
if (modelAttrs.parameters.topK !== void 0) {
|
|
402
|
+
attributes[ATTR_GEN_AI_REQUEST_TOP_K] = modelAttrs.parameters.topK;
|
|
500
403
|
}
|
|
501
|
-
if (
|
|
502
|
-
attributes[
|
|
404
|
+
if (modelAttrs.parameters.presencePenalty !== void 0) {
|
|
405
|
+
attributes[ATTR_GEN_AI_REQUEST_PRESENCE_PENALTY] = modelAttrs.parameters.presencePenalty;
|
|
503
406
|
}
|
|
504
|
-
if (
|
|
505
|
-
attributes[
|
|
407
|
+
if (modelAttrs.parameters.frequencyPenalty !== void 0) {
|
|
408
|
+
attributes[ATTR_GEN_AI_REQUEST_FREQUENCY_PENALTY] = modelAttrs.parameters.frequencyPenalty;
|
|
506
409
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const workflowAttrs = aiSpan.attributes;
|
|
510
|
-
if (workflowAttrs.workflowId) {
|
|
511
|
-
attributes["workflow.id"] = workflowAttrs.workflowId;
|
|
410
|
+
if (modelAttrs.parameters.stopSequences) {
|
|
411
|
+
attributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = JSON.stringify(modelAttrs.parameters.stopSequences);
|
|
512
412
|
}
|
|
513
|
-
if (
|
|
514
|
-
attributes[
|
|
413
|
+
if (modelAttrs.parameters.seed) {
|
|
414
|
+
attributes[ATTR_GEN_AI_REQUEST_SEED] = modelAttrs.parameters.seed;
|
|
515
415
|
}
|
|
516
416
|
}
|
|
517
|
-
if (
|
|
518
|
-
attributes[
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
417
|
+
if (modelAttrs.finishReason) {
|
|
418
|
+
attributes[ATTR_GEN_AI_RESPONSE_FINISH_REASONS] = JSON.stringify([modelAttrs.finishReason]);
|
|
419
|
+
}
|
|
420
|
+
if (modelAttrs.responseModel) {
|
|
421
|
+
attributes[ATTR_GEN_AI_RESPONSE_MODEL] = modelAttrs.responseModel;
|
|
422
|
+
}
|
|
423
|
+
if (modelAttrs.responseId) {
|
|
424
|
+
attributes[ATTR_GEN_AI_RESPONSE_ID] = modelAttrs.responseId;
|
|
425
|
+
}
|
|
426
|
+
if (modelAttrs.serverAddress) {
|
|
427
|
+
attributes[ATTR_SERVER_ADDRESS] = modelAttrs.serverAddress;
|
|
428
|
+
}
|
|
429
|
+
if (modelAttrs.serverPort !== void 0) {
|
|
430
|
+
attributes[ATTR_SERVER_PORT] = modelAttrs.serverPort;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if ((span.type === SpanType.TOOL_CALL || span.type === SpanType.MCP_TOOL_CALL) && span.attributes) {
|
|
434
|
+
const toolAttrs = span.attributes;
|
|
435
|
+
if (toolAttrs.toolId) {
|
|
436
|
+
attributes[ATTR_GEN_AI_TOOL_NAME] = toolAttrs.toolId;
|
|
437
|
+
}
|
|
438
|
+
if (span.type === SpanType.MCP_TOOL_CALL) {
|
|
439
|
+
const mcpAttrs = toolAttrs;
|
|
440
|
+
if (mcpAttrs.mcpServer) {
|
|
441
|
+
attributes[ATTR_SERVER_ADDRESS] = mcpAttrs.mcpServer;
|
|
523
442
|
}
|
|
524
|
-
|
|
525
|
-
|
|
443
|
+
} else {
|
|
444
|
+
if (toolAttrs.toolDescription) {
|
|
445
|
+
attributes[ATTR_GEN_AI_TOOL_DESCRIPTION] = toolAttrs.toolDescription;
|
|
526
446
|
}
|
|
527
447
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
448
|
+
}
|
|
449
|
+
if (span.type === SpanType.AGENT_RUN && span.attributes) {
|
|
450
|
+
const agentAttrs = span.attributes;
|
|
451
|
+
if (agentAttrs.agentId) {
|
|
452
|
+
attributes[ATTR_GEN_AI_AGENT_ID] = agentAttrs.agentId;
|
|
453
|
+
}
|
|
454
|
+
if (agentAttrs.agentName) {
|
|
455
|
+
attributes[ATTR_GEN_AI_AGENT_NAME] = agentAttrs.agentName;
|
|
456
|
+
}
|
|
457
|
+
if (agentAttrs.conversationId) {
|
|
458
|
+
attributes[ATTR_GEN_AI_CONVERSATION_ID] = agentAttrs.conversationId;
|
|
459
|
+
}
|
|
460
|
+
if (agentAttrs.maxSteps) {
|
|
461
|
+
attributes[`mastra.${spanType}.max_steps`] = agentAttrs.maxSteps;
|
|
462
|
+
}
|
|
463
|
+
if (agentAttrs.availableTools) {
|
|
464
|
+
attributes[`gen_ai.tool.definitions`] = JSON.stringify(agentAttrs.availableTools);
|
|
465
|
+
}
|
|
466
|
+
attributes[ATTR_GEN_AI_SYSTEM_INSTRUCTIONS] = agentAttrs.instructions;
|
|
467
|
+
}
|
|
468
|
+
if (span.errorInfo) {
|
|
469
|
+
attributes[ATTR_ERROR_TYPE] = span.errorInfo.id || "unknown";
|
|
470
|
+
attributes[ATTR_ERROR_MESSAGE] = span.errorInfo.message;
|
|
471
|
+
if (span.errorInfo.domain) {
|
|
472
|
+
attributes["error.domain"] = span.errorInfo.domain;
|
|
541
473
|
}
|
|
542
|
-
if (
|
|
543
|
-
attributes["
|
|
474
|
+
if (span.errorInfo.category) {
|
|
475
|
+
attributes["error.category"] = span.errorInfo.category;
|
|
544
476
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
477
|
+
}
|
|
478
|
+
return attributes;
|
|
479
|
+
}
|
|
480
|
+
var PROVIDER_ALIASES = {
|
|
481
|
+
anthropic: ["anthropic", "claude"],
|
|
482
|
+
"aws.bedrock": ["awsbedrock", "bedrock", "amazonbedrock"],
|
|
483
|
+
"azure.ai.inference": ["azureaiinference", "azureinference"],
|
|
484
|
+
"azure.ai.openai": ["azureaiopenai", "azureopenai", "msopenai", "microsoftopenai"],
|
|
485
|
+
cohere: ["cohere"],
|
|
486
|
+
deepseek: ["deepseek"],
|
|
487
|
+
"gcp.gemini": ["gcpgemini", "gemini"],
|
|
488
|
+
"gcp.gen_ai": ["gcpgenai", "googlegenai", "googleai"],
|
|
489
|
+
"gcp.vertex_ai": ["gcpvertexai", "vertexai"],
|
|
490
|
+
groq: ["groq"],
|
|
491
|
+
"ibm.watsonx.ai": ["ibmwatsonxai", "watsonx", "watsonxai"],
|
|
492
|
+
mistral_ai: ["mistral", "mistralai"],
|
|
493
|
+
openai: ["openai", "oai"],
|
|
494
|
+
perplexity: ["perplexity", "pplx"],
|
|
495
|
+
x_ai: ["xai", "x-ai", "x_ai", "x.com ai"]
|
|
496
|
+
};
|
|
497
|
+
function normalizeProviderString(input) {
|
|
498
|
+
return input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
499
|
+
}
|
|
500
|
+
function normalizeProvider(providerName) {
|
|
501
|
+
const normalized = normalizeProviderString(providerName);
|
|
502
|
+
for (const [canonical, aliases] of Object.entries(PROVIDER_ALIASES)) {
|
|
503
|
+
for (const alias of aliases) {
|
|
504
|
+
if (normalized === alias) {
|
|
505
|
+
return canonical;
|
|
506
|
+
}
|
|
549
507
|
}
|
|
550
|
-
return attributes;
|
|
551
508
|
}
|
|
509
|
+
return providerName.toLowerCase();
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/span-converter.ts
|
|
513
|
+
var SpanConverter = class {
|
|
514
|
+
constructor(params) {
|
|
515
|
+
this.params = params;
|
|
516
|
+
this.format = params.format;
|
|
517
|
+
}
|
|
518
|
+
resource;
|
|
519
|
+
scope;
|
|
520
|
+
initPromise;
|
|
521
|
+
format;
|
|
552
522
|
/**
|
|
553
|
-
*
|
|
523
|
+
* Lazily initialize resource & scope on first use.
|
|
524
|
+
* Subsequent calls reuse the same promise (no races).
|
|
554
525
|
*/
|
|
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, ".");
|
|
526
|
+
async initIfNeeded() {
|
|
527
|
+
if (this.initPromise) {
|
|
528
|
+
return this.initPromise;
|
|
570
529
|
}
|
|
530
|
+
this.initPromise = (async () => {
|
|
531
|
+
const packageVersion = await getPackageVersion(this.params.packageName) ?? "unknown";
|
|
532
|
+
const serviceVersion = await getPackageVersion("@mastra/core") ?? "unknown";
|
|
533
|
+
let resource = resourceFromAttributes({
|
|
534
|
+
[ATTR_SERVICE_NAME]: this.params.serviceName || "mastra-service",
|
|
535
|
+
[ATTR_SERVICE_VERSION]: serviceVersion,
|
|
536
|
+
[ATTR_TELEMETRY_SDK_NAME]: this.params.packageName,
|
|
537
|
+
[ATTR_TELEMETRY_SDK_VERSION]: packageVersion,
|
|
538
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: "nodejs"
|
|
539
|
+
});
|
|
540
|
+
if (this.params.config?.resourceAttributes) {
|
|
541
|
+
resource = resource.merge(
|
|
542
|
+
// Duplicate attributes from config will override defaults above
|
|
543
|
+
resourceFromAttributes(this.params.config.resourceAttributes)
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
this.resource = resource;
|
|
547
|
+
this.scope = {
|
|
548
|
+
name: this.params.packageName,
|
|
549
|
+
version: packageVersion
|
|
550
|
+
};
|
|
551
|
+
})();
|
|
552
|
+
return this.initPromise;
|
|
571
553
|
}
|
|
572
554
|
/**
|
|
573
|
-
*
|
|
555
|
+
* Convert a Mastra Span to an OpenTelemetry ReadableSpan
|
|
574
556
|
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
557
|
+
async convertSpan(span) {
|
|
558
|
+
await this.initIfNeeded();
|
|
559
|
+
if (!this.resource || !this.scope) {
|
|
560
|
+
throw new Error("SpanConverter not initialized correctly");
|
|
561
|
+
}
|
|
562
|
+
const name = getSpanName(span);
|
|
563
|
+
const kind = getSpanKind(span.type);
|
|
564
|
+
const attributes = getAttributes(span);
|
|
565
|
+
if (span.metadata) {
|
|
566
|
+
for (const [k, v] of Object.entries(span.metadata)) {
|
|
567
|
+
if (v === null || v === void 0) {
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
attributes[`mastra.metadata.${k}`] = typeof v === "object" ? JSON.stringify(v) : v;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (span.isRootSpan && span.tags?.length) {
|
|
574
|
+
attributes["mastra.tags"] = JSON.stringify(span.tags);
|
|
590
575
|
}
|
|
576
|
+
const startTime = dateToHrTime(span.startTime);
|
|
577
|
+
const endTime = span.endTime ? dateToHrTime(span.endTime) : startTime;
|
|
578
|
+
const duration = computeDuration(span.startTime, span.endTime);
|
|
579
|
+
const { status, events } = buildStatusAndEvents(span, startTime);
|
|
580
|
+
const spanContext = {
|
|
581
|
+
traceId: span.traceId,
|
|
582
|
+
spanId: span.id,
|
|
583
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
584
|
+
isRemote: false
|
|
585
|
+
};
|
|
586
|
+
const parentSpanContext = span.parentSpanId ? {
|
|
587
|
+
traceId: span.traceId,
|
|
588
|
+
spanId: span.parentSpanId,
|
|
589
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
590
|
+
isRemote: false
|
|
591
|
+
} : void 0;
|
|
592
|
+
const links = [];
|
|
593
|
+
const readable = {
|
|
594
|
+
name,
|
|
595
|
+
kind,
|
|
596
|
+
spanContext: () => spanContext,
|
|
597
|
+
parentSpanContext,
|
|
598
|
+
startTime,
|
|
599
|
+
endTime,
|
|
600
|
+
status,
|
|
601
|
+
attributes,
|
|
602
|
+
links,
|
|
603
|
+
events,
|
|
604
|
+
duration,
|
|
605
|
+
ended: !!span.endTime,
|
|
606
|
+
resource: this.resource,
|
|
607
|
+
instrumentationScope: this.scope,
|
|
608
|
+
droppedAttributesCount: 0,
|
|
609
|
+
droppedEventsCount: 0,
|
|
610
|
+
droppedLinksCount: 0
|
|
611
|
+
};
|
|
612
|
+
return readable;
|
|
591
613
|
}
|
|
592
614
|
};
|
|
615
|
+
async function getPackageVersion(pkgName) {
|
|
616
|
+
try {
|
|
617
|
+
const manifestUrl = new URL(await import.meta.resolve(`${pkgName}/package.json`));
|
|
618
|
+
const path = fileURLToPath(manifestUrl);
|
|
619
|
+
const pkgJson = JSON.parse(readFileSync(path, "utf8"));
|
|
620
|
+
return pkgJson.version;
|
|
621
|
+
} catch {
|
|
622
|
+
return void 0;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function getSpanKind(type) {
|
|
626
|
+
switch (type) {
|
|
627
|
+
case SpanType.MODEL_GENERATION:
|
|
628
|
+
case SpanType.MCP_TOOL_CALL:
|
|
629
|
+
return SpanKind.CLIENT;
|
|
630
|
+
default:
|
|
631
|
+
return SpanKind.INTERNAL;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function dateToHrTime(date) {
|
|
635
|
+
const ms = date.getTime();
|
|
636
|
+
const seconds = Math.floor(ms / 1e3);
|
|
637
|
+
const nanoseconds = ms % 1e3 * 1e6;
|
|
638
|
+
return [seconds, nanoseconds];
|
|
639
|
+
}
|
|
640
|
+
function computeDuration(start, end) {
|
|
641
|
+
if (!end) return [0, 0];
|
|
642
|
+
const diffMs = end.getTime() - start.getTime();
|
|
643
|
+
return [Math.floor(diffMs / 1e3), diffMs % 1e3 * 1e6];
|
|
644
|
+
}
|
|
645
|
+
function buildStatusAndEvents(span, defaultTime) {
|
|
646
|
+
const events = [];
|
|
647
|
+
if (span.errorInfo) {
|
|
648
|
+
const status = {
|
|
649
|
+
code: SpanStatusCode.ERROR,
|
|
650
|
+
message: span.errorInfo.message
|
|
651
|
+
};
|
|
652
|
+
events.push({
|
|
653
|
+
name: "exception",
|
|
654
|
+
attributes: {
|
|
655
|
+
"exception.message": span.errorInfo.message,
|
|
656
|
+
"exception.type": "Error",
|
|
657
|
+
...span.errorInfo.details?.stack && {
|
|
658
|
+
"exception.stacktrace": span.errorInfo.details.stack
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
time: defaultTime,
|
|
662
|
+
droppedAttributesCount: 0
|
|
663
|
+
});
|
|
664
|
+
return { status, events };
|
|
665
|
+
}
|
|
666
|
+
if (span.endTime) {
|
|
667
|
+
return {
|
|
668
|
+
status: { code: SpanStatusCode.OK },
|
|
669
|
+
events
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
return {
|
|
673
|
+
status: { code: SpanStatusCode.UNSET },
|
|
674
|
+
events
|
|
675
|
+
};
|
|
676
|
+
}
|
|
593
677
|
|
|
594
|
-
// src/
|
|
678
|
+
// src/tracing.ts
|
|
595
679
|
var OtelExporter = class extends BaseExporter {
|
|
596
680
|
config;
|
|
597
|
-
|
|
681
|
+
observabilityConfig;
|
|
598
682
|
spanConverter;
|
|
599
683
|
processor;
|
|
600
684
|
exporter;
|
|
@@ -603,7 +687,6 @@ var OtelExporter = class extends BaseExporter {
|
|
|
603
687
|
constructor(config) {
|
|
604
688
|
super(config);
|
|
605
689
|
this.config = config;
|
|
606
|
-
this.spanConverter = new SpanConverter();
|
|
607
690
|
if (config.logLevel === "debug") {
|
|
608
691
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
|
|
609
692
|
}
|
|
@@ -611,8 +694,8 @@ var OtelExporter = class extends BaseExporter {
|
|
|
611
694
|
/**
|
|
612
695
|
* Initialize with tracing configuration
|
|
613
696
|
*/
|
|
614
|
-
init(
|
|
615
|
-
this.
|
|
697
|
+
init(options) {
|
|
698
|
+
this.observabilityConfig = options.config;
|
|
616
699
|
}
|
|
617
700
|
async setupExporter() {
|
|
618
701
|
if (this.isSetup || this.exporter) return;
|
|
@@ -690,21 +773,12 @@ var OtelExporter = class extends BaseExporter {
|
|
|
690
773
|
}
|
|
691
774
|
async setupProcessor() {
|
|
692
775
|
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"
|
|
776
|
+
this.spanConverter = new SpanConverter({
|
|
777
|
+
packageName: "@mastra/otel-exporter",
|
|
778
|
+
serviceName: this.observabilityConfig?.serviceName,
|
|
779
|
+
config: this.config,
|
|
780
|
+
format: "GenAI_v1_38_0"
|
|
700
781
|
});
|
|
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
782
|
this.processor = new BatchSpanProcessor(this.exporter, {
|
|
709
783
|
maxExportBatchSize: this.config.batchSize || 512,
|
|
710
784
|
// Default batch size
|
|
@@ -725,8 +799,8 @@ var OtelExporter = class extends BaseExporter {
|
|
|
725
799
|
await this.setupProcessor();
|
|
726
800
|
this.isSetup = true;
|
|
727
801
|
}
|
|
728
|
-
async
|
|
729
|
-
if (event.type !==
|
|
802
|
+
async _exportTracingEvent(event) {
|
|
803
|
+
if (event.type !== TracingEventType.SPAN_ENDED) {
|
|
730
804
|
return;
|
|
731
805
|
}
|
|
732
806
|
const span = event.exportedSpan;
|
|
@@ -740,9 +814,9 @@ var OtelExporter = class extends BaseExporter {
|
|
|
740
814
|
return;
|
|
741
815
|
}
|
|
742
816
|
try {
|
|
743
|
-
const
|
|
817
|
+
const otelSpan = await this.spanConverter.convertSpan(span);
|
|
744
818
|
await new Promise((resolve) => {
|
|
745
|
-
this.processor.onEnd(
|
|
819
|
+
this.processor.onEnd(otelSpan);
|
|
746
820
|
resolve();
|
|
747
821
|
});
|
|
748
822
|
this.logger.debug(
|
|
@@ -759,6 +833,6 @@ var OtelExporter = class extends BaseExporter {
|
|
|
759
833
|
}
|
|
760
834
|
};
|
|
761
835
|
|
|
762
|
-
export { OtelExporter };
|
|
836
|
+
export { OtelExporter, SpanConverter, getSpanKind };
|
|
763
837
|
//# sourceMappingURL=index.js.map
|
|
764
838
|
//# sourceMappingURL=index.js.map
|