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