@agentmark-ai/shared-utils 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +197 -1
- package/dist/index.d.ts +197 -1
- package/dist/index.js +705 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +696 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,31 +34,40 @@ __export(index_exports, {
|
|
|
34
34
|
AgentMarkTransformer: () => AgentMarkTransformer,
|
|
35
35
|
AiSdkTransformer: () => AiSdkTransformer,
|
|
36
36
|
ClaudeAgentTransformer: () => AgentMarkTransformer,
|
|
37
|
+
DispatchingTransformer: () => DispatchingTransformer,
|
|
37
38
|
MastraTransformer: () => MastraTransformer,
|
|
39
|
+
OpenInferenceTransformer: () => OpenInferenceTransformer,
|
|
40
|
+
OpenLLMetryTransformer: () => OpenLLMetryTransformer,
|
|
38
41
|
OtelGenAiTransformer: () => OtelGenAiTransformer,
|
|
39
42
|
SEMANTIC_KINDS: () => SEMANTIC_KINDS,
|
|
40
43
|
SpanType: () => SpanType,
|
|
41
44
|
TransformerRegistry: () => TransformerRegistry,
|
|
42
45
|
TypeClassifier: () => TypeClassifier,
|
|
46
|
+
collectIndices: () => collectIndices,
|
|
43
47
|
convertOtlpAttributes: () => convertOtlpAttributes,
|
|
44
48
|
createSignature: () => createSignature,
|
|
45
49
|
deriveTraceIO: () => deriveTraceIO,
|
|
46
50
|
detectVersion: () => detectVersion,
|
|
47
51
|
extractCustomMetadata: () => extractCustomMetadata,
|
|
52
|
+
extractIndexedToolCalls: () => extractIndexedToolCalls,
|
|
48
53
|
extractReasoningFromProviderMetadata: () => extractReasoningFromProviderMetadata,
|
|
49
54
|
extractResourceScopeSpan: () => extractResourceScopeSpan,
|
|
50
55
|
fetchPromptsFrontmatter: () => fetchPromptsFrontmatter,
|
|
51
56
|
findPromptFiles: () => findPromptFiles,
|
|
52
57
|
generateTypeDefinitions: () => generateTypeDefinitions,
|
|
53
58
|
generateUnique8CharString: () => generateUnique8CharString,
|
|
59
|
+
hasVectorStoreSignature: () => hasVectorStoreSignature,
|
|
60
|
+
messagesToPlainText: () => messagesToPlainText,
|
|
54
61
|
normalizeOtlpSpans: () => normalizeOtlpSpans,
|
|
55
62
|
normalizeOtlpStatusCode: () => normalizeOtlpStatusCode,
|
|
56
63
|
normalizeSpan: () => normalizeSpan,
|
|
57
64
|
parseAgentMarkAttributes: () => parseAgentMarkAttributes,
|
|
65
|
+
parseIndexedMessages: () => parseIndexedMessages,
|
|
58
66
|
parseMetadata: () => parseMetadata,
|
|
59
67
|
parseTokens: () => parseTokens,
|
|
60
68
|
registry: () => registry,
|
|
61
69
|
resolveSemanticKind: () => resolveSemanticKind,
|
|
70
|
+
retrievalDocumentsToText: () => retrievalDocumentsToText,
|
|
62
71
|
toFrontMatter: () => toFrontMatter,
|
|
63
72
|
typeClassifier: () => typeClassifier,
|
|
64
73
|
verifySignature: () => verifySignature
|
|
@@ -2203,85 +2212,562 @@ var OtelGenAiTransformer = class {
|
|
|
2203
2212
|
};
|
|
2204
2213
|
OtelGenAiTransformer.SCOPE_NAME = "pydantic-ai";
|
|
2205
2214
|
|
|
2206
|
-
// src/normalizer/
|
|
2207
|
-
function
|
|
2215
|
+
// src/normalizer/extractors/indexed-message-parser.ts
|
|
2216
|
+
function escapeRegExp(value) {
|
|
2217
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2218
|
+
}
|
|
2219
|
+
function collectIndices(attributes, prefix) {
|
|
2220
|
+
const re = new RegExp(`^${escapeRegExp(prefix)}\\.(\\d+)\\.`);
|
|
2221
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2222
|
+
for (const key of Object.keys(attributes)) {
|
|
2223
|
+
const match = re.exec(key);
|
|
2224
|
+
if (match) seen.add(Number(match[1]));
|
|
2225
|
+
}
|
|
2226
|
+
return [...seen].sort((a, b) => a - b);
|
|
2227
|
+
}
|
|
2228
|
+
function parseArgs(raw) {
|
|
2229
|
+
if (raw === void 0 || raw === null) return {};
|
|
2230
|
+
if (typeof raw === "object") return raw;
|
|
2231
|
+
if (typeof raw === "string") {
|
|
2232
|
+
try {
|
|
2233
|
+
const parsed = JSON.parse(raw);
|
|
2234
|
+
return parsed && typeof parsed === "object" ? parsed : { raw };
|
|
2235
|
+
} catch {
|
|
2236
|
+
return { raw };
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
return { raw };
|
|
2240
|
+
}
|
|
2241
|
+
function readMessageToolCalls(attributes, messageBase, config) {
|
|
2242
|
+
const tc = config.toolCalls;
|
|
2243
|
+
if (!tc) return [];
|
|
2244
|
+
const arrayPrefix = `${messageBase}${tc.arrayKey}`;
|
|
2245
|
+
const indices = collectIndices(attributes, arrayPrefix);
|
|
2246
|
+
const calls = [];
|
|
2247
|
+
for (const j of indices) {
|
|
2248
|
+
const base = `${arrayPrefix}.${j}.${tc.infix}`;
|
|
2249
|
+
const name = attributes[`${base}${tc.nameKey}`];
|
|
2250
|
+
if (name === void 0) continue;
|
|
2251
|
+
const id = attributes[`${base}${tc.idKey}`];
|
|
2252
|
+
const args = parseArgs(attributes[`${base}${tc.argsKey}`]);
|
|
2253
|
+
calls.push({
|
|
2254
|
+
type: "tool-call",
|
|
2255
|
+
toolCallId: id !== void 0 ? String(id) : "",
|
|
2256
|
+
toolName: String(name),
|
|
2257
|
+
args
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
return calls;
|
|
2261
|
+
}
|
|
2262
|
+
function readContentsText(attributes, messageBase, config) {
|
|
2208
2263
|
var _a;
|
|
2209
|
-
if (
|
|
2210
|
-
|
|
2264
|
+
if (!config.contentsKey) return void 0;
|
|
2265
|
+
const contentsPrefix = `${messageBase}${config.contentsKey}`;
|
|
2266
|
+
const indices = collectIndices(attributes, contentsPrefix);
|
|
2267
|
+
if (indices.length === 0) return void 0;
|
|
2268
|
+
const partInfix = (_a = config.contentsPartInfix) != null ? _a : "";
|
|
2269
|
+
const parts = [];
|
|
2270
|
+
for (const j of indices) {
|
|
2271
|
+
const text = attributes[`${contentsPrefix}.${j}.${partInfix}text`];
|
|
2272
|
+
if (typeof text === "string" && text.length > 0) parts.push(text);
|
|
2273
|
+
}
|
|
2274
|
+
return parts.length > 0 ? parts.join("\n") : void 0;
|
|
2275
|
+
}
|
|
2276
|
+
function parseIndexedMessages(attributes, config) {
|
|
2277
|
+
var _a, _b;
|
|
2278
|
+
const indices = collectIndices(attributes, config.prefix);
|
|
2279
|
+
if (indices.length === 0) return void 0;
|
|
2280
|
+
const roleKey = (_a = config.roleKey) != null ? _a : "role";
|
|
2281
|
+
const contentKey = (_b = config.contentKey) != null ? _b : "content";
|
|
2282
|
+
const messages = [];
|
|
2283
|
+
for (const i of indices) {
|
|
2284
|
+
const base = `${config.prefix}.${i}.${config.messageInfix}`;
|
|
2285
|
+
const role = attributes[`${base}${roleKey}`];
|
|
2286
|
+
const scalarContent = attributes[`${base}${contentKey}`];
|
|
2287
|
+
const text = typeof scalarContent === "string" ? scalarContent : scalarContent !== void 0 ? String(scalarContent) : readContentsText(attributes, base, config);
|
|
2288
|
+
const toolCalls = readMessageToolCalls(attributes, base, config);
|
|
2289
|
+
if (role === void 0 && text === void 0 && toolCalls.length === 0) continue;
|
|
2290
|
+
let content;
|
|
2291
|
+
if (toolCalls.length > 0) {
|
|
2292
|
+
const parts = [];
|
|
2293
|
+
if (text) parts.push({ type: "text", text });
|
|
2294
|
+
for (const call of toolCalls) {
|
|
2295
|
+
parts.push({
|
|
2296
|
+
type: "tool-call",
|
|
2297
|
+
toolCallId: call.toolCallId,
|
|
2298
|
+
toolName: call.toolName,
|
|
2299
|
+
args: call.args
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
content = parts;
|
|
2303
|
+
} else {
|
|
2304
|
+
content = text != null ? text : "";
|
|
2305
|
+
}
|
|
2306
|
+
messages.push({ role: role !== void 0 ? String(role) : "user", content });
|
|
2211
2307
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2308
|
+
return messages.length > 0 ? messages : void 0;
|
|
2309
|
+
}
|
|
2310
|
+
function extractIndexedToolCalls(attributes, config) {
|
|
2311
|
+
if (!config.toolCalls) return void 0;
|
|
2312
|
+
const indices = collectIndices(attributes, config.prefix);
|
|
2313
|
+
const calls = [];
|
|
2314
|
+
for (const i of indices) {
|
|
2315
|
+
const base = `${config.prefix}.${i}.${config.messageInfix}`;
|
|
2316
|
+
calls.push(...readMessageToolCalls(attributes, base, config));
|
|
2317
|
+
}
|
|
2318
|
+
return calls.length > 0 ? calls : void 0;
|
|
2319
|
+
}
|
|
2320
|
+
function messagesToPlainText(messages) {
|
|
2321
|
+
if (!messages || messages.length === 0) return void 0;
|
|
2322
|
+
const chunks = [];
|
|
2323
|
+
for (const msg of messages) {
|
|
2324
|
+
if (typeof msg.content === "string") {
|
|
2325
|
+
if (msg.content.length > 0) chunks.push(msg.content);
|
|
2326
|
+
} else if (Array.isArray(msg.content)) {
|
|
2327
|
+
for (const part of msg.content) {
|
|
2328
|
+
if (typeof part === "string") {
|
|
2329
|
+
if (part.length > 0) chunks.push(part);
|
|
2330
|
+
} else if (part.type === "text" && part.text.length > 0) {
|
|
2331
|
+
chunks.push(part.text);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2214
2335
|
}
|
|
2215
|
-
|
|
2216
|
-
|
|
2336
|
+
return chunks.length > 0 ? chunks.join("\n") : void 0;
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// src/normalizer/utils/coerce.ts
|
|
2340
|
+
function toNumber(value) {
|
|
2341
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
2342
|
+
if (typeof value === "string") {
|
|
2343
|
+
const n = Number(value);
|
|
2344
|
+
return Number.isFinite(n) ? n : void 0;
|
|
2217
2345
|
}
|
|
2218
|
-
|
|
2219
|
-
|
|
2346
|
+
return void 0;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
// src/normalizer/transformers/openinference/index.ts
|
|
2350
|
+
var Attrs2 = {
|
|
2351
|
+
SPAN_KIND: "openinference.span.kind",
|
|
2352
|
+
MODEL: "llm.model_name",
|
|
2353
|
+
PROVIDER: "llm.provider",
|
|
2354
|
+
SYSTEM: "llm.system",
|
|
2355
|
+
INVOCATION_PARAMETERS: "llm.invocation_parameters",
|
|
2356
|
+
TOKEN_PROMPT: "llm.token_count.prompt",
|
|
2357
|
+
TOKEN_COMPLETION: "llm.token_count.completion",
|
|
2358
|
+
TOKEN_TOTAL: "llm.token_count.total",
|
|
2359
|
+
TOKEN_REASONING: "llm.token_count.completion_details.reasoning",
|
|
2360
|
+
INPUT_VALUE: "input.value",
|
|
2361
|
+
INPUT_MIME: "input.mime_type",
|
|
2362
|
+
OUTPUT_VALUE: "output.value",
|
|
2363
|
+
OUTPUT_MIME: "output.mime_type",
|
|
2364
|
+
TOOL_NAME: "tool.name",
|
|
2365
|
+
SESSION_ID: "session.id",
|
|
2366
|
+
USER_ID: "user.id",
|
|
2367
|
+
METADATA: "metadata"
|
|
2368
|
+
};
|
|
2369
|
+
var INPUT_MESSAGES = {
|
|
2370
|
+
prefix: "llm.input_messages",
|
|
2371
|
+
messageInfix: "message.",
|
|
2372
|
+
contentsKey: "contents",
|
|
2373
|
+
contentsPartInfix: "message_content.",
|
|
2374
|
+
toolCalls: {
|
|
2375
|
+
arrayKey: "tool_calls",
|
|
2376
|
+
infix: "tool_call.",
|
|
2377
|
+
idKey: "id",
|
|
2378
|
+
nameKey: "function.name",
|
|
2379
|
+
argsKey: "function.arguments"
|
|
2220
2380
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2381
|
+
};
|
|
2382
|
+
var OUTPUT_MESSAGES = {
|
|
2383
|
+
...INPUT_MESSAGES,
|
|
2384
|
+
prefix: "llm.output_messages"
|
|
2385
|
+
};
|
|
2386
|
+
var RETRIEVAL_PREFIX = "retrieval.documents";
|
|
2387
|
+
function extractSettings(attributes) {
|
|
2388
|
+
var _a, _b, _c, _d, _e;
|
|
2389
|
+
const raw = attributes[Attrs2.INVOCATION_PARAMETERS];
|
|
2390
|
+
if (raw === void 0) return void 0;
|
|
2391
|
+
let parsed;
|
|
2392
|
+
if (typeof raw === "string") {
|
|
2393
|
+
try {
|
|
2394
|
+
parsed = JSON.parse(raw);
|
|
2395
|
+
} catch {
|
|
2396
|
+
return void 0;
|
|
2397
|
+
}
|
|
2398
|
+
} else if (typeof raw === "object" && raw !== null) {
|
|
2399
|
+
parsed = raw;
|
|
2400
|
+
} else {
|
|
2401
|
+
return void 0;
|
|
2223
2402
|
}
|
|
2224
|
-
if (
|
|
2225
|
-
|
|
2403
|
+
if (!parsed || typeof parsed !== "object") return void 0;
|
|
2404
|
+
const settings = {};
|
|
2405
|
+
const temperature = toNumber(parsed.temperature);
|
|
2406
|
+
const maxTokens = toNumber((_b = (_a = parsed.max_tokens) != null ? _a : parsed.maxTokens) != null ? _b : parsed.max_completion_tokens);
|
|
2407
|
+
const topP = toNumber((_c = parsed.top_p) != null ? _c : parsed.topP);
|
|
2408
|
+
const presencePenalty = toNumber((_d = parsed.presence_penalty) != null ? _d : parsed.presencePenalty);
|
|
2409
|
+
const frequencyPenalty = toNumber((_e = parsed.frequency_penalty) != null ? _e : parsed.frequencyPenalty);
|
|
2410
|
+
if (temperature !== void 0) settings.temperature = temperature;
|
|
2411
|
+
if (maxTokens !== void 0) settings.maxTokens = maxTokens;
|
|
2412
|
+
if (topP !== void 0) settings.topP = topP;
|
|
2413
|
+
if (presencePenalty !== void 0) settings.presencePenalty = presencePenalty;
|
|
2414
|
+
if (frequencyPenalty !== void 0) settings.frequencyPenalty = frequencyPenalty;
|
|
2415
|
+
return Object.keys(settings).length > 0 ? settings : void 0;
|
|
2416
|
+
}
|
|
2417
|
+
function extractGenericInput(attributes) {
|
|
2418
|
+
const value = attributes[Attrs2.INPUT_VALUE];
|
|
2419
|
+
if (value === void 0) return {};
|
|
2420
|
+
const mime = attributes[Attrs2.INPUT_MIME];
|
|
2421
|
+
if (mime === "application/json" && typeof value === "string") {
|
|
2422
|
+
try {
|
|
2423
|
+
const parsed = JSON.parse(value);
|
|
2424
|
+
if (Array.isArray(parsed) && parsed.every((m) => m && typeof m === "object" && "role" in m)) {
|
|
2425
|
+
return { input: parsed };
|
|
2426
|
+
}
|
|
2427
|
+
return { input: [{ role: "user", content: JSON.stringify(parsed) }] };
|
|
2428
|
+
} catch {
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return { input: [{ role: "user", content: String(value) }] };
|
|
2432
|
+
}
|
|
2433
|
+
function extractGenericOutput(attributes) {
|
|
2434
|
+
const value = attributes[Attrs2.OUTPUT_VALUE];
|
|
2435
|
+
if (value === void 0) return {};
|
|
2436
|
+
const mime = attributes[Attrs2.OUTPUT_MIME];
|
|
2437
|
+
if (mime === "application/json" && typeof value === "string") {
|
|
2438
|
+
try {
|
|
2439
|
+
const parsed = JSON.parse(value);
|
|
2440
|
+
return { output: JSON.stringify(parsed), outputObject: parsed };
|
|
2441
|
+
} catch {
|
|
2442
|
+
}
|
|
2226
2443
|
}
|
|
2444
|
+
return { output: String(value) };
|
|
2445
|
+
}
|
|
2446
|
+
function parseDocumentMetadata(raw) {
|
|
2447
|
+
let parsed = raw;
|
|
2448
|
+
if (typeof raw === "string") {
|
|
2449
|
+
try {
|
|
2450
|
+
parsed = JSON.parse(raw);
|
|
2451
|
+
} catch {
|
|
2452
|
+
return void 0;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
2227
2456
|
return void 0;
|
|
2228
2457
|
}
|
|
2229
|
-
function
|
|
2230
|
-
|
|
2231
|
-
|
|
2458
|
+
function extractRetrievalDocuments(attributes) {
|
|
2459
|
+
const docs = [];
|
|
2460
|
+
for (const i of collectIndices(attributes, RETRIEVAL_PREFIX)) {
|
|
2461
|
+
const base = `${RETRIEVAL_PREFIX}.${i}.document`;
|
|
2462
|
+
const doc = {};
|
|
2463
|
+
const id = attributes[`${base}.id`];
|
|
2464
|
+
if (id !== void 0 && id !== null && String(id).length > 0) doc.id = String(id);
|
|
2465
|
+
const content = attributes[`${base}.content`];
|
|
2466
|
+
if (typeof content === "string" && content.length > 0) doc.content = content;
|
|
2467
|
+
const score = toNumber(attributes[`${base}.score`]);
|
|
2468
|
+
if (score !== void 0) doc.score = score;
|
|
2469
|
+
const metadata = parseDocumentMetadata(attributes[`${base}.metadata`]);
|
|
2470
|
+
if (metadata !== void 0) doc.metadata = metadata;
|
|
2471
|
+
if (Object.keys(doc).length > 0) docs.push(doc);
|
|
2472
|
+
}
|
|
2473
|
+
return docs;
|
|
2474
|
+
}
|
|
2475
|
+
function retrievalDocumentsToText(documents) {
|
|
2476
|
+
const text = documents.map((d) => d.content).filter((c) => typeof c === "string" && c.length > 0).join("\n\n");
|
|
2477
|
+
return text.length > 0 ? text : void 0;
|
|
2478
|
+
}
|
|
2479
|
+
var OpenInferenceTransformer = class {
|
|
2480
|
+
classify(_span, attributes) {
|
|
2481
|
+
const kind = attributes[Attrs2.SPAN_KIND];
|
|
2482
|
+
if (typeof kind === "string" && kind.toUpperCase() === "LLM") return "GENERATION" /* GENERATION */;
|
|
2483
|
+
if (attributes[Attrs2.TOKEN_PROMPT] !== void 0 || attributes[Attrs2.TOKEN_COMPLETION] !== void 0) {
|
|
2484
|
+
return "GENERATION" /* GENERATION */;
|
|
2485
|
+
}
|
|
2486
|
+
return "SPAN" /* SPAN */;
|
|
2232
2487
|
}
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2488
|
+
transform(_span, attributes) {
|
|
2489
|
+
const result = {};
|
|
2490
|
+
const model = attributes[Attrs2.MODEL];
|
|
2491
|
+
if (typeof model === "string" && model.length > 0) result.model = model;
|
|
2492
|
+
const inputTokens = toNumber(attributes[Attrs2.TOKEN_PROMPT]);
|
|
2493
|
+
const outputTokens = toNumber(attributes[Attrs2.TOKEN_COMPLETION]);
|
|
2494
|
+
const totalTokens = toNumber(attributes[Attrs2.TOKEN_TOTAL]);
|
|
2495
|
+
const reasoningTokens = toNumber(attributes[Attrs2.TOKEN_REASONING]);
|
|
2496
|
+
if (inputTokens !== void 0) result.inputTokens = inputTokens;
|
|
2497
|
+
if (outputTokens !== void 0) result.outputTokens = outputTokens;
|
|
2498
|
+
if (totalTokens !== void 0) {
|
|
2499
|
+
result.totalTokens = totalTokens;
|
|
2500
|
+
} else if (inputTokens !== void 0 && outputTokens !== void 0) {
|
|
2501
|
+
result.totalTokens = inputTokens + outputTokens;
|
|
2502
|
+
}
|
|
2503
|
+
if (reasoningTokens !== void 0) result.reasoningTokens = reasoningTokens;
|
|
2504
|
+
const settings = extractSettings(attributes);
|
|
2505
|
+
if (settings) result.settings = settings;
|
|
2506
|
+
const inputMessages = parseIndexedMessages(attributes, INPUT_MESSAGES);
|
|
2507
|
+
if (inputMessages) {
|
|
2508
|
+
result.input = inputMessages;
|
|
2509
|
+
} else {
|
|
2510
|
+
Object.assign(result, extractGenericInput(attributes));
|
|
2511
|
+
}
|
|
2512
|
+
const outputMessages = parseIndexedMessages(attributes, OUTPUT_MESSAGES);
|
|
2513
|
+
const toolCalls = extractIndexedToolCalls(attributes, OUTPUT_MESSAGES);
|
|
2514
|
+
if (toolCalls) result.toolCalls = toolCalls;
|
|
2515
|
+
if (outputMessages) {
|
|
2516
|
+
const text = messagesToPlainText(outputMessages);
|
|
2517
|
+
if (text) result.output = text;
|
|
2518
|
+
} else {
|
|
2519
|
+
Object.assign(result, extractGenericOutput(attributes));
|
|
2520
|
+
}
|
|
2521
|
+
const documents = extractRetrievalDocuments(attributes);
|
|
2522
|
+
if (documents.length > 0) {
|
|
2523
|
+
if (result.outputObject === void 0) result.outputObject = { documents };
|
|
2524
|
+
if (result.output === void 0) {
|
|
2525
|
+
const text = retrievalDocumentsToText(documents);
|
|
2526
|
+
if (text) result.output = text;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
const toolName = attributes[Attrs2.TOOL_NAME];
|
|
2530
|
+
if (typeof toolName === "string" && toolName.length > 0) result.name = toolName;
|
|
2531
|
+
const sessionId = attributes[Attrs2.SESSION_ID];
|
|
2532
|
+
if (sessionId !== void 0) result.sessionId = String(sessionId);
|
|
2533
|
+
const userId = attributes[Attrs2.USER_ID];
|
|
2534
|
+
if (userId !== void 0) result.userId = String(userId);
|
|
2535
|
+
const metadataRaw = attributes[Attrs2.METADATA];
|
|
2536
|
+
if (metadataRaw !== void 0) {
|
|
2537
|
+
let parsed = metadataRaw;
|
|
2538
|
+
if (typeof metadataRaw === "string") {
|
|
2539
|
+
try {
|
|
2540
|
+
parsed = JSON.parse(metadataRaw);
|
|
2541
|
+
} catch {
|
|
2542
|
+
parsed = void 0;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2546
|
+
const metadata = {};
|
|
2547
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
2548
|
+
metadata[k] = typeof v === "string" ? v : JSON.stringify(v);
|
|
2549
|
+
}
|
|
2550
|
+
if (Object.keys(metadata).length > 0) result.metadata = metadata;
|
|
2551
|
+
}
|
|
2237
2552
|
}
|
|
2553
|
+
return result;
|
|
2238
2554
|
}
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
// src/normalizer/transformers/openllmetry/index.ts
|
|
2558
|
+
var Attrs3 = {
|
|
2559
|
+
SPAN_KIND: "traceloop.span.kind",
|
|
2560
|
+
REQUEST_MODEL: "gen_ai.request.model",
|
|
2561
|
+
RESPONSE_MODEL: "gen_ai.response.model",
|
|
2562
|
+
REQUEST_TEMPERATURE: "gen_ai.request.temperature",
|
|
2563
|
+
REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens",
|
|
2564
|
+
REQUEST_TOP_P: "gen_ai.request.top_p",
|
|
2565
|
+
REQUEST_PRESENCE_PENALTY: "gen_ai.request.presence_penalty",
|
|
2566
|
+
REQUEST_FREQUENCY_PENALTY: "gen_ai.request.frequency_penalty",
|
|
2567
|
+
RESPONSE_FINISH_REASON: "gen_ai.response.finish_reason",
|
|
2568
|
+
TOTAL_TOKENS_ALT: "llm.usage.total_tokens",
|
|
2569
|
+
ENTITY_INPUT: "traceloop.entity.input",
|
|
2570
|
+
ENTITY_OUTPUT: "traceloop.entity.output",
|
|
2571
|
+
ENTITY_NAME: "traceloop.entity.name",
|
|
2572
|
+
ASSOCIATION_PREFIX: "traceloop.association.properties."
|
|
2573
|
+
};
|
|
2574
|
+
var PROMPT_MESSAGES = {
|
|
2575
|
+
prefix: "gen_ai.prompt",
|
|
2576
|
+
messageInfix: "",
|
|
2577
|
+
toolCalls: { arrayKey: "tool_calls", infix: "", idKey: "id", nameKey: "name", argsKey: "arguments" }
|
|
2578
|
+
};
|
|
2579
|
+
var COMPLETION_MESSAGES = {
|
|
2580
|
+
...PROMPT_MESSAGES,
|
|
2581
|
+
prefix: "gen_ai.completion"
|
|
2582
|
+
};
|
|
2583
|
+
function extractSettings2(attributes) {
|
|
2584
|
+
const settings = {};
|
|
2585
|
+
const temperature = toNumber(attributes[Attrs3.REQUEST_TEMPERATURE]);
|
|
2586
|
+
const maxTokens = toNumber(attributes[Attrs3.REQUEST_MAX_TOKENS]);
|
|
2587
|
+
const topP = toNumber(attributes[Attrs3.REQUEST_TOP_P]);
|
|
2588
|
+
const presencePenalty = toNumber(attributes[Attrs3.REQUEST_PRESENCE_PENALTY]);
|
|
2589
|
+
const frequencyPenalty = toNumber(attributes[Attrs3.REQUEST_FREQUENCY_PENALTY]);
|
|
2590
|
+
if (temperature !== void 0) settings.temperature = temperature;
|
|
2591
|
+
if (maxTokens !== void 0) settings.maxTokens = maxTokens;
|
|
2592
|
+
if (topP !== void 0) settings.topP = topP;
|
|
2593
|
+
if (presencePenalty !== void 0) settings.presencePenalty = presencePenalty;
|
|
2594
|
+
if (frequencyPenalty !== void 0) settings.frequencyPenalty = frequencyPenalty;
|
|
2595
|
+
return Object.keys(settings).length > 0 ? settings : void 0;
|
|
2596
|
+
}
|
|
2597
|
+
function extractEntityInput(attributes) {
|
|
2598
|
+
const raw = attributes[Attrs3.ENTITY_INPUT];
|
|
2599
|
+
if (raw === void 0) return void 0;
|
|
2600
|
+
const text = typeof raw === "string" ? raw : JSON.stringify(raw);
|
|
2601
|
+
return [{ role: "user", content: text }];
|
|
2602
|
+
}
|
|
2603
|
+
function extractEntityOutput(attributes) {
|
|
2604
|
+
const raw = attributes[Attrs3.ENTITY_OUTPUT];
|
|
2605
|
+
if (raw === void 0) return {};
|
|
2606
|
+
if (typeof raw === "string") {
|
|
2607
|
+
try {
|
|
2608
|
+
const parsed = JSON.parse(raw);
|
|
2609
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2610
|
+
return { output: raw, outputObject: parsed };
|
|
2611
|
+
}
|
|
2612
|
+
} catch {
|
|
2613
|
+
}
|
|
2614
|
+
return { output: raw };
|
|
2615
|
+
}
|
|
2616
|
+
const result = { output: JSON.stringify(raw) };
|
|
2617
|
+
if (typeof raw === "object" && raw !== null) result.outputObject = raw;
|
|
2239
2618
|
return result;
|
|
2240
2619
|
}
|
|
2241
|
-
function
|
|
2620
|
+
function extractFromEvents(events, attrKey) {
|
|
2242
2621
|
var _a, _b, _c;
|
|
2243
|
-
|
|
2244
|
-
const
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
const links = (otlpSpan.links || []).map((otlpLink) => ({
|
|
2258
|
-
traceId: otlpLink.traceId,
|
|
2259
|
-
spanId: otlpLink.spanId,
|
|
2260
|
-
traceState: otlpLink.traceState,
|
|
2261
|
-
attributes: convertOtlpAttributes(otlpLink.attributes)
|
|
2262
|
-
}));
|
|
2263
|
-
const span = {
|
|
2264
|
-
traceId: otlpSpan.traceId,
|
|
2265
|
-
spanId: otlpSpan.spanId,
|
|
2266
|
-
parentSpanId: otlpSpan.parentSpanId,
|
|
2267
|
-
traceState: otlpSpan.traceState,
|
|
2268
|
-
name: otlpSpan.name,
|
|
2269
|
-
kind: otlpSpan.kind,
|
|
2270
|
-
startTimeUnixNano: otlpSpan.startTimeUnixNano,
|
|
2271
|
-
endTimeUnixNano: otlpSpan.endTimeUnixNano,
|
|
2272
|
-
attributes: spanAttributes,
|
|
2273
|
-
events,
|
|
2274
|
-
links,
|
|
2275
|
-
status: otlpSpan.status
|
|
2276
|
-
};
|
|
2277
|
-
const resource = {
|
|
2278
|
-
attributes: resourceAttributes
|
|
2279
|
-
};
|
|
2280
|
-
result.push({ resource, scope, span });
|
|
2622
|
+
if (!events) return void 0;
|
|
2623
|
+
for (const event of events) {
|
|
2624
|
+
const value = (_c = (_a = event.attributes) == null ? void 0 : _a[attrKey]) != null ? _c : (_b = event.attributes) == null ? void 0 : _b["content"];
|
|
2625
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
2626
|
+
}
|
|
2627
|
+
return void 0;
|
|
2628
|
+
}
|
|
2629
|
+
function parseResultMetadata(raw) {
|
|
2630
|
+
let parsed = raw;
|
|
2631
|
+
if (typeof raw === "string") {
|
|
2632
|
+
try {
|
|
2633
|
+
parsed = JSON.parse(raw);
|
|
2634
|
+
} catch {
|
|
2635
|
+
return void 0;
|
|
2281
2636
|
}
|
|
2282
2637
|
}
|
|
2283
|
-
return
|
|
2638
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
2639
|
+
return void 0;
|
|
2640
|
+
}
|
|
2641
|
+
var VECTOR_RESULT_EVENT_NAMES = /* @__PURE__ */ new Set(["db.query.result", "db.search.result"]);
|
|
2642
|
+
function extractVectorResultDocuments(events) {
|
|
2643
|
+
var _a, _b;
|
|
2644
|
+
if (!events) return [];
|
|
2645
|
+
const docs = [];
|
|
2646
|
+
for (const event of events) {
|
|
2647
|
+
if (!VECTOR_RESULT_EVENT_NAMES.has(event.name)) continue;
|
|
2648
|
+
const a = (_a = event.attributes) != null ? _a : {};
|
|
2649
|
+
const get = (field) => {
|
|
2650
|
+
var _a2;
|
|
2651
|
+
return (_a2 = a[`db.query.result.${field}`]) != null ? _a2 : a[`db.search.result.${field}`];
|
|
2652
|
+
};
|
|
2653
|
+
const doc = {};
|
|
2654
|
+
const id = get("id");
|
|
2655
|
+
if (id !== void 0 && id !== null && String(id).length > 0) doc.id = String(id);
|
|
2656
|
+
const content = get("document");
|
|
2657
|
+
if (typeof content === "string" && content.length > 0) doc.content = content;
|
|
2658
|
+
const score = toNumber(get("score"));
|
|
2659
|
+
if (score !== void 0) doc.score = score;
|
|
2660
|
+
const distance = toNumber(get("distance"));
|
|
2661
|
+
if (distance !== void 0) doc.distance = distance;
|
|
2662
|
+
let metadata = parseResultMetadata(get("metadata"));
|
|
2663
|
+
if (metadata === void 0) {
|
|
2664
|
+
const entity = get("entity");
|
|
2665
|
+
if (entity !== void 0 && entity !== null && String(entity).length > 0) {
|
|
2666
|
+
metadata = (_b = parseResultMetadata(entity)) != null ? _b : { entity: String(entity) };
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
if (metadata !== void 0) doc.metadata = metadata;
|
|
2670
|
+
if (Object.keys(doc).length > 0) docs.push(doc);
|
|
2671
|
+
}
|
|
2672
|
+
return docs;
|
|
2673
|
+
}
|
|
2674
|
+
function extractFinishReason(attributes) {
|
|
2675
|
+
const direct = attributes[Attrs3.RESPONSE_FINISH_REASON];
|
|
2676
|
+
if (direct !== void 0) {
|
|
2677
|
+
return Array.isArray(direct) ? String(direct[0]) : String(direct);
|
|
2678
|
+
}
|
|
2679
|
+
const indexed = attributes["gen_ai.completion.0.finish_reason"];
|
|
2680
|
+
if (indexed !== void 0) return String(indexed);
|
|
2681
|
+
return void 0;
|
|
2284
2682
|
}
|
|
2683
|
+
var OpenLLMetryTransformer = class {
|
|
2684
|
+
classify(_span, attributes) {
|
|
2685
|
+
const kind = attributes[Attrs3.SPAN_KIND];
|
|
2686
|
+
if (typeof kind === "string" && kind.toUpperCase() === "LLM") return "GENERATION" /* GENERATION */;
|
|
2687
|
+
if (attributes["gen_ai.usage.prompt_tokens"] !== void 0 || attributes["gen_ai.usage.completion_tokens"] !== void 0 || attributes["gen_ai.usage.input_tokens"] !== void 0) {
|
|
2688
|
+
return "GENERATION" /* GENERATION */;
|
|
2689
|
+
}
|
|
2690
|
+
return "SPAN" /* SPAN */;
|
|
2691
|
+
}
|
|
2692
|
+
transform(span, attributes) {
|
|
2693
|
+
var _a;
|
|
2694
|
+
const result = {};
|
|
2695
|
+
const model = (_a = attributes[Attrs3.RESPONSE_MODEL]) != null ? _a : attributes[Attrs3.REQUEST_MODEL];
|
|
2696
|
+
if (typeof model === "string" && model.length > 0) result.model = model;
|
|
2697
|
+
const tokens = parseTokens(attributes, {
|
|
2698
|
+
inputKey: "gen_ai.usage.input_tokens",
|
|
2699
|
+
outputKey: "gen_ai.usage.output_tokens",
|
|
2700
|
+
totalKey: "gen_ai.usage.total_tokens",
|
|
2701
|
+
promptKey: "gen_ai.usage.prompt_tokens",
|
|
2702
|
+
completionKey: "gen_ai.usage.completion_tokens"
|
|
2703
|
+
});
|
|
2704
|
+
if (tokens.inputTokens !== void 0) result.inputTokens = tokens.inputTokens;
|
|
2705
|
+
if (tokens.outputTokens !== void 0) result.outputTokens = tokens.outputTokens;
|
|
2706
|
+
if (tokens.totalTokens !== void 0) {
|
|
2707
|
+
result.totalTokens = tokens.totalTokens;
|
|
2708
|
+
} else {
|
|
2709
|
+
const altTotal = toNumber(attributes[Attrs3.TOTAL_TOKENS_ALT]);
|
|
2710
|
+
if (altTotal !== void 0) result.totalTokens = altTotal;
|
|
2711
|
+
}
|
|
2712
|
+
const settings = extractSettings2(attributes);
|
|
2713
|
+
if (settings) result.settings = settings;
|
|
2714
|
+
const finishReason = extractFinishReason(attributes);
|
|
2715
|
+
if (finishReason) result.finishReason = finishReason;
|
|
2716
|
+
const promptMessages = parseIndexedMessages(attributes, PROMPT_MESSAGES);
|
|
2717
|
+
if (promptMessages) {
|
|
2718
|
+
result.input = promptMessages;
|
|
2719
|
+
} else {
|
|
2720
|
+
const entityInput = extractEntityInput(attributes);
|
|
2721
|
+
if (entityInput) {
|
|
2722
|
+
result.input = entityInput;
|
|
2723
|
+
} else {
|
|
2724
|
+
const eventPrompt = extractFromEvents(span.events, "gen_ai.prompt");
|
|
2725
|
+
if (eventPrompt) result.input = [{ role: "user", content: eventPrompt }];
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
const completionMessages = parseIndexedMessages(attributes, COMPLETION_MESSAGES);
|
|
2729
|
+
const toolCalls = extractIndexedToolCalls(attributes, COMPLETION_MESSAGES);
|
|
2730
|
+
if (toolCalls) result.toolCalls = toolCalls;
|
|
2731
|
+
if (completionMessages) {
|
|
2732
|
+
const text = messagesToPlainText(completionMessages);
|
|
2733
|
+
if (text) result.output = text;
|
|
2734
|
+
} else {
|
|
2735
|
+
const entityOutput = extractEntityOutput(attributes);
|
|
2736
|
+
if (entityOutput.output !== void 0) {
|
|
2737
|
+
Object.assign(result, entityOutput);
|
|
2738
|
+
} else {
|
|
2739
|
+
const eventCompletion = extractFromEvents(span.events, "gen_ai.completion");
|
|
2740
|
+
if (eventCompletion) result.output = eventCompletion;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
if (result.outputObject === void 0) {
|
|
2744
|
+
const documents = extractVectorResultDocuments(span.events);
|
|
2745
|
+
if (documents.length > 0) {
|
|
2746
|
+
result.outputObject = { documents };
|
|
2747
|
+
if (result.output === void 0) {
|
|
2748
|
+
const text = documents.map((d) => d.content).filter((c) => typeof c === "string" && c.length > 0).join("\n\n");
|
|
2749
|
+
if (text) result.output = text;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
const entityName = attributes[Attrs3.ENTITY_NAME];
|
|
2754
|
+
if (typeof entityName === "string" && entityName.length > 0) result.traceName = entityName;
|
|
2755
|
+
const metadata = {};
|
|
2756
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
2757
|
+
if (!key.startsWith(Attrs3.ASSOCIATION_PREFIX)) continue;
|
|
2758
|
+
const prop = key.slice(Attrs3.ASSOCIATION_PREFIX.length);
|
|
2759
|
+
if (prop === "session_id") {
|
|
2760
|
+
result.sessionId = String(value);
|
|
2761
|
+
} else if (prop === "user_id") {
|
|
2762
|
+
result.userId = String(value);
|
|
2763
|
+
} else if (prop) {
|
|
2764
|
+
metadata[prop] = typeof value === "string" ? value : JSON.stringify(value);
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
if (Object.keys(metadata).length > 0) result.metadata = metadata;
|
|
2768
|
+
return result;
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2285
2771
|
|
|
2286
2772
|
// src/normalizer/resolvers/semantic-kind-resolver.ts
|
|
2287
2773
|
var SEMANTIC_KINDS = ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
@@ -2296,6 +2782,25 @@ var OPENINFERENCE_MAP = {
|
|
|
2296
2782
|
"GUARDRAIL": "guardrail",
|
|
2297
2783
|
"RERANKER": "retrieval"
|
|
2298
2784
|
};
|
|
2785
|
+
var VECTOR_DB_SYSTEMS = /* @__PURE__ */ new Set([
|
|
2786
|
+
"pinecone",
|
|
2787
|
+
"qdrant",
|
|
2788
|
+
"weaviate",
|
|
2789
|
+
"milvus",
|
|
2790
|
+
"chroma",
|
|
2791
|
+
"chromadb",
|
|
2792
|
+
"marqo",
|
|
2793
|
+
"lancedb"
|
|
2794
|
+
]);
|
|
2795
|
+
var VECTOR_RESULT_EVENT_NAMES2 = /* @__PURE__ */ new Set(["db.query.result", "db.search.result"]);
|
|
2796
|
+
function hasVectorStoreSignature(attributes, events) {
|
|
2797
|
+
var _a;
|
|
2798
|
+
const dbSystem = (_a = attributes["db.system"]) != null ? _a : attributes["db.system.name"];
|
|
2799
|
+
if (typeof dbSystem === "string" && VECTOR_DB_SYSTEMS.has(dbSystem.toLowerCase())) return true;
|
|
2800
|
+
if (Object.keys(attributes).some((k) => k.startsWith("db.vector.query."))) return true;
|
|
2801
|
+
if (events == null ? void 0 : events.some((e) => VECTOR_RESULT_EVENT_NAMES2.has(e.name))) return true;
|
|
2802
|
+
return false;
|
|
2803
|
+
}
|
|
2299
2804
|
var FRAMEWORK_MAPPINGS = [
|
|
2300
2805
|
{
|
|
2301
2806
|
key: "ai.operationId",
|
|
@@ -2348,6 +2853,9 @@ function resolveSemanticKind(normalized, allAttributes) {
|
|
|
2348
2853
|
if (mapped) return mapped;
|
|
2349
2854
|
}
|
|
2350
2855
|
}
|
|
2856
|
+
if (hasVectorStoreSignature(allAttributes, normalized.events)) {
|
|
2857
|
+
return "retrieval";
|
|
2858
|
+
}
|
|
2351
2859
|
const opName = allAttributes["gen_ai.operation.name"];
|
|
2352
2860
|
if (opName) {
|
|
2353
2861
|
const op = String(opName).toLowerCase();
|
|
@@ -2370,6 +2878,132 @@ function resolveSemanticKind(normalized, allAttributes) {
|
|
|
2370
2878
|
return "function";
|
|
2371
2879
|
}
|
|
2372
2880
|
|
|
2881
|
+
// src/normalizer/transformers/dispatching/index.ts
|
|
2882
|
+
var OPENINFERENCE_INDEXED = /^llm\.(input_messages|output_messages|token_count)\./;
|
|
2883
|
+
var OPENLLMETRY_INDEXED = /^gen_ai\.(prompt|completion)\.\d+\./;
|
|
2884
|
+
function isOpenInference(attributes) {
|
|
2885
|
+
if (attributes["openinference.span.kind"] !== void 0) return true;
|
|
2886
|
+
if (attributes["llm.model_name"] !== void 0) return true;
|
|
2887
|
+
for (const key of Object.keys(attributes)) {
|
|
2888
|
+
if (OPENINFERENCE_INDEXED.test(key)) return true;
|
|
2889
|
+
}
|
|
2890
|
+
return false;
|
|
2891
|
+
}
|
|
2892
|
+
function isOpenLLMetry(attributes) {
|
|
2893
|
+
for (const key of Object.keys(attributes)) {
|
|
2894
|
+
if (key.startsWith("traceloop.")) return true;
|
|
2895
|
+
if (OPENLLMETRY_INDEXED.test(key)) return true;
|
|
2896
|
+
}
|
|
2897
|
+
return false;
|
|
2898
|
+
}
|
|
2899
|
+
var DispatchingTransformer = class {
|
|
2900
|
+
constructor() {
|
|
2901
|
+
this.openInference = new OpenInferenceTransformer();
|
|
2902
|
+
this.openLLMetry = new OpenLLMetryTransformer();
|
|
2903
|
+
this.otelGenAi = new OtelGenAiTransformer();
|
|
2904
|
+
}
|
|
2905
|
+
/** Choose the extractor for a span from its attribute/event signature.
|
|
2906
|
+
* OpenInference is checked before OpenLLMetry because its markers (`llm.*`,
|
|
2907
|
+
* `openinference.span.kind`) are more specific. Vector-store query spans
|
|
2908
|
+
* route to the OpenLLMetry extractor — they may carry no `traceloop.*`
|
|
2909
|
+
* marker (a bare Pinecone span is just `db.system` + `db.query.result`
|
|
2910
|
+
* events), so without this they'd fall through to the OTel-GenAI catch-all
|
|
2911
|
+
* and their result documents would be dropped. The bare OTel GenAI
|
|
2912
|
+
* transformer is the final catch-all. */
|
|
2913
|
+
select(attributes, span) {
|
|
2914
|
+
if (isOpenInference(attributes)) return this.openInference;
|
|
2915
|
+
if (isOpenLLMetry(attributes)) return this.openLLMetry;
|
|
2916
|
+
if (hasVectorStoreSignature(attributes, span == null ? void 0 : span.events)) return this.openLLMetry;
|
|
2917
|
+
return this.otelGenAi;
|
|
2918
|
+
}
|
|
2919
|
+
classify(span, attributes) {
|
|
2920
|
+
return this.select(attributes, span).classify(span, attributes);
|
|
2921
|
+
}
|
|
2922
|
+
transform(span, attributes) {
|
|
2923
|
+
return this.select(attributes, span).transform(span, attributes);
|
|
2924
|
+
}
|
|
2925
|
+
};
|
|
2926
|
+
|
|
2927
|
+
// src/normalizer/converters/otlp-converter.ts
|
|
2928
|
+
function convertOtlpValue(value) {
|
|
2929
|
+
var _a;
|
|
2930
|
+
if (value.stringValue !== void 0) {
|
|
2931
|
+
return value.stringValue;
|
|
2932
|
+
}
|
|
2933
|
+
if (value.intValue !== void 0) {
|
|
2934
|
+
return typeof value.intValue === "string" ? parseInt(value.intValue, 10) : value.intValue;
|
|
2935
|
+
}
|
|
2936
|
+
if (value.doubleValue !== void 0) {
|
|
2937
|
+
return value.doubleValue;
|
|
2938
|
+
}
|
|
2939
|
+
if (value.boolValue !== void 0) {
|
|
2940
|
+
return value.boolValue;
|
|
2941
|
+
}
|
|
2942
|
+
if ((_a = value.arrayValue) == null ? void 0 : _a.values) {
|
|
2943
|
+
return value.arrayValue.values.map(convertOtlpValue);
|
|
2944
|
+
}
|
|
2945
|
+
if (value.bytesValue !== void 0) {
|
|
2946
|
+
return value.bytesValue;
|
|
2947
|
+
}
|
|
2948
|
+
return void 0;
|
|
2949
|
+
}
|
|
2950
|
+
function convertOtlpAttributes(attributes) {
|
|
2951
|
+
if (!attributes || attributes.length === 0) {
|
|
2952
|
+
return {};
|
|
2953
|
+
}
|
|
2954
|
+
const result = {};
|
|
2955
|
+
for (const attr of attributes) {
|
|
2956
|
+
if (attr.key && isSafeKey(attr.key)) {
|
|
2957
|
+
result[attr.key] = convertOtlpValue(attr.value);
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
return result;
|
|
2961
|
+
}
|
|
2962
|
+
function extractResourceScopeSpan(resourceSpans) {
|
|
2963
|
+
var _a, _b, _c;
|
|
2964
|
+
const result = [];
|
|
2965
|
+
const resourceAttributes = convertOtlpAttributes((_a = resourceSpans.resource) == null ? void 0 : _a.attributes);
|
|
2966
|
+
for (const scopeSpans of resourceSpans.scopeSpans || []) {
|
|
2967
|
+
const scope = {
|
|
2968
|
+
name: (_b = scopeSpans.scope) == null ? void 0 : _b.name,
|
|
2969
|
+
version: (_c = scopeSpans.scope) == null ? void 0 : _c.version
|
|
2970
|
+
};
|
|
2971
|
+
for (const otlpSpan of scopeSpans.spans || []) {
|
|
2972
|
+
const spanAttributes = convertOtlpAttributes(otlpSpan.attributes);
|
|
2973
|
+
const events = (otlpSpan.events || []).map((otlpEvent) => ({
|
|
2974
|
+
timeUnixNano: otlpEvent.timeUnixNano,
|
|
2975
|
+
name: otlpEvent.name,
|
|
2976
|
+
attributes: convertOtlpAttributes(otlpEvent.attributes)
|
|
2977
|
+
}));
|
|
2978
|
+
const links = (otlpSpan.links || []).map((otlpLink) => ({
|
|
2979
|
+
traceId: otlpLink.traceId,
|
|
2980
|
+
spanId: otlpLink.spanId,
|
|
2981
|
+
traceState: otlpLink.traceState,
|
|
2982
|
+
attributes: convertOtlpAttributes(otlpLink.attributes)
|
|
2983
|
+
}));
|
|
2984
|
+
const span = {
|
|
2985
|
+
traceId: otlpSpan.traceId,
|
|
2986
|
+
spanId: otlpSpan.spanId,
|
|
2987
|
+
parentSpanId: otlpSpan.parentSpanId,
|
|
2988
|
+
traceState: otlpSpan.traceState,
|
|
2989
|
+
name: otlpSpan.name,
|
|
2990
|
+
kind: otlpSpan.kind,
|
|
2991
|
+
startTimeUnixNano: otlpSpan.startTimeUnixNano,
|
|
2992
|
+
endTimeUnixNano: otlpSpan.endTimeUnixNano,
|
|
2993
|
+
attributes: spanAttributes,
|
|
2994
|
+
events,
|
|
2995
|
+
links,
|
|
2996
|
+
status: otlpSpan.status
|
|
2997
|
+
};
|
|
2998
|
+
const resource = {
|
|
2999
|
+
attributes: resourceAttributes
|
|
3000
|
+
};
|
|
3001
|
+
result.push({ resource, scope, span });
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
return result;
|
|
3005
|
+
}
|
|
3006
|
+
|
|
2373
3007
|
// src/normalizer/type-classifier.ts
|
|
2374
3008
|
var TypeClassifier = class {
|
|
2375
3009
|
classify(span, attributes) {
|
|
@@ -2392,7 +3026,7 @@ registry.register("ai", new AiSdkTransformer());
|
|
|
2392
3026
|
registry.register("default-tracer", new MastraTransformer());
|
|
2393
3027
|
registry.register("agentmark", new AgentMarkTransformer());
|
|
2394
3028
|
registry.register("pydantic-ai", new OtelGenAiTransformer());
|
|
2395
|
-
registry.setDefault(new
|
|
3029
|
+
registry.setDefault(new DispatchingTransformer());
|
|
2396
3030
|
var OTLP_STATUS_CODE_MAP = {
|
|
2397
3031
|
"0": "0",
|
|
2398
3032
|
STATUS_CODE_UNSET: "0",
|
|
@@ -2516,31 +3150,40 @@ function deriveTraceIO(spans) {
|
|
|
2516
3150
|
AgentMarkTransformer,
|
|
2517
3151
|
AiSdkTransformer,
|
|
2518
3152
|
ClaudeAgentTransformer,
|
|
3153
|
+
DispatchingTransformer,
|
|
2519
3154
|
MastraTransformer,
|
|
3155
|
+
OpenInferenceTransformer,
|
|
3156
|
+
OpenLLMetryTransformer,
|
|
2520
3157
|
OtelGenAiTransformer,
|
|
2521
3158
|
SEMANTIC_KINDS,
|
|
2522
3159
|
SpanType,
|
|
2523
3160
|
TransformerRegistry,
|
|
2524
3161
|
TypeClassifier,
|
|
3162
|
+
collectIndices,
|
|
2525
3163
|
convertOtlpAttributes,
|
|
2526
3164
|
createSignature,
|
|
2527
3165
|
deriveTraceIO,
|
|
2528
3166
|
detectVersion,
|
|
2529
3167
|
extractCustomMetadata,
|
|
3168
|
+
extractIndexedToolCalls,
|
|
2530
3169
|
extractReasoningFromProviderMetadata,
|
|
2531
3170
|
extractResourceScopeSpan,
|
|
2532
3171
|
fetchPromptsFrontmatter,
|
|
2533
3172
|
findPromptFiles,
|
|
2534
3173
|
generateTypeDefinitions,
|
|
2535
3174
|
generateUnique8CharString,
|
|
3175
|
+
hasVectorStoreSignature,
|
|
3176
|
+
messagesToPlainText,
|
|
2536
3177
|
normalizeOtlpSpans,
|
|
2537
3178
|
normalizeOtlpStatusCode,
|
|
2538
3179
|
normalizeSpan,
|
|
2539
3180
|
parseAgentMarkAttributes,
|
|
3181
|
+
parseIndexedMessages,
|
|
2540
3182
|
parseMetadata,
|
|
2541
3183
|
parseTokens,
|
|
2542
3184
|
registry,
|
|
2543
3185
|
resolveSemanticKind,
|
|
3186
|
+
retrievalDocumentsToText,
|
|
2544
3187
|
toFrontMatter,
|
|
2545
3188
|
typeClassifier,
|
|
2546
3189
|
verifySignature
|