@lmnr-ai/lmnr 0.8.30 → 0.8.32
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/cli.cjs +20 -22
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +7 -9
- package/dist/cli.mjs.map +1 -1
- package/dist/{consts-ivIFfgfN.mjs → consts-3AfXaMBI.mjs} +1 -1
- package/dist/{consts-ivIFfgfN.mjs.map → consts-3AfXaMBI.mjs.map} +1 -1
- package/dist/{consts-Cx9iKRmq.cjs → consts-DV6_Ea-8.cjs} +1 -1
- package/dist/{consts-Cx9iKRmq.cjs.map → consts-DV6_Ea-8.cjs.map} +1 -1
- package/dist/{dist-Cyli7uVF.cjs → dist-CDaxruok.cjs} +580 -12
- package/dist/dist-CDaxruok.cjs.map +1 -0
- package/dist/{dist-DMgpr2Zn.mjs → dist-DwtZd9Jy.mjs} +337 -5
- package/dist/dist-DwtZd9Jy.mjs.map +1 -0
- package/dist/{evaluations-DLNweSzE.d.cts → evaluations-8E6Oxgoq.d.cts} +18 -5
- package/dist/{evaluations-fF1Y_olL.d.mts → evaluations-HtzF0xSN.d.mts} +18 -5
- package/dist/{file-utils-CHgYB_Ei.mjs → file-utils-CjQ2Zw9n.mjs} +3 -3
- package/dist/{file-utils-CHgYB_Ei.mjs.map → file-utils-CjQ2Zw9n.mjs.map} +1 -1
- package/dist/{file-utils-Cysp1Ym1.cjs → file-utils-DWqUwg2p.cjs} +12 -12
- package/dist/{file-utils-Cysp1Ym1.cjs.map → file-utils-DWqUwg2p.cjs.map} +1 -1
- package/dist/index.cjs +555 -502
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -33
- package/dist/index.d.mts +108 -33
- package/dist/index.mjs +343 -290
- package/dist/index.mjs.map +1 -1
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.cjs +69 -69
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.cjs.map +1 -1
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.mjs +2 -2
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/dist-Cyli7uVF.cjs.map +0 -1
- package/dist/dist-DMgpr2Zn.mjs.map +0 -1
- package/dist/utils-Bdv7YZH7.mjs +0 -337
- package/dist/utils-Bdv7YZH7.mjs.map +0 -1
- package/dist/utils-C_Pf3r64.cjs +0 -561
- package/dist/utils-C_Pf3r64.cjs.map +0 -1
- /package/dist/{chunk-hT5z_Zn9.mjs → rolldown-runtime-2rV9d50f.mjs} +0 -0
- /package/dist/{chunk-BN4qSVkS.cjs → rolldown-runtime-CVvi-lCc.cjs} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const require_consts = require("./consts-Cx9iKRmq.cjs");
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CVvi-lCc.cjs");
|
|
3
|
+
const require_dist = require("./dist-CDaxruok.cjs");
|
|
4
|
+
const require_consts = require("./consts-DV6_Ea-8.cjs");
|
|
6
5
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
7
6
|
let _opentelemetry_context_async_hooks = require("@opentelemetry/context-async-hooks");
|
|
8
7
|
let _opentelemetry_instrumentation = require("@opentelemetry/instrumentation");
|
|
@@ -10,7 +9,7 @@ let _opentelemetry_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
|
10
9
|
let _opentelemetry_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
|
|
11
10
|
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
12
11
|
let path = require("path");
|
|
13
|
-
path =
|
|
12
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
14
13
|
let _traceloop_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
|
|
15
14
|
let _traceloop_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
|
|
16
15
|
let _traceloop_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
|
|
@@ -26,11 +25,11 @@ let node_crypto = require("node:crypto");
|
|
|
26
25
|
let node_fs = require("node:fs");
|
|
27
26
|
let node_path = require("node:path");
|
|
28
27
|
let fs = require("fs");
|
|
29
|
-
fs =
|
|
28
|
+
fs = require_rolldown_runtime.__toESM(fs);
|
|
30
29
|
let net = require("net");
|
|
31
|
-
net =
|
|
30
|
+
net = require_rolldown_runtime.__toESM(net);
|
|
32
31
|
let os = require("os");
|
|
33
|
-
os =
|
|
32
|
+
os = require_rolldown_runtime.__toESM(os);
|
|
34
33
|
let async_hooks = require("async_hooks");
|
|
35
34
|
let zod_to_json_schema = require("zod-to-json-schema");
|
|
36
35
|
let _opentelemetry_core = require("@opentelemetry/core");
|
|
@@ -38,11 +37,11 @@ let _grpc_grpc_js = require("@grpc/grpc-js");
|
|
|
38
37
|
let _opentelemetry_exporter_trace_otlp_grpc = require("@opentelemetry/exporter-trace-otlp-grpc");
|
|
39
38
|
let _opentelemetry_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
40
39
|
let cli_progress = require("cli-progress");
|
|
41
|
-
cli_progress =
|
|
40
|
+
cli_progress = require_rolldown_runtime.__toESM(cli_progress);
|
|
42
41
|
let _noble_hashes_blake3_js = require("@noble/hashes/blake3.js");
|
|
43
42
|
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
44
43
|
let node_diagnostics_channel = require("node:diagnostics_channel");
|
|
45
|
-
node_diagnostics_channel =
|
|
44
|
+
node_diagnostics_channel = require_rolldown_runtime.__toESM(node_diagnostics_channel);
|
|
46
45
|
//#region src/datasets.ts
|
|
47
46
|
const DEFAULT_FETCH_SIZE = 25;
|
|
48
47
|
var EvaluationDataset = class {
|
|
@@ -96,7 +95,7 @@ var LaminarDataset = class extends EvaluationDataset {
|
|
|
96
95
|
*/
|
|
97
96
|
async push(paths, recursive = false) {
|
|
98
97
|
if (!this.client) throw new Error("Client not set");
|
|
99
|
-
const { loadFromPaths } = await Promise.resolve().then(() => require("./file-utils-
|
|
98
|
+
const { loadFromPaths } = await Promise.resolve().then(() => require("./file-utils-DWqUwg2p.cjs")).then((n) => n.file_utils_exports);
|
|
100
99
|
const data = await loadFromPaths(Array.isArray(paths) ? paths : [paths], recursive);
|
|
101
100
|
if (data.length === 0) {
|
|
102
101
|
console.warn("No data to push. Skipping");
|
|
@@ -112,7 +111,7 @@ var LaminarDataset = class extends EvaluationDataset {
|
|
|
112
111
|
};
|
|
113
112
|
//#endregion
|
|
114
113
|
//#region src/opentelemetry-lib/tracing/compat.ts
|
|
115
|
-
const logger$24 =
|
|
114
|
+
const logger$24 = require_dist.initializeLogger();
|
|
116
115
|
const makeSpanOtelV2Compatible = (span) => {
|
|
117
116
|
const spanAny = span;
|
|
118
117
|
if (spanAny.instrumentationScope && !spanAny.instrumentationLibrary) Object.assign(span, { instrumentationLibrary: spanAny.instrumentationScope });
|
|
@@ -228,7 +227,7 @@ const consumeAISDKResult = async (result) => {
|
|
|
228
227
|
} catch (error) {
|
|
229
228
|
errors.push({
|
|
230
229
|
field: key,
|
|
231
|
-
error:
|
|
230
|
+
error: require_dist.errorMessage(error)
|
|
232
231
|
});
|
|
233
232
|
}
|
|
234
233
|
};
|
|
@@ -340,7 +339,7 @@ const consumeResponse = async (response) => {
|
|
|
340
339
|
};
|
|
341
340
|
//#endregion
|
|
342
341
|
//#region src/opentelemetry-lib/tracing/stream-utils.ts
|
|
343
|
-
const logger$23 =
|
|
342
|
+
const logger$23 = require_dist.initializeLogger();
|
|
344
343
|
const pendingStreamProcessing = /* @__PURE__ */ new Set();
|
|
345
344
|
/**
|
|
346
345
|
* Wait for all pending stream processing to complete with a timeout
|
|
@@ -383,15 +382,15 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
383
382
|
try {
|
|
384
383
|
partialOutput = await consumeAISDKResult(streamInfo.result);
|
|
385
384
|
if (shouldSendTraces() && !ignoreOutput) try {
|
|
386
|
-
span.setAttribute(
|
|
385
|
+
span.setAttribute(require_dist.SPAN_OUTPUT, serialize(partialOutput));
|
|
387
386
|
} catch (error) {
|
|
388
|
-
logger$23.warn("Failed to serialize AI SDK stream output: " +
|
|
387
|
+
logger$23.warn("Failed to serialize AI SDK stream output: " + require_dist.errorMessage(error));
|
|
389
388
|
}
|
|
390
389
|
} catch (error) {
|
|
391
390
|
if (Object.keys(partialOutput).length > 0 && shouldSendTraces() && !ignoreOutput) try {
|
|
392
|
-
span.setAttribute(
|
|
391
|
+
span.setAttribute(require_dist.SPAN_OUTPUT, serialize(partialOutput));
|
|
393
392
|
} catch (serError) {
|
|
394
|
-
logger$23.warn("Failed to serialize partial AI SDK output: " +
|
|
393
|
+
logger$23.warn("Failed to serialize partial AI SDK output: " + require_dist.errorMessage(serError));
|
|
395
394
|
}
|
|
396
395
|
span.recordException(error);
|
|
397
396
|
} finally {
|
|
@@ -412,9 +411,9 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
412
411
|
type: "stream",
|
|
413
412
|
chunks
|
|
414
413
|
};
|
|
415
|
-
span.setAttribute(
|
|
414
|
+
span.setAttribute(require_dist.SPAN_OUTPUT, serialize(output));
|
|
416
415
|
} catch (serError) {
|
|
417
|
-
logger$23.warn("Failed to serialize stream output: " +
|
|
416
|
+
logger$23.warn("Failed to serialize stream output: " + require_dist.errorMessage(serError));
|
|
418
417
|
}
|
|
419
418
|
if (error) span.recordException(error);
|
|
420
419
|
} finally {
|
|
@@ -435,9 +434,9 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
435
434
|
type: "async-iterable",
|
|
436
435
|
chunks
|
|
437
436
|
};
|
|
438
|
-
span.setAttribute(
|
|
437
|
+
span.setAttribute(require_dist.SPAN_OUTPUT, serialize(output));
|
|
439
438
|
} catch (serError) {
|
|
440
|
-
logger$23.warn("Failed to serialize async iterable output: " +
|
|
439
|
+
logger$23.warn("Failed to serialize async iterable output: " + require_dist.errorMessage(serError));
|
|
441
440
|
}
|
|
442
441
|
if (error) span.recordException(error);
|
|
443
442
|
} finally {
|
|
@@ -468,9 +467,9 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
468
467
|
type: "response",
|
|
469
468
|
chunks
|
|
470
469
|
};
|
|
471
|
-
span.setAttribute(
|
|
470
|
+
span.setAttribute(require_dist.SPAN_OUTPUT, serialize(output));
|
|
472
471
|
} catch (serError) {
|
|
473
|
-
logger$23.warn("Failed to serialize response output: " +
|
|
472
|
+
logger$23.warn("Failed to serialize response output: " + require_dist.errorMessage(serError));
|
|
474
473
|
}
|
|
475
474
|
if (error) span.recordException(error);
|
|
476
475
|
} catch (err) {
|
|
@@ -487,50 +486,67 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
487
486
|
return originalResult;
|
|
488
487
|
};
|
|
489
488
|
//#endregion
|
|
490
|
-
//#region src/debug/
|
|
489
|
+
//#region src/debug/debug-session-file.ts
|
|
490
|
+
const str = (v) => typeof v === "string" && v.length > 0 ? v : null;
|
|
491
491
|
/**
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
* followed by compact JSON. When `LMNR_DEBUG_WRITE_LAST_RUN_TO_FILE` is set the
|
|
496
|
-
* same payload is also written to `${CWD}/.lmnr/last-run.json` (best-effort: any
|
|
497
|
-
* IO error is swallowed so a read-only working directory never breaks the run).
|
|
498
|
-
*
|
|
499
|
-
* Part of the cross-language parity surface — keep line-comparable with the
|
|
500
|
-
* Python `pointer.py` (identical key order, prefix, and best-effort semantics).
|
|
492
|
+
* Read `${dir ?? cwd}/.lmnr/debug-session.json`. Best-effort: returns null on a
|
|
493
|
+
* missing / unreadable / malformed file, or one with no usable `session_id`
|
|
494
|
+
* (the caller treats null as "no existing session" and mints a fresh one).
|
|
501
495
|
*/
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
const
|
|
496
|
+
const readDebugSessionFile = (dir = process.cwd()) => {
|
|
497
|
+
try {
|
|
498
|
+
const raw = (0, node_fs.readFileSync)((0, node_path.join)(dir, require_dist.DEBUG_SESSION_DIR, require_dist.DEBUG_SESSION_FILE), "utf-8");
|
|
499
|
+
const r = JSON.parse(raw);
|
|
500
|
+
const session_id = str(r.session_id);
|
|
501
|
+
if (!session_id) return null;
|
|
502
|
+
return {
|
|
503
|
+
session_id,
|
|
504
|
+
trace_id: str(r.trace_id),
|
|
505
|
+
replay_trace_id: str(r.replay_trace_id),
|
|
506
|
+
cache_until: str(r.cache_until),
|
|
507
|
+
debugger_url: str(r.debugger_url),
|
|
508
|
+
started_at: str(r.started_at) ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
509
|
+
};
|
|
510
|
+
} catch {
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
};
|
|
506
514
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* (shutdown). Defaults to now for standalone callers.
|
|
515
|
+
* Find the nearest directory (walking up from `startDir` to the filesystem
|
|
516
|
+
* root) whose `.lmnr/debug-session.json` holds a usable session record, so a
|
|
517
|
+
* debug run started from a subdirectory of a project joins the project's
|
|
518
|
+
* session. Returns null when no ancestor (including `startDir`) has one.
|
|
512
519
|
*/
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const emitPointer = (pointer) => {
|
|
523
|
-
const payload = JSON.stringify(pointer);
|
|
524
|
-
console.log(`${CONSOLE_PREFIX}${payload}`);
|
|
525
|
-
if (process.env.LMNR_DEBUG_WRITE_LAST_RUN_TO_FILE) writePointerFile(payload);
|
|
520
|
+
const findDebugSessionDir = (startDir = process.cwd()) => {
|
|
521
|
+
let dir = (0, node_path.resolve)(startDir);
|
|
522
|
+
const root = (0, node_path.parse)(dir).root;
|
|
523
|
+
while (true) {
|
|
524
|
+
if (readDebugSessionFile(dir) !== null) return dir;
|
|
525
|
+
const parent = (0, node_path.dirname)(dir);
|
|
526
|
+
if (parent === dir || dir === root) return null;
|
|
527
|
+
dir = parent;
|
|
528
|
+
}
|
|
526
529
|
};
|
|
527
|
-
|
|
530
|
+
/**
|
|
531
|
+
* The directory the debug-session file should be read from AND written to: the
|
|
532
|
+
* nearest ancestor (incl. `startDir`) that already has one, else `startDir`
|
|
533
|
+
* itself. Read and write MUST share this anchor — reading from an ancestor but
|
|
534
|
+
* writing to cwd would strand the ancestor's copy stale and shadow it with a
|
|
535
|
+
* nested one.
|
|
536
|
+
*/
|
|
537
|
+
const resolveDebugSessionDir = (startDir = process.cwd()) => findDebugSessionDir(startDir) ?? (0, node_path.resolve)(startDir);
|
|
538
|
+
/**
|
|
539
|
+
* Write the debug-session file (mkdir -p first). Best-effort: swallows any IO
|
|
540
|
+
* error so a read-only working directory never breaks a run.
|
|
541
|
+
*/
|
|
542
|
+
const writeDebugSessionFile = (file, dir = process.cwd()) => {
|
|
528
543
|
try {
|
|
529
|
-
const directory = (0, node_path.join)(
|
|
544
|
+
const directory = (0, node_path.join)(dir, require_dist.DEBUG_SESSION_DIR);
|
|
530
545
|
(0, node_fs.mkdirSync)(directory, { recursive: true });
|
|
531
|
-
(0, node_fs.writeFileSync)((0, node_path.join)(directory,
|
|
532
|
-
|
|
533
|
-
|
|
546
|
+
(0, node_fs.writeFileSync)((0, node_path.join)(directory, require_dist.DEBUG_SESSION_FILE), JSON.stringify(file), "utf-8");
|
|
547
|
+
return true;
|
|
548
|
+
} catch {
|
|
549
|
+
return false;
|
|
534
550
|
}
|
|
535
551
|
};
|
|
536
552
|
//#endregion
|
|
@@ -543,7 +559,7 @@ const writePointerFile = (payload) => {
|
|
|
543
559
|
* contract. This file is part of the cross-language parity surface — keep its
|
|
544
560
|
* logic line-comparable with the Python `config.py`.
|
|
545
561
|
*/
|
|
546
|
-
const logger$
|
|
562
|
+
const logger$22 = require_dist.initializeLogger();
|
|
547
563
|
const TRUTHY = new Set([
|
|
548
564
|
"true",
|
|
549
565
|
"1",
|
|
@@ -579,27 +595,10 @@ const parseCacheUntil = (value) => {
|
|
|
579
595
|
if (value === void 0 || value === "") return null;
|
|
580
596
|
const spanId = normalizeSpanId(value);
|
|
581
597
|
if (spanId !== null) return spanId;
|
|
582
|
-
logger$
|
|
598
|
+
logger$22.warn(`LMNR_DEBUG_CACHE_UNTIL=${JSON.stringify(value)} is not a span id; ignoring`);
|
|
583
599
|
return null;
|
|
584
600
|
};
|
|
585
601
|
/**
|
|
586
|
-
* Read `${CWD}/.lmnr/last-run.json` (the previous run's pointer).
|
|
587
|
-
*
|
|
588
|
-
* Best-effort: a missing / unreadable / malformed file returns {} so the caller
|
|
589
|
-
* silently falls back to env vars. Keep line-comparable with the Python
|
|
590
|
-
* `_load_last_run`.
|
|
591
|
-
*/
|
|
592
|
-
const loadLastRun = () => {
|
|
593
|
-
try {
|
|
594
|
-
const path = (0, node_path.join)(process.cwd(), POINTER_DIR, POINTER_FILE);
|
|
595
|
-
const data = JSON.parse((0, node_fs.readFileSync)(path, { encoding: "utf-8" }));
|
|
596
|
-
return data !== null && typeof data === "object" ? data : {};
|
|
597
|
-
} catch (e) {
|
|
598
|
-
logger$21.debug(`Could not read debug pointer file: ${String(e)}`);
|
|
599
|
-
return {};
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
/**
|
|
603
602
|
* True when both a replay trace and a cache-until span id are set, i.e. at least
|
|
604
603
|
* one call should consult the cache. The server resolves the span-id window, so
|
|
605
604
|
* the SDK only needs both ids present to arm replay.
|
|
@@ -611,25 +610,32 @@ const replayEnabledForConfig = (config) => config.replayTraceId !== null && conf
|
|
|
611
610
|
* Returns null when debug mode is disabled (LMNR_DEBUG falsey/absent) — the
|
|
612
611
|
* caller treats null as "everything inert".
|
|
613
612
|
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
613
|
+
* The `.lmnr/debug-session.json` file is now DEFAULT-ON: it is read
|
|
614
|
+
* unconditionally (no opt-in env gate). The decision tree:
|
|
615
|
+
*
|
|
616
|
+
* 1. Read the file (best-effort → `existing | null`).
|
|
617
|
+
* 2. `sessionId` precedence: `LMNR_DEBUG_SESSION_ID` → `existing.session_id` →
|
|
618
|
+
* a freshly-minted UUID.
|
|
619
|
+
* 3. `sessionMinted` is true ONLY when we minted (neither env nor file supplied
|
|
620
|
+
* a session id). A file-present run is a CONTINUATION: it rejoins the same
|
|
621
|
+
* session silently (no browser).
|
|
622
|
+
* 4. `replayTraceId`: `LMNR_DEBUG_REPLAY_TRACE_ID` → `existing.replay_trace_id`
|
|
623
|
+
* → null. NOTE: continuation is NOT auto-replay — we do NOT promote the prior
|
|
624
|
+
* run's `trace_id` into `replayTraceId`. Replay is armed explicitly by the
|
|
625
|
+
* agent via the env var or the file's `replay_trace_id`.
|
|
626
|
+
* 5. `cacheUntilSpanId`: parsed from `LMNR_DEBUG_CACHE_UNTIL ??
|
|
627
|
+
* existing.cache_until`.
|
|
620
628
|
*/
|
|
621
629
|
const buildDebugConfig = () => {
|
|
622
630
|
if (!isTruthy(process.env.LMNR_DEBUG)) return null;
|
|
623
|
-
const
|
|
624
|
-
const providedSessionId = process.env.LMNR_DEBUG_SESSION_ID ||
|
|
631
|
+
const existing = readDebugSessionFile(resolveDebugSessionDir());
|
|
632
|
+
const providedSessionId = process.env.LMNR_DEBUG_SESSION_ID || existing?.session_id || void 0;
|
|
625
633
|
const sessionId = providedSessionId || (0, node_crypto.randomUUID)();
|
|
626
|
-
const sessionMinted = providedSessionId === void 0
|
|
627
|
-
const replayTraceId = process.env.LMNR_DEBUG_REPLAY_TRACE_ID || lastRun.trace_id || null;
|
|
628
|
-
const lastRunCacheUntil = typeof lastRun.cache_until === "string" ? lastRun.cache_until : void 0;
|
|
634
|
+
const sessionMinted = providedSessionId === void 0;
|
|
629
635
|
return {
|
|
630
636
|
sessionId,
|
|
631
|
-
replayTraceId,
|
|
632
|
-
cacheUntilSpanId: parseCacheUntil(process.env.LMNR_DEBUG_CACHE_UNTIL ??
|
|
637
|
+
replayTraceId: process.env.LMNR_DEBUG_REPLAY_TRACE_ID || existing?.replay_trace_id || null,
|
|
638
|
+
cacheUntilSpanId: parseCacheUntil(process.env.LMNR_DEBUG_CACHE_UNTIL ?? existing?.cache_until ?? void 0),
|
|
633
639
|
localOrigin: true,
|
|
634
640
|
sessionMinted
|
|
635
641
|
};
|
|
@@ -662,6 +668,46 @@ const buildDebugConfigFromContext = (debug) => {
|
|
|
662
668
|
};
|
|
663
669
|
};
|
|
664
670
|
//#endregion
|
|
671
|
+
//#region src/debug/pointer.ts
|
|
672
|
+
const CONSOLE_PREFIX = "LMNR_DEBUG_RUN ";
|
|
673
|
+
/**
|
|
674
|
+
* Build the persisted debug-session record.
|
|
675
|
+
*
|
|
676
|
+
* `startedAt` is the run's start time, captured by `DebugRuntime` at SDK init so
|
|
677
|
+
* the record reflects when tracing began rather than when it was emitted
|
|
678
|
+
* (shutdown). Defaults to now for standalone callers.
|
|
679
|
+
*/
|
|
680
|
+
const buildDebugSessionFile = (args) => ({
|
|
681
|
+
session_id: args.sessionId,
|
|
682
|
+
trace_id: args.traceId,
|
|
683
|
+
replay_trace_id: args.replayTraceId,
|
|
684
|
+
cache_until: args.cacheUntil,
|
|
685
|
+
debugger_url: args.debuggerUrl,
|
|
686
|
+
started_at: args.startedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
687
|
+
});
|
|
688
|
+
/**
|
|
689
|
+
* Print the console line, then best-effort write the debug-session file.
|
|
690
|
+
*
|
|
691
|
+
* The pointer is emitted at shutdown (via the `exit` hook / `Laminar.shutdown()`),
|
|
692
|
+
* which can be long after the run started. If a newer session was minted in the
|
|
693
|
+
* meantime — e.g. `lmnr-cli debug session new` reset `.lmnr/debug-session.json`
|
|
694
|
+
* while this (older) process was still running — blindly writing our in-memory
|
|
695
|
+
* session would clobber that fresher session id. So skip the file write when the
|
|
696
|
+
* on-disk `session_id` is present and differs from ours; we no longer own the
|
|
697
|
+
* file. The console marker is always printed regardless.
|
|
698
|
+
*
|
|
699
|
+
* The file location is the nearest-ancestor anchor (`resolveDebugSessionDir`),
|
|
700
|
+
* matching where startup (`config.ts`) read the session from — the guard's
|
|
701
|
+
* re-read and the write must hit the SAME file or the guard is meaningless.
|
|
702
|
+
*/
|
|
703
|
+
const emitPointer = (file) => {
|
|
704
|
+
console.log(`${CONSOLE_PREFIX}${JSON.stringify(file)}`);
|
|
705
|
+
const dir = resolveDebugSessionDir();
|
|
706
|
+
const onDisk = readDebugSessionFile(dir);
|
|
707
|
+
if (onDisk !== null && onDisk.session_id !== file.session_id) return;
|
|
708
|
+
writeDebugSessionFile(file, dir);
|
|
709
|
+
};
|
|
710
|
+
//#endregion
|
|
665
711
|
//#region src/debug/index.ts
|
|
666
712
|
/**
|
|
667
713
|
* Holds the immutable debug config plus the handle used to look up the
|
|
@@ -797,21 +843,22 @@ var DebugRuntime = class {
|
|
|
797
843
|
return `${this._debuggerUrl}/project/${this._projectId}/debugger-sessions/${this._config.sessionId}`;
|
|
798
844
|
}
|
|
799
845
|
/**
|
|
800
|
-
* Emit the
|
|
846
|
+
* Emit the debug-session record once (console line + best-effort file write
|
|
847
|
+
* to `.lmnr/debug-session.json`).
|
|
801
848
|
*
|
|
802
849
|
* No-op on a downstream run (`localOrigin: false`): a runtime armed from a
|
|
803
850
|
* propagated `DebugContext` joins the upstream replay session and must NOT
|
|
804
|
-
*
|
|
805
|
-
* sites) so `shutdown()` and any exit hook stay safe. Mirrors Python's
|
|
851
|
+
* own/overwrite the file — the origin owns it. Gated here (not just at the
|
|
852
|
+
* call sites) so `shutdown()` and any exit hook stay safe. Mirrors Python's
|
|
806
853
|
* `emit_pointer`.
|
|
807
854
|
*/
|
|
808
855
|
emitPointer() {
|
|
809
856
|
if (!this._config.localOrigin) return;
|
|
810
857
|
if (this._emitted) return;
|
|
811
858
|
this._emitted = true;
|
|
812
|
-
emitPointer(
|
|
813
|
-
traceId: this._traceId ?? "",
|
|
859
|
+
emitPointer(buildDebugSessionFile({
|
|
814
860
|
sessionId: this._config.sessionId,
|
|
861
|
+
traceId: this._traceId,
|
|
815
862
|
replayTraceId: this._config.replayTraceId,
|
|
816
863
|
cacheUntil: this._config.cacheUntilSpanId,
|
|
817
864
|
debuggerUrl: this.debuggerSessionUrl(),
|
|
@@ -899,7 +946,7 @@ const resetDebugRuntime = () => {
|
|
|
899
946
|
};
|
|
900
947
|
//#endregion
|
|
901
948
|
//#region src/opentelemetry-lib/tracing/span.ts
|
|
902
|
-
const logger$
|
|
949
|
+
const logger$21 = require_dist.initializeLogger();
|
|
903
950
|
/**
|
|
904
951
|
* Build the debug block to propagate, or undefined when debug mode is off.
|
|
905
952
|
*
|
|
@@ -1004,24 +1051,24 @@ var LaminarSpan = class LaminarSpan {
|
|
|
1004
1051
|
return this._span.recordException(exception, time);
|
|
1005
1052
|
}
|
|
1006
1053
|
setTraceSessionId(sessionId) {
|
|
1007
|
-
this._span.setAttribute(
|
|
1054
|
+
this._span.setAttribute(require_dist.SESSION_ID, sessionId);
|
|
1008
1055
|
}
|
|
1009
1056
|
setTraceUserId(userId) {
|
|
1010
|
-
this._span.setAttribute(
|
|
1057
|
+
this._span.setAttribute(require_dist.USER_ID, userId);
|
|
1011
1058
|
}
|
|
1012
1059
|
setTraceMetadata(metadata) {
|
|
1013
|
-
this._span.setAttributes(
|
|
1060
|
+
this._span.setAttributes(require_dist.metadataToAttributes(metadata));
|
|
1014
1061
|
}
|
|
1015
1062
|
setInput(input) {
|
|
1016
1063
|
const finalInput = typeof input === "string" ? input : JSON.stringify(input);
|
|
1017
|
-
this._span.setAttribute(
|
|
1064
|
+
this._span.setAttribute(require_dist.SPAN_INPUT, finalInput);
|
|
1018
1065
|
}
|
|
1019
1066
|
setOutput(output) {
|
|
1020
1067
|
const finalOutput = typeof output === "string" ? output : JSON.stringify(output);
|
|
1021
|
-
this._span.setAttribute(
|
|
1068
|
+
this._span.setAttribute(require_dist.SPAN_OUTPUT, finalOutput);
|
|
1022
1069
|
}
|
|
1023
1070
|
setTags(tags) {
|
|
1024
|
-
this._span.setAttribute(`${
|
|
1071
|
+
this._span.setAttribute(`${require_dist.ASSOCIATION_PROPERTIES}.tags`, Array.from(new Set(tags)));
|
|
1025
1072
|
}
|
|
1026
1073
|
addTags(tags) {
|
|
1027
1074
|
const currentTags = this.tags;
|
|
@@ -1033,26 +1080,26 @@ var LaminarSpan = class LaminarSpan {
|
|
|
1033
1080
|
let userId;
|
|
1034
1081
|
let sessionId;
|
|
1035
1082
|
let traceType;
|
|
1036
|
-
let tracingLevel =
|
|
1083
|
+
let tracingLevel = require_dist.TracingLevel.ALL;
|
|
1037
1084
|
const metadata = {};
|
|
1038
1085
|
if (this._span.attributes) {
|
|
1039
|
-
spanPath = this._span.attributes[
|
|
1040
|
-
spanIdsPath = this._span.attributes[
|
|
1041
|
-
userId = this._span.attributes[
|
|
1042
|
-
sessionId = this._span.attributes[
|
|
1043
|
-
traceType = this._span.attributes[
|
|
1044
|
-
tracingLevel = this._span.attributes[`lmnr.association.properties.tracing_level`] ??
|
|
1086
|
+
spanPath = this._span.attributes[require_dist.SPAN_PATH];
|
|
1087
|
+
spanIdsPath = this._span.attributes[require_dist.SPAN_IDS_PATH];
|
|
1088
|
+
userId = this._span.attributes[require_dist.USER_ID];
|
|
1089
|
+
sessionId = this._span.attributes[require_dist.SESSION_ID];
|
|
1090
|
+
traceType = this._span.attributes[require_dist.TRACE_TYPE];
|
|
1091
|
+
tracingLevel = this._span.attributes[`lmnr.association.properties.tracing_level`] ?? require_dist.TracingLevel.ALL;
|
|
1045
1092
|
for (const [key, rawValue] of Object.entries(this._span.attributes)) if (key.startsWith(`lmnr.association.properties.metadata.`)) {
|
|
1046
1093
|
let value = rawValue;
|
|
1047
1094
|
try {
|
|
1048
1095
|
value = JSON.parse(value);
|
|
1049
1096
|
} catch {}
|
|
1050
|
-
metadata[key.replace(`${
|
|
1097
|
+
metadata[key.replace(`${require_dist.ASSOCIATION_PROPERTIES}.metadata.`, "")] = value;
|
|
1051
1098
|
}
|
|
1052
|
-
} else logger$
|
|
1099
|
+
} else logger$21.warn("Attributes object is not available. Most likely the span is not a LaminarSpan and not an OpenTelemetry default SDK Span. Span path and ids path will be empty.");
|
|
1053
1100
|
return {
|
|
1054
|
-
spanId:
|
|
1055
|
-
traceId:
|
|
1101
|
+
spanId: require_dist.otelSpanIdToUUID(this._span.spanContext().spanId),
|
|
1102
|
+
traceId: require_dist.otelTraceIdToUUID(this._span.spanContext().traceId),
|
|
1056
1103
|
isRemote: this._span.spanContext().isRemote ?? false,
|
|
1057
1104
|
spanPath,
|
|
1058
1105
|
spanIdsPath,
|
|
@@ -1067,23 +1114,23 @@ var LaminarSpan = class LaminarSpan {
|
|
|
1067
1114
|
spanId(format = "otel") {
|
|
1068
1115
|
const spanId = this._span.spanContext().spanId;
|
|
1069
1116
|
if (format === "otel") return spanId;
|
|
1070
|
-
return
|
|
1117
|
+
return require_dist.otelSpanIdToUUID(spanId);
|
|
1071
1118
|
}
|
|
1072
1119
|
traceId(format = "otel") {
|
|
1073
1120
|
const traceId = this._span.spanContext().traceId;
|
|
1074
1121
|
if (format === "otel") return traceId;
|
|
1075
|
-
return
|
|
1122
|
+
return require_dist.otelTraceIdToUUID(traceId);
|
|
1076
1123
|
}
|
|
1077
1124
|
get tags() {
|
|
1078
1125
|
if (!this._span.attributes) {
|
|
1079
|
-
logger$
|
|
1126
|
+
logger$21.warn("[LaminarSpan.tags] WARNING. Current span does not have attributes object. Possibly, the span was created with a custom OTel SDK. Returning an empty list. Help: OpenTelemetry API does not guarantee reading attributes from a span, but OTel SDK allows it by default. Laminar SDK allows to read attributes too.");
|
|
1080
1127
|
return [];
|
|
1081
1128
|
}
|
|
1082
1129
|
return this._span.attributes[`lmnr.association.properties.tags`] ?? [];
|
|
1083
1130
|
}
|
|
1084
1131
|
get laminarAssociationProperties() {
|
|
1085
1132
|
if (!this._span.attributes) {
|
|
1086
|
-
logger$
|
|
1133
|
+
logger$21.warn("[LaminarSpan.laminarAssociationProperties] WARNING. Current span does not have attributes object. Possibly, the span was created with a custom OTel SDK. Returning an empty object. Help: OpenTelemetry API does not guarantee reading attributes from a span, but OTel SDK allows it by default. Laminar SDK allows to read attributes too.");
|
|
1087
1134
|
return {};
|
|
1088
1135
|
}
|
|
1089
1136
|
try {
|
|
@@ -1093,14 +1140,14 @@ var LaminarSpan = class LaminarSpan {
|
|
|
1093
1140
|
if (!key.startsWith(`lmnr.association.properties.`)) continue;
|
|
1094
1141
|
let value = rawValue;
|
|
1095
1142
|
if (key.startsWith(`lmnr.association.properties.metadata.`)) {
|
|
1096
|
-
const metaKey = key.replace(`${
|
|
1143
|
+
const metaKey = key.replace(`${require_dist.ASSOCIATION_PROPERTIES}.metadata.`, "");
|
|
1097
1144
|
try {
|
|
1098
1145
|
value = JSON.parse(value);
|
|
1099
1146
|
} catch {}
|
|
1100
1147
|
metadata[metaKey] = value;
|
|
1101
1148
|
}
|
|
1102
1149
|
}
|
|
1103
|
-
properties.tracingLevel = this._span.attributes[`lmnr.association.properties.tracing_level`] ??
|
|
1150
|
+
properties.tracingLevel = this._span.attributes[`lmnr.association.properties.tracing_level`] ?? require_dist.TracingLevel.ALL;
|
|
1104
1151
|
properties.userId = this._span.attributes["lmnr.association.properties.user_id"] ?? void 0;
|
|
1105
1152
|
properties.sessionId = this._span.attributes["lmnr.association.properties.session_id"] ?? void 0;
|
|
1106
1153
|
properties.traceType = this._span.attributes["lmnr.association.properties.trace_type"] ?? void 0;
|
|
@@ -1279,7 +1326,7 @@ var LaminarContextManager = class {
|
|
|
1279
1326
|
};
|
|
1280
1327
|
//#endregion
|
|
1281
1328
|
//#region src/opentelemetry-lib/instrumentation/claude-agent-sdk/proxy.ts
|
|
1282
|
-
const logger$
|
|
1329
|
+
const logger$20 = require_dist.initializeLogger();
|
|
1283
1330
|
const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com";
|
|
1284
1331
|
const DEFAULT_CC_PROXY_PORT = 45667;
|
|
1285
1332
|
const CC_PROXY_PORT_ATTEMPTS = 50;
|
|
@@ -1352,7 +1399,7 @@ const resolveTargetUrlFromEnv = (envDict, fallback = DEFAULT_ANTHROPIC_BASE_URL)
|
|
|
1352
1399
|
if (foundryBaseUrl) return foundryBaseUrl.replace(/\/$/, "");
|
|
1353
1400
|
const foundryResource = getEnvValue(FOUNDRY_RESOURCE_ENV);
|
|
1354
1401
|
if (foundryResource) return `https://${foundryResource}.services.ai.azure.com/anthropic`;
|
|
1355
|
-
logger$
|
|
1402
|
+
logger$20.error(`${FOUNDRY_USE_ENV} is set but neither ${FOUNDRY_BASE_URL_ENV} nor ${FOUNDRY_RESOURCE_ENV} is configured. Microsoft Foundry requires one of these values.`);
|
|
1356
1403
|
return null;
|
|
1357
1404
|
}
|
|
1358
1405
|
if (isTruthyEnv(getEnvValue(BEDROCK_USE_ENV))) {
|
|
@@ -1361,7 +1408,7 @@ const resolveTargetUrlFromEnv = (envDict, fallback = DEFAULT_ANTHROPIC_BASE_URL)
|
|
|
1361
1408
|
let region = getEnvValue(BEDROCK_AWS_REGION_ENV);
|
|
1362
1409
|
if (!region) region = getRegionFromAwsConfig(getEnvValue("AWS_PROFILE") || "default") ?? void 0;
|
|
1363
1410
|
if (region) return `https://bedrock-runtime.${region}.amazonaws.com`;
|
|
1364
|
-
logger$
|
|
1411
|
+
logger$20.error(`${BEDROCK_USE_ENV} is set but could not determine AWS region. Set ${BEDROCK_AWS_REGION_ENV} or configure a region in ~/.aws/config for the active profile.`);
|
|
1365
1412
|
return null;
|
|
1366
1413
|
}
|
|
1367
1414
|
if (isTruthyEnv(getEnvValue(VERTEX_USE_ENV))) {
|
|
@@ -1443,11 +1490,11 @@ const waitForPort = (port, timeoutMs = 5e3) => new Promise((resolve) => {
|
|
|
1443
1490
|
const registerGlobalProxyShutdown = () => {
|
|
1444
1491
|
if (!globalShutdownRegistered) {
|
|
1445
1492
|
process.on("exit", () => {
|
|
1446
|
-
logger$
|
|
1493
|
+
logger$20.debug("process.on(\"exit\") called - stopping all active proxies");
|
|
1447
1494
|
for (const proxyServer of activeProxyServers) try {
|
|
1448
1495
|
proxyServer.stopServer();
|
|
1449
1496
|
} catch (e) {
|
|
1450
|
-
logger$
|
|
1497
|
+
logger$20.debug(`Failed to stop proxy: ${require_dist.errorMessage(e)}`);
|
|
1451
1498
|
}
|
|
1452
1499
|
activeProxyServers.clear();
|
|
1453
1500
|
});
|
|
@@ -1462,28 +1509,28 @@ const createProxyInstance = async ({ env }) => {
|
|
|
1462
1509
|
try {
|
|
1463
1510
|
const port = await findAvailablePort(DEFAULT_CC_PROXY_PORT, CC_PROXY_PORT_ATTEMPTS);
|
|
1464
1511
|
if (port === null) {
|
|
1465
|
-
logger$
|
|
1512
|
+
logger$20.warn("Unable to allocate port for cc-proxy.");
|
|
1466
1513
|
return null;
|
|
1467
1514
|
}
|
|
1468
1515
|
const targetUrl = resolveTargetUrlFromEnv(env);
|
|
1469
1516
|
if (!targetUrl) {
|
|
1470
|
-
logger$
|
|
1517
|
+
logger$20.warn("Unable to resolve target URL for cc-proxy (provider misconfigured).");
|
|
1471
1518
|
return null;
|
|
1472
1519
|
}
|
|
1473
|
-
logger$
|
|
1520
|
+
logger$20.debug(`Creating proxy instance on port ${port} targeting: ${targetUrl}`);
|
|
1474
1521
|
try {
|
|
1475
1522
|
const { ProxyServer } = require("@lmnr-ai/claude-code-proxy");
|
|
1476
1523
|
const proxyServer = new ProxyServer(port);
|
|
1477
1524
|
proxyServer.runServer(targetUrl);
|
|
1478
1525
|
if (!await waitForPort(port)) {
|
|
1479
|
-
logger$
|
|
1526
|
+
logger$20.warn(`cc-proxy failed to start on port ${port}`);
|
|
1480
1527
|
proxyServer.stopServer();
|
|
1481
1528
|
return null;
|
|
1482
1529
|
}
|
|
1483
1530
|
const proxyBaseUrl = `http://127.0.0.1:${port}`;
|
|
1484
1531
|
activeProxyServers.add(proxyServer);
|
|
1485
1532
|
registerGlobalProxyShutdown();
|
|
1486
|
-
logger$
|
|
1533
|
+
logger$20.info(`Started claude proxy server on: ${proxyBaseUrl}`);
|
|
1487
1534
|
return {
|
|
1488
1535
|
server: proxyServer,
|
|
1489
1536
|
baseUrl: proxyBaseUrl,
|
|
@@ -1491,11 +1538,11 @@ const createProxyInstance = async ({ env }) => {
|
|
|
1491
1538
|
targetUrl
|
|
1492
1539
|
};
|
|
1493
1540
|
} catch (e) {
|
|
1494
|
-
logger$
|
|
1541
|
+
logger$20.warn(`Unable to start cc-proxy: ${require_dist.errorMessage(e)}`);
|
|
1495
1542
|
return null;
|
|
1496
1543
|
}
|
|
1497
1544
|
} catch (e) {
|
|
1498
|
-
logger$
|
|
1545
|
+
logger$20.warn(`Failed to create proxy instance: ${require_dist.errorMessage(e)}`);
|
|
1499
1546
|
return null;
|
|
1500
1547
|
}
|
|
1501
1548
|
};
|
|
@@ -1505,11 +1552,11 @@ const createProxyInstance = async ({ env }) => {
|
|
|
1505
1552
|
const stopProxyInstance = (instance) => {
|
|
1506
1553
|
if (!instance) return;
|
|
1507
1554
|
try {
|
|
1508
|
-
logger$
|
|
1555
|
+
logger$20.debug(`Stopping proxy instance on port ${instance.port}`);
|
|
1509
1556
|
instance.server.stopServer();
|
|
1510
1557
|
activeProxyServers.delete(instance.server);
|
|
1511
1558
|
} catch (e) {
|
|
1512
|
-
logger$
|
|
1559
|
+
logger$20.debug(`Failed to stop proxy instance: ${require_dist.errorMessage(e)}`);
|
|
1513
1560
|
}
|
|
1514
1561
|
};
|
|
1515
1562
|
/**
|
|
@@ -1517,11 +1564,11 @@ const stopProxyInstance = (instance) => {
|
|
|
1517
1564
|
* Used during shutdown to ensure cleanup
|
|
1518
1565
|
*/
|
|
1519
1566
|
const forceReleaseProxy = () => {
|
|
1520
|
-
logger$
|
|
1567
|
+
logger$20.debug(`Force stopping all ${activeProxyServers.size} active proxy servers`);
|
|
1521
1568
|
for (const proxyServer of activeProxyServers) try {
|
|
1522
1569
|
proxyServer.stopServer();
|
|
1523
1570
|
} catch (e) {
|
|
1524
|
-
logger$
|
|
1571
|
+
logger$20.debug(`Failed to stop proxy: ${require_dist.errorMessage(e)}`);
|
|
1525
1572
|
}
|
|
1526
1573
|
activeProxyServers.clear();
|
|
1527
1574
|
};
|
|
@@ -1538,8 +1585,8 @@ const getSpanContextPayload = () => {
|
|
|
1538
1585
|
try {
|
|
1539
1586
|
const readableSpan = currentSpan;
|
|
1540
1587
|
if (readableSpan.attributes) {
|
|
1541
|
-
const idsPath = readableSpan.attributes[
|
|
1542
|
-
const path$1 = readableSpan.attributes[
|
|
1588
|
+
const idsPath = readableSpan.attributes[require_dist.SPAN_IDS_PATH];
|
|
1589
|
+
const path$1 = readableSpan.attributes[require_dist.SPAN_PATH];
|
|
1543
1590
|
if (Array.isArray(idsPath)) spanIdsPath = idsPath;
|
|
1544
1591
|
if (Array.isArray(path$1)) spanPath = path$1;
|
|
1545
1592
|
}
|
|
@@ -1571,14 +1618,14 @@ const setTraceToProxyInstance = async (instance) => {
|
|
|
1571
1618
|
spanPath: payload.span_path,
|
|
1572
1619
|
laminarUrl: payload.laminar_url
|
|
1573
1620
|
});
|
|
1574
|
-
logger$
|
|
1621
|
+
logger$20.debug(`Set trace context to proxy on port ${instance.port}`);
|
|
1575
1622
|
} catch (e) {
|
|
1576
|
-
logger$
|
|
1623
|
+
logger$20.debug(`Unable to set trace context to proxy on port ${instance.port}: ` + require_dist.errorMessage(e));
|
|
1577
1624
|
}
|
|
1578
1625
|
};
|
|
1579
1626
|
//#endregion
|
|
1580
1627
|
//#region src/opentelemetry-lib/instrumentation/claude-agent-sdk/index.ts
|
|
1581
|
-
const logger$
|
|
1628
|
+
const logger$19 = require_dist.initializeLogger();
|
|
1582
1629
|
/**
|
|
1583
1630
|
* Create an instrumented version of the claude-agent-sdk query function.
|
|
1584
1631
|
* This can be used when importing the query function before Laminar initialization.
|
|
@@ -1593,7 +1640,7 @@ function instrumentClaudeAgentQuery(originalQuery) {
|
|
|
1593
1640
|
name: "query",
|
|
1594
1641
|
spanType: "DEFAULT"
|
|
1595
1642
|
});
|
|
1596
|
-
span.setAttribute(
|
|
1643
|
+
span.setAttribute(require_dist.SPAN_INPUT, JSON.stringify({ prompt: typeof params.prompt === "string" ? params.prompt : "<stream>" }));
|
|
1597
1644
|
const generator = async function* () {
|
|
1598
1645
|
const collected = [];
|
|
1599
1646
|
let proxyInstance = null;
|
|
@@ -1605,9 +1652,9 @@ function instrumentClaudeAgentQuery(originalQuery) {
|
|
|
1605
1652
|
const targetUrl = resolveTargetUrlFromEnv(mergedEnv);
|
|
1606
1653
|
proxyInstance = await createProxyInstance({ env: mergedEnv });
|
|
1607
1654
|
if (proxyInstance && targetUrl) {
|
|
1608
|
-
logger$
|
|
1655
|
+
logger$19.debug(`Using proxy on port ${proxyInstance.port}`);
|
|
1609
1656
|
await Laminar.withSpan(span, async () => {
|
|
1610
|
-
logger$
|
|
1657
|
+
logger$19.debug("Setting trace to proxy instance...");
|
|
1611
1658
|
await setTraceToProxyInstance(proxyInstance);
|
|
1612
1659
|
});
|
|
1613
1660
|
const varsToRemove = getEnvVarsToRemove(mergedEnv);
|
|
@@ -1620,7 +1667,7 @@ function instrumentClaudeAgentQuery(originalQuery) {
|
|
|
1620
1667
|
if (params.options.env.CLAUDE_CODE_USE_FOUNDRY === "1") params.options.env.ANTHROPIC_FOUNDRY_BASE_URL = proxyInstance.baseUrl;
|
|
1621
1668
|
if (params.options.env.CLAUDE_CODE_USE_BEDROCK === "1") params.options.env.ANTHROPIC_BEDROCK_BASE_URL = proxyInstance.baseUrl;
|
|
1622
1669
|
if (params.options.env.CLAUDE_CODE_USE_VERTEX === "1") params.options.env.ANTHROPIC_VERTEX_BASE_URL = proxyInstance.baseUrl;
|
|
1623
|
-
} else logger$
|
|
1670
|
+
} else logger$19.debug("No claude proxy server available. Proceeding without proxy.");
|
|
1624
1671
|
const originalGenerator = originalQuery(params);
|
|
1625
1672
|
for await (const message of originalGenerator) {
|
|
1626
1673
|
collected.push(message);
|
|
@@ -1633,7 +1680,7 @@ function instrumentClaudeAgentQuery(originalQuery) {
|
|
|
1633
1680
|
throw error;
|
|
1634
1681
|
} finally {
|
|
1635
1682
|
stopProxyInstance(proxyInstance);
|
|
1636
|
-
span.setAttribute(
|
|
1683
|
+
span.setAttribute(require_dist.SPAN_OUTPUT, JSON.stringify(collected));
|
|
1637
1684
|
span.end();
|
|
1638
1685
|
}
|
|
1639
1686
|
};
|
|
@@ -1649,7 +1696,7 @@ var ClaudeAgentSDKInstrumentation = class extends _opentelemetry_instrumentation
|
|
|
1649
1696
|
}
|
|
1650
1697
|
manuallyInstrument(claudeAgentModule) {
|
|
1651
1698
|
if (claudeAgentModule.query && typeof claudeAgentModule.query === "function") this._wrap(claudeAgentModule, "query", this.patchQuery());
|
|
1652
|
-
else logger$
|
|
1699
|
+
else logger$19.debug("query function not found in claudeAgentSDK module, skipping instrumentation");
|
|
1653
1700
|
}
|
|
1654
1701
|
patchQuery() {
|
|
1655
1702
|
return (original) => instrumentClaudeAgentQuery(original);
|
|
@@ -1666,8 +1713,8 @@ var ClaudeAgentSDKInstrumentation = class extends _opentelemetry_instrumentation
|
|
|
1666
1713
|
};
|
|
1667
1714
|
//#endregion
|
|
1668
1715
|
//#region src/laminar.ts
|
|
1669
|
-
|
|
1670
|
-
const logger$
|
|
1716
|
+
require_dist.loadEnv();
|
|
1717
|
+
const logger$18 = require_dist.initializeLogger();
|
|
1671
1718
|
var Laminar = class Laminar {
|
|
1672
1719
|
static {
|
|
1673
1720
|
this.isInitialized = false;
|
|
@@ -1753,11 +1800,11 @@ var Laminar = class Laminar {
|
|
|
1753
1800
|
*/
|
|
1754
1801
|
static initialize({ projectApiKey, baseUrl, baseHttpUrl, httpPort, grpcPort, instrumentModules, disableBatch, traceExportTimeoutMillis, logLevel, maxExportBatchSize, forceHttp, sessionRecordingOptions, metadata, inheritGlobalContext, spanProcessor } = {}) {
|
|
1755
1802
|
if (this.isInitialized) {
|
|
1756
|
-
logger$
|
|
1803
|
+
logger$18.warn("Laminar has already been initialized. Skipping initialization.");
|
|
1757
1804
|
return;
|
|
1758
1805
|
}
|
|
1759
1806
|
const key = projectApiKey ?? process?.env?.LMNR_PROJECT_API_KEY;
|
|
1760
|
-
|
|
1807
|
+
require_dist.validateTracingConfig(key);
|
|
1761
1808
|
this.projectApiKey = key ?? "";
|
|
1762
1809
|
let url = baseUrl ?? process?.env?.LMNR_BASE_URL;
|
|
1763
1810
|
if (key && !url) url = "https://api.lmnr.ai";
|
|
@@ -1777,7 +1824,7 @@ var Laminar = class Laminar {
|
|
|
1777
1824
|
...metadata ?? {}
|
|
1778
1825
|
};
|
|
1779
1826
|
if (inheritGlobalContext) LaminarContextManager.inheritGlobalContext = true;
|
|
1780
|
-
if (spanProcessor && !(spanProcessor instanceof LaminarSpanProcessor)) logger$
|
|
1827
|
+
if (spanProcessor && !(spanProcessor instanceof LaminarSpanProcessor)) logger$18.warn("Span processor is not a LaminarSpanProcessor. Some functionality may be impaired.");
|
|
1781
1828
|
this.isInitialized = true;
|
|
1782
1829
|
const urlWithoutSlash = url?.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
|
|
1783
1830
|
const httpUrlWithoutSlash = httpUrl?.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
|
|
@@ -1810,9 +1857,9 @@ var Laminar = class Laminar {
|
|
|
1810
1857
|
const envContext = process?.env?.LMNR_SPAN_CONTEXT;
|
|
1811
1858
|
if (!envContext) return;
|
|
1812
1859
|
try {
|
|
1813
|
-
const laminarContext =
|
|
1860
|
+
const laminarContext = require_dist.deserializeLaminarSpanContext(envContext);
|
|
1814
1861
|
this._armDebugRuntimeFromContext(laminarContext.debug);
|
|
1815
|
-
const otelSpanContext =
|
|
1862
|
+
const otelSpanContext = require_dist.tryToOtelSpanContext(laminarContext);
|
|
1816
1863
|
otelSpanContext.isRemote = true;
|
|
1817
1864
|
const processor = getSpanProcessor();
|
|
1818
1865
|
if (processor && processor instanceof LaminarSpanProcessor && laminarContext.spanPath && laminarContext.spanIdsPath) processor.setParentPathInfo(otelSpanContext.spanId, laminarContext.spanPath, laminarContext.spanIdsPath);
|
|
@@ -1820,13 +1867,13 @@ var Laminar = class Laminar {
|
|
|
1820
1867
|
const ctx = LaminarContextManager.setRawAssociationProperties(laminarContext, baseContext);
|
|
1821
1868
|
LaminarContextManager.pushContext(ctx);
|
|
1822
1869
|
try {
|
|
1823
|
-
getRuntime()?.recordTraceId(
|
|
1870
|
+
getRuntime()?.recordTraceId(require_dist.otelTraceIdToUUID(otelSpanContext.traceId));
|
|
1824
1871
|
} catch (e) {
|
|
1825
|
-
logger$
|
|
1872
|
+
logger$18.debug("Failed to record debug trace id from env: " + require_dist.errorMessage(e));
|
|
1826
1873
|
}
|
|
1827
|
-
logger$
|
|
1874
|
+
logger$18.debug("Initialized Laminar parent context from LMNR_SPAN_CONTEXT.");
|
|
1828
1875
|
} catch (e) {
|
|
1829
|
-
logger$
|
|
1876
|
+
logger$18.warn("LMNR_SPAN_CONTEXT is set but could not be used: " + require_dist.errorMessage(e));
|
|
1830
1877
|
}
|
|
1831
1878
|
}
|
|
1832
1879
|
/**
|
|
@@ -1863,21 +1910,21 @@ var Laminar = class Laminar {
|
|
|
1863
1910
|
projectApiKey: this.projectApiKey,
|
|
1864
1911
|
port: httpPort
|
|
1865
1912
|
});
|
|
1866
|
-
const debuggerUrl = process?.env?.LMNR_FRONTEND_URL ??
|
|
1913
|
+
const debuggerUrl = process?.env?.LMNR_FRONTEND_URL ?? require_dist.getFrontendUrl(baseUrl);
|
|
1867
1914
|
const { runtime } = initDebugRuntime(client.rolloutSessions, debuggerUrl);
|
|
1868
1915
|
if (runtime === null) return;
|
|
1869
1916
|
client.rolloutSessions.register({ sessionId: runtime.sessionId }).then((projectId) => {
|
|
1870
1917
|
if (projectId) {
|
|
1871
1918
|
runtime.recordProjectId(projectId);
|
|
1872
1919
|
const sessionUrl = runtime.debuggerSessionUrl();
|
|
1873
|
-
logger$
|
|
1920
|
+
logger$18.info(`Laminar debugger session: ${sessionUrl}`);
|
|
1874
1921
|
if (runtime.shouldOpenBrowser) (0, node_child_process.spawn)(process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open", [sessionUrl], {
|
|
1875
1922
|
detached: true,
|
|
1876
1923
|
stdio: "ignore"
|
|
1877
1924
|
}).unref();
|
|
1878
1925
|
}
|
|
1879
1926
|
}).catch((e) => {
|
|
1880
|
-
logger$
|
|
1927
|
+
logger$18.warn("Failed to register debug session: " + require_dist.errorMessage(e));
|
|
1881
1928
|
});
|
|
1882
1929
|
this.globalMetadata = {
|
|
1883
1930
|
...this.globalMetadata,
|
|
@@ -1887,7 +1934,7 @@ var Laminar = class Laminar {
|
|
|
1887
1934
|
this.debugExitHook = () => runtime.emitPointer();
|
|
1888
1935
|
process.once("exit", this.debugExitHook);
|
|
1889
1936
|
} catch (e) {
|
|
1890
|
-
logger$
|
|
1937
|
+
logger$18.warn("Failed to initialize debug runtime: " + require_dist.errorMessage(e));
|
|
1891
1938
|
}
|
|
1892
1939
|
}
|
|
1893
1940
|
/**
|
|
@@ -1925,14 +1972,14 @@ var Laminar = class Laminar {
|
|
|
1925
1972
|
baseUrl: this.baseUrlForDebug,
|
|
1926
1973
|
projectApiKey: this.projectApiKey,
|
|
1927
1974
|
port: this.httpPortForDebug
|
|
1928
|
-
}).rolloutSessions, process?.env?.LMNR_FRONTEND_URL ??
|
|
1975
|
+
}).rolloutSessions, process?.env?.LMNR_FRONTEND_URL ?? require_dist.getFrontendUrl(this.baseUrlForDebug));
|
|
1929
1976
|
if (runtime === null) return;
|
|
1930
1977
|
if (configChanged) {
|
|
1931
1978
|
this.debugRunLive = false;
|
|
1932
1979
|
runtime.rolloutSessions.register({ sessionId: runtime.sessionId }).then((projectId) => {
|
|
1933
1980
|
if (projectId) runtime.recordProjectId(projectId);
|
|
1934
1981
|
}).catch((e) => {
|
|
1935
|
-
logger$
|
|
1982
|
+
logger$18.debug("Failed to register downstream debug session: " + require_dist.errorMessage(e));
|
|
1936
1983
|
});
|
|
1937
1984
|
this.globalMetadata = {
|
|
1938
1985
|
...this.globalMetadata,
|
|
@@ -1941,7 +1988,7 @@ var Laminar = class Laminar {
|
|
|
1941
1988
|
LaminarContextManager.setGlobalMetadata(this.globalMetadata);
|
|
1942
1989
|
}
|
|
1943
1990
|
} catch (e) {
|
|
1944
|
-
logger$
|
|
1991
|
+
logger$18.debug("Failed to arm debug runtime from context: " + require_dist.errorMessage(e));
|
|
1945
1992
|
}
|
|
1946
1993
|
}
|
|
1947
1994
|
/**
|
|
@@ -1956,7 +2003,7 @@ var Laminar = class Laminar {
|
|
|
1956
2003
|
*/
|
|
1957
2004
|
static patch(modules) {
|
|
1958
2005
|
if (!this.isInitialized) {
|
|
1959
|
-
logger$
|
|
2006
|
+
logger$18.warn("Laminar must be initialized before patching modules. Skipping patch.");
|
|
1960
2007
|
return;
|
|
1961
2008
|
}
|
|
1962
2009
|
if (!modules || Object.keys(modules).length === 0) throw new Error("Pass at least one module to patch");
|
|
@@ -2204,7 +2251,7 @@ var Laminar = class Laminar {
|
|
|
2204
2251
|
let parentUserId;
|
|
2205
2252
|
let parentSessionId;
|
|
2206
2253
|
if (parentSpanContext) try {
|
|
2207
|
-
const laminarContext = typeof parentSpanContext === "string" ?
|
|
2254
|
+
const laminarContext = typeof parentSpanContext === "string" ? require_dist.deserializeLaminarSpanContext(parentSpanContext) : parentSpanContext;
|
|
2208
2255
|
parentPath = laminarContext.spanPath;
|
|
2209
2256
|
parentIdsPath = laminarContext.spanIdsPath;
|
|
2210
2257
|
parentMetadata = laminarContext.metadata;
|
|
@@ -2213,38 +2260,38 @@ var Laminar = class Laminar {
|
|
|
2213
2260
|
parentUserId = laminarContext.userId;
|
|
2214
2261
|
parentSessionId = laminarContext.sessionId;
|
|
2215
2262
|
this._armDebugRuntimeFromContext(laminarContext.debug);
|
|
2216
|
-
const spanContext =
|
|
2263
|
+
const spanContext = require_dist.tryToOtelSpanContext(laminarContext);
|
|
2217
2264
|
entityContext = _opentelemetry_api.trace.setSpan(entityContext, _opentelemetry_api.trace.wrapSpanContext(spanContext));
|
|
2218
2265
|
} catch (e) {
|
|
2219
|
-
logger$
|
|
2266
|
+
logger$18.warn("Failed to parse parent span context: " + require_dist.errorMessage(e));
|
|
2220
2267
|
}
|
|
2221
|
-
const tagProperties = tags ? { [`${
|
|
2268
|
+
const tagProperties = tags ? { [`${require_dist.ASSOCIATION_PROPERTIES}.tags`]: Array.from(new Set(tags)) } : {};
|
|
2222
2269
|
const ctxAssociationProperties = LaminarContextManager.getAssociationProperties();
|
|
2223
2270
|
const userIdValue = userId ?? parentUserId ?? ctxAssociationProperties.userId;
|
|
2224
2271
|
const sessionIdValue = sessionId ?? parentSessionId ?? ctxAssociationProperties.sessionId;
|
|
2225
2272
|
const traceTypeValue = parentTraceType ?? (spanType === "EVALUATION" ? "EVALUATION" : void 0) ?? ctxAssociationProperties.traceType;
|
|
2226
2273
|
const tracingLevelValue = parentTracingLevel ?? ctxAssociationProperties.tracingLevel;
|
|
2227
2274
|
const ctxMetadata = ctxAssociationProperties.metadata;
|
|
2228
|
-
const userIdProperties = userIdValue ? { [
|
|
2229
|
-
const sessionIdProperties = sessionIdValue ? { [
|
|
2230
|
-
const traceTypeProperties = traceTypeValue ? { [
|
|
2231
|
-
const tracingLevelProperties = tracingLevelValue ? { [`${
|
|
2232
|
-
const metadataProperties =
|
|
2275
|
+
const userIdProperties = userIdValue ? { [require_dist.USER_ID]: userIdValue } : {};
|
|
2276
|
+
const sessionIdProperties = sessionIdValue ? { [require_dist.SESSION_ID]: sessionIdValue } : {};
|
|
2277
|
+
const traceTypeProperties = traceTypeValue ? { [require_dist.TRACE_TYPE]: traceTypeValue } : {};
|
|
2278
|
+
const tracingLevelProperties = tracingLevelValue ? { [`${require_dist.ASSOCIATION_PROPERTIES}.tracing_level`]: tracingLevelValue } : {};
|
|
2279
|
+
const metadataProperties = require_dist.metadataToAttributes({
|
|
2233
2280
|
...this.globalMetadata,
|
|
2234
2281
|
...ctxMetadata,
|
|
2235
2282
|
...parentMetadata,
|
|
2236
2283
|
...metadata
|
|
2237
2284
|
});
|
|
2238
2285
|
const attributes = {
|
|
2239
|
-
[
|
|
2286
|
+
[require_dist.SPAN_TYPE]: spanType ?? "DEFAULT",
|
|
2240
2287
|
...tagProperties,
|
|
2241
2288
|
...userIdProperties,
|
|
2242
2289
|
...sessionIdProperties,
|
|
2243
2290
|
...metadataProperties,
|
|
2244
2291
|
...traceTypeProperties,
|
|
2245
2292
|
...tracingLevelProperties,
|
|
2246
|
-
...parentPath ? { [
|
|
2247
|
-
...parentIdsPath ? { [
|
|
2293
|
+
...parentPath ? { [require_dist.PARENT_SPAN_PATH]: parentPath } : {},
|
|
2294
|
+
...parentIdsPath ? { [require_dist.PARENT_SPAN_IDS_PATH]: parentIdsPath } : {}
|
|
2248
2295
|
};
|
|
2249
2296
|
const span = new LaminarSpan(getTracer().startSpan(name, {
|
|
2250
2297
|
attributes,
|
|
@@ -2319,13 +2366,13 @@ var Laminar = class Laminar {
|
|
|
2319
2366
|
}
|
|
2320
2367
|
static async flush() {
|
|
2321
2368
|
if (this.isInitialized) {
|
|
2322
|
-
logger$
|
|
2369
|
+
logger$18.debug("Flushing spans");
|
|
2323
2370
|
await forceFlush();
|
|
2324
2371
|
}
|
|
2325
2372
|
}
|
|
2326
2373
|
static async shutdown() {
|
|
2327
2374
|
if (this.isInitialized) {
|
|
2328
|
-
logger$
|
|
2375
|
+
logger$18.debug("Shutting down Laminar");
|
|
2329
2376
|
getRuntime()?.emitPointer();
|
|
2330
2377
|
await forceFlush();
|
|
2331
2378
|
this.isInitialized = false;
|
|
@@ -2460,7 +2507,7 @@ return module.exports;
|
|
|
2460
2507
|
//#endregion
|
|
2461
2508
|
//#region src/browser/utils.ts
|
|
2462
2509
|
const LMNR_SEND_EVENTS_FUNCTION_NAME = "lmnrSendEvents";
|
|
2463
|
-
const logger$
|
|
2510
|
+
const logger$17 = require_dist.initializeLogger();
|
|
2464
2511
|
/**
|
|
2465
2512
|
* If the first argument is a string, return an object with the name of the method
|
|
2466
2513
|
* and the argument as the value.
|
|
@@ -2483,7 +2530,7 @@ const takeFullSnapshot = async (page) => await page.evaluate(() => {
|
|
|
2483
2530
|
window.lmnrRrweb.record.takeFullSnapshot();
|
|
2484
2531
|
return true;
|
|
2485
2532
|
} catch (error) {
|
|
2486
|
-
logger$
|
|
2533
|
+
logger$17.error("Error taking full snapshot: " + require_dist.errorMessage(error));
|
|
2487
2534
|
return false;
|
|
2488
2535
|
}
|
|
2489
2536
|
return false;
|
|
@@ -2494,7 +2541,7 @@ const injectSessionRecorder = async (page, sessionRecordingOptions) => {
|
|
|
2494
2541
|
try {
|
|
2495
2542
|
return await script();
|
|
2496
2543
|
} catch (error) {
|
|
2497
|
-
logger$
|
|
2544
|
+
logger$17.error("Operation " + script.name + " failed: " + require_dist.errorMessage(error));
|
|
2498
2545
|
}
|
|
2499
2546
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
2500
2547
|
}
|
|
@@ -2504,20 +2551,20 @@ const injectSessionRecorder = async (page, sessionRecordingOptions) => {
|
|
|
2504
2551
|
try {
|
|
2505
2552
|
isRrwebPresent = await castedPage.evaluate(() => typeof window.lmnrRrweb !== "undefined");
|
|
2506
2553
|
} catch (error) {
|
|
2507
|
-
logger$
|
|
2554
|
+
logger$17.debug("Failed to check if session recorder is loaded: " + require_dist.errorMessage(error));
|
|
2508
2555
|
}
|
|
2509
2556
|
if (!isRrwebPresent) {
|
|
2510
2557
|
if (!await tryRunScript(async function injectSessionRecorder() {
|
|
2511
2558
|
await castedPage.evaluate(RECORDER);
|
|
2512
2559
|
return true;
|
|
2513
2560
|
})) {
|
|
2514
|
-
logger$
|
|
2561
|
+
logger$17.error("Failed to load session recorder");
|
|
2515
2562
|
return;
|
|
2516
2563
|
}
|
|
2517
2564
|
try {
|
|
2518
2565
|
await castedPage.evaluate(injectScript, sessionRecordingOptions);
|
|
2519
2566
|
} catch (error) {
|
|
2520
|
-
logger$
|
|
2567
|
+
logger$17.debug("Failed to inject session recorder: " + require_dist.errorMessage(error));
|
|
2521
2568
|
}
|
|
2522
2569
|
}
|
|
2523
2570
|
};
|
|
@@ -2780,7 +2827,7 @@ async function sendEvents(chunk, client, chunkBuffers, sessionId, traceId) {
|
|
|
2780
2827
|
try {
|
|
2781
2828
|
const { batchId, chunkIndex, totalChunks, data } = chunk;
|
|
2782
2829
|
if (!sessionId || !traceId) {
|
|
2783
|
-
logger$
|
|
2830
|
+
logger$17.debug("Missing sessionId or traceId in chunk");
|
|
2784
2831
|
return;
|
|
2785
2832
|
}
|
|
2786
2833
|
if (!chunkBuffers.has(batchId)) chunkBuffers.set(batchId, {
|
|
@@ -2799,7 +2846,7 @@ async function sendEvents(chunk, client, chunkBuffers, sessionId, traceId) {
|
|
|
2799
2846
|
traceId,
|
|
2800
2847
|
events
|
|
2801
2848
|
}).catch((error) => {
|
|
2802
|
-
logger$
|
|
2849
|
+
logger$17.debug("Failed to send events: " + require_dist.errorMessage(error));
|
|
2803
2850
|
});
|
|
2804
2851
|
chunkBuffers.delete(batchId);
|
|
2805
2852
|
}
|
|
@@ -2807,16 +2854,16 @@ async function sendEvents(chunk, client, chunkBuffers, sessionId, traceId) {
|
|
|
2807
2854
|
const toDelete = [];
|
|
2808
2855
|
for (const [bid, buffer] of chunkBuffers.entries()) if (currentTime - buffer.timestamp > OLD_BUFFER_TIMEOUT) toDelete.push(bid);
|
|
2809
2856
|
for (const bid of toDelete) {
|
|
2810
|
-
logger$
|
|
2857
|
+
logger$17.debug(`Cleaning up incomplete chunk buffer: ${bid}`);
|
|
2811
2858
|
chunkBuffers.delete(bid);
|
|
2812
2859
|
}
|
|
2813
2860
|
} catch (error) {
|
|
2814
|
-
logger$
|
|
2861
|
+
logger$17.debug("Could not send events: " + require_dist.errorMessage(error));
|
|
2815
2862
|
}
|
|
2816
2863
|
}
|
|
2817
2864
|
//#endregion
|
|
2818
2865
|
//#region src/browser/playwright.ts
|
|
2819
|
-
const logger$
|
|
2866
|
+
const logger$16 = require_dist.initializeLogger();
|
|
2820
2867
|
var PlaywrightInstrumentation = class extends _opentelemetry_instrumentation.InstrumentationBase {
|
|
2821
2868
|
constructor(client, sessionRecordingOptions) {
|
|
2822
2869
|
super("@lmnr/playwright-instrumentation", require_dist.version, { enabled: true });
|
|
@@ -2880,7 +2927,7 @@ var PlaywrightInstrumentation = class extends _opentelemetry_instrumentation.Ins
|
|
|
2880
2927
|
const plugin = this;
|
|
2881
2928
|
return (original) => async function method(...args) {
|
|
2882
2929
|
const browser = await original.call(this, ...args);
|
|
2883
|
-
const sessionId =
|
|
2930
|
+
const sessionId = require_dist.newUUID();
|
|
2884
2931
|
for (const context of browser.contexts()) {
|
|
2885
2932
|
context.on("page", (page) => plugin.patchPage(page, sessionId));
|
|
2886
2933
|
for (const page of context.pages()) await plugin.patchPage(page, sessionId);
|
|
@@ -2894,7 +2941,7 @@ var PlaywrightInstrumentation = class extends _opentelemetry_instrumentation.Ins
|
|
|
2894
2941
|
const plugin = this;
|
|
2895
2942
|
return (original) => async function method(...args) {
|
|
2896
2943
|
const context = await original.bind(this).apply(this, args);
|
|
2897
|
-
const sessionId =
|
|
2944
|
+
const sessionId = require_dist.newUUID();
|
|
2898
2945
|
context.on("page", async (page) => plugin.patchPage(page, sessionId));
|
|
2899
2946
|
for (const page of context.pages()) await plugin.patchPage(page, sessionId);
|
|
2900
2947
|
return context;
|
|
@@ -2917,14 +2964,14 @@ var PlaywrightInstrumentation = class extends _opentelemetry_instrumentation.Ins
|
|
|
2917
2964
|
await takeFullSnapshot(page);
|
|
2918
2965
|
};
|
|
2919
2966
|
const currentSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
2920
|
-
currentSpan?.setAttribute(
|
|
2967
|
+
currentSpan?.setAttribute(require_dist.TRACE_HAS_BROWSER_SESSION, true);
|
|
2921
2968
|
const otelTraceId = currentSpan?.spanContext().traceId;
|
|
2922
|
-
const traceId = otelTraceId ?
|
|
2969
|
+
const traceId = otelTraceId ? require_dist.otelTraceIdToUUID(otelTraceId) : require_dist.NIL_UUID;
|
|
2923
2970
|
page.on("domcontentloaded", async () => {
|
|
2924
2971
|
try {
|
|
2925
2972
|
await injectSessionRecorder(page, this._sessionRecordingOptions);
|
|
2926
2973
|
} catch (error) {
|
|
2927
|
-
logger$
|
|
2974
|
+
logger$16.error("Error in onLoad handler: " + require_dist.errorMessage(error));
|
|
2928
2975
|
}
|
|
2929
2976
|
});
|
|
2930
2977
|
const chunkBuffers = /* @__PURE__ */ new Map();
|
|
@@ -2934,7 +2981,7 @@ var PlaywrightInstrumentation = class extends _opentelemetry_instrumentation.Ins
|
|
|
2934
2981
|
await sendEvents(chunk, this._client, chunkBuffers, sessionId, traceId);
|
|
2935
2982
|
});
|
|
2936
2983
|
} catch (error) {
|
|
2937
|
-
logger$
|
|
2984
|
+
logger$16.debug("Could not expose function lmnrSendEvents: " + require_dist.errorMessage(error));
|
|
2938
2985
|
}
|
|
2939
2986
|
}
|
|
2940
2987
|
};
|
|
@@ -2961,7 +3008,7 @@ const createLLMClientCreateChatCompletionWrapper = (globalLLMClientOptions) => (
|
|
|
2961
3008
|
const recordedProvider = globalLLMClientOptions.get(this)?.provider;
|
|
2962
3009
|
const provider = recordedProvider === "aisdk" && globalLLMClientOptions.get(this)?.model ? modelToProvider(globalLLMClientOptions.get(this).model) ?? "aisdk" : recordedProvider;
|
|
2963
3010
|
span.setAttributes({
|
|
2964
|
-
[
|
|
3011
|
+
[require_dist.SPAN_TYPE]: "LLM",
|
|
2965
3012
|
...innerOptions.temperature ? { "gen_ai.request.temperature": innerOptions.temperature } : {},
|
|
2966
3013
|
...innerOptions.top_p ? { "gen_ai.request.top_p": innerOptions.top_p } : {},
|
|
2967
3014
|
...innerOptions.frequency_penalty ? { "gen_ai.request.frequency_penalty": innerOptions.frequency_penalty } : {},
|
|
@@ -3099,7 +3146,7 @@ var StagehandV2Instrumentation = class extends _opentelemetry_instrumentation.In
|
|
|
3099
3146
|
patchStagehandInit() {
|
|
3100
3147
|
const instrumentation = this;
|
|
3101
3148
|
return (original) => async function method() {
|
|
3102
|
-
const sessionId =
|
|
3149
|
+
const sessionId = require_dist.newUUID();
|
|
3103
3150
|
const parentSpan = Laminar.startSpan({ name: "Stagehand" });
|
|
3104
3151
|
instrumentation.playwrightInstrumentation.setParentSpanForSession(sessionId, parentSpan);
|
|
3105
3152
|
const result = await original.bind(this).apply(this);
|
|
@@ -3359,7 +3406,7 @@ var StagehandV2Instrumentation = class extends _opentelemetry_instrumentation.In
|
|
|
3359
3406
|
};
|
|
3360
3407
|
//#endregion
|
|
3361
3408
|
//#region src/browser/puppeteer.ts
|
|
3362
|
-
const logger$
|
|
3409
|
+
const logger$15 = require_dist.initializeLogger();
|
|
3363
3410
|
var PuppeteerInstrumentation = class extends _opentelemetry_instrumentation.InstrumentationBase {
|
|
3364
3411
|
constructor(client, sessionRecordingOptions) {
|
|
3365
3412
|
super("@lmnr/puppeteer-instrumentation", require_dist.version, { enabled: true });
|
|
@@ -3399,15 +3446,15 @@ var PuppeteerInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3399
3446
|
const plugin = this;
|
|
3400
3447
|
return (original) => async function method(...args) {
|
|
3401
3448
|
const browser = await original.call(this, ...args);
|
|
3402
|
-
const sessionId =
|
|
3449
|
+
const sessionId = require_dist.newUUID();
|
|
3403
3450
|
for (const context of browser.browserContexts()) {
|
|
3404
3451
|
context.on("targetcreated", (target) => {
|
|
3405
3452
|
target.page().then((page) => {
|
|
3406
3453
|
if (page) plugin.patchPage(page, sessionId).catch((error) => {
|
|
3407
|
-
logger$
|
|
3454
|
+
logger$15.error("Failed to patch page: " + require_dist.errorMessage(error));
|
|
3408
3455
|
});
|
|
3409
3456
|
}).catch((error) => {
|
|
3410
|
-
logger$
|
|
3457
|
+
logger$15.error("Failed to patch page: " + require_dist.errorMessage(error));
|
|
3411
3458
|
});
|
|
3412
3459
|
});
|
|
3413
3460
|
await Promise.all((await context.pages()).map((page) => plugin.patchPage(page, sessionId)));
|
|
@@ -3421,23 +3468,23 @@ var PuppeteerInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3421
3468
|
const plugin = this;
|
|
3422
3469
|
return (original) => async function method(...args) {
|
|
3423
3470
|
const context = await original.bind(this).apply(this, args);
|
|
3424
|
-
const sessionId =
|
|
3471
|
+
const sessionId = require_dist.newUUID();
|
|
3425
3472
|
context.on("targetcreated", (target) => {
|
|
3426
3473
|
target.page().then((page) => {
|
|
3427
3474
|
if (page) plugin.patchPage(page, sessionId).catch((error) => {
|
|
3428
|
-
logger$
|
|
3475
|
+
logger$15.error("Failed to patch page: " + require_dist.errorMessage(error));
|
|
3429
3476
|
});
|
|
3430
3477
|
}).catch((error) => {
|
|
3431
|
-
logger$
|
|
3478
|
+
logger$15.error("Failed to patch page: " + require_dist.errorMessage(error));
|
|
3432
3479
|
});
|
|
3433
3480
|
});
|
|
3434
3481
|
context.on("targetchanged", (target) => {
|
|
3435
3482
|
target.page().then((page) => {
|
|
3436
3483
|
if (page) plugin.patchPage(page, sessionId).catch((error) => {
|
|
3437
|
-
logger$
|
|
3484
|
+
logger$15.error("Failed to patch page: " + require_dist.errorMessage(error));
|
|
3438
3485
|
});
|
|
3439
3486
|
}).catch((error) => {
|
|
3440
|
-
logger$
|
|
3487
|
+
logger$15.error("Failed to patch page: " + require_dist.errorMessage(error));
|
|
3441
3488
|
});
|
|
3442
3489
|
});
|
|
3443
3490
|
for (const page of await context.pages()) await plugin.patchPage(page, sessionId);
|
|
@@ -3456,12 +3503,12 @@ var PuppeteerInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3456
3503
|
await takeFullSnapshot(page);
|
|
3457
3504
|
};
|
|
3458
3505
|
const currentSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
3459
|
-
currentSpan?.setAttribute(
|
|
3506
|
+
currentSpan?.setAttribute(require_dist.TRACE_HAS_BROWSER_SESSION, true);
|
|
3460
3507
|
const otelTraceId = currentSpan?.spanContext().traceId;
|
|
3461
|
-
const traceId = otelTraceId ?
|
|
3508
|
+
const traceId = otelTraceId ? require_dist.otelTraceIdToUUID(otelTraceId) : require_dist.NIL_UUID;
|
|
3462
3509
|
page.on("domcontentloaded", () => {
|
|
3463
3510
|
injectSessionRecorder(page, this._sessionRecordingOptions).catch((error) => {
|
|
3464
|
-
logger$
|
|
3511
|
+
logger$15.error("Error in onLoad handler: " + require_dist.errorMessage(error));
|
|
3465
3512
|
});
|
|
3466
3513
|
});
|
|
3467
3514
|
await injectSessionRecorder(page, this._sessionRecordingOptions);
|
|
@@ -3471,13 +3518,13 @@ var PuppeteerInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3471
3518
|
await sendEvents(chunk, this._client, chunkBuffers, sessionId, traceId);
|
|
3472
3519
|
});
|
|
3473
3520
|
} catch (error) {
|
|
3474
|
-
logger$
|
|
3521
|
+
logger$15.debug("Could not expose function lmnrSendEvents: " + require_dist.errorMessage(error));
|
|
3475
3522
|
}
|
|
3476
3523
|
}
|
|
3477
3524
|
};
|
|
3478
3525
|
//#endregion
|
|
3479
3526
|
//#region src/browser/stagehand/v3/constants.ts
|
|
3480
|
-
const logger$
|
|
3527
|
+
const logger$14 = require_dist.initializeLogger();
|
|
3481
3528
|
const CDP_OPERATION_TIMEOUT_MS = 1e4;
|
|
3482
3529
|
const SKIP_URL_PATTERNS = [
|
|
3483
3530
|
"about:blank",
|
|
@@ -3528,7 +3575,7 @@ async function getOrCreateIsolatedWorld(page) {
|
|
|
3528
3575
|
frameId
|
|
3529
3576
|
};
|
|
3530
3577
|
} catch (error) {
|
|
3531
|
-
logger$
|
|
3578
|
+
logger$14.debug("Failed to create isolated world: " + require_dist.errorMessage(error));
|
|
3532
3579
|
return null;
|
|
3533
3580
|
}
|
|
3534
3581
|
}
|
|
@@ -3545,7 +3592,7 @@ async function isRecorderPresent(page, contextId) {
|
|
|
3545
3592
|
if (!result) return true;
|
|
3546
3593
|
return result.result?.value === true;
|
|
3547
3594
|
} catch (error) {
|
|
3548
|
-
logger$
|
|
3595
|
+
logger$14.debug("Failed to check if recorder is present: " + require_dist.errorMessage(error));
|
|
3549
3596
|
return true;
|
|
3550
3597
|
}
|
|
3551
3598
|
}
|
|
@@ -3558,21 +3605,21 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
3558
3605
|
try {
|
|
3559
3606
|
url = page.url();
|
|
3560
3607
|
} catch (error) {
|
|
3561
|
-
logger$
|
|
3608
|
+
logger$14.debug("Failed to get page URL, page might be closed: " + require_dist.errorMessage(error));
|
|
3562
3609
|
return null;
|
|
3563
3610
|
}
|
|
3564
3611
|
if (shouldSkipUrl(url)) {
|
|
3565
|
-
logger$
|
|
3612
|
+
logger$14.debug(`Skipping recorder injection for URL: ${url}`);
|
|
3566
3613
|
return null;
|
|
3567
3614
|
}
|
|
3568
3615
|
const worldResult = await getOrCreateIsolatedWorld(page);
|
|
3569
3616
|
if (!worldResult) {
|
|
3570
|
-
logger$
|
|
3617
|
+
logger$14.debug("Failed to get isolated world for page");
|
|
3571
3618
|
return null;
|
|
3572
3619
|
}
|
|
3573
3620
|
const { contextId, frameId } = worldResult;
|
|
3574
3621
|
if (await isRecorderPresent(page, contextId)) {
|
|
3575
|
-
logger$
|
|
3622
|
+
logger$14.debug("Recorder already present, skipping injection");
|
|
3576
3623
|
state.contextIdToSession.set(contextId, {
|
|
3577
3624
|
sessionId: state.sessionId,
|
|
3578
3625
|
traceId: state.traceId
|
|
@@ -3585,7 +3632,7 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
3585
3632
|
contextId
|
|
3586
3633
|
});
|
|
3587
3634
|
} catch (error) {
|
|
3588
|
-
logger$
|
|
3635
|
+
logger$14.debug("Failed to inject rrweb: " + require_dist.errorMessage(error));
|
|
3589
3636
|
return null;
|
|
3590
3637
|
}
|
|
3591
3638
|
const optionsJson = JSON.stringify(sessionRecordingOptions ?? {});
|
|
@@ -3596,14 +3643,14 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
3596
3643
|
contextId
|
|
3597
3644
|
});
|
|
3598
3645
|
} catch (error) {
|
|
3599
|
-
logger$
|
|
3646
|
+
logger$14.debug("Failed to inject recording setup: " + require_dist.errorMessage(error));
|
|
3600
3647
|
return null;
|
|
3601
3648
|
}
|
|
3602
3649
|
try {
|
|
3603
3650
|
await sendCDP(page, "Runtime.addBinding", { name: "lmnrSendEvents" });
|
|
3604
|
-
logger$
|
|
3651
|
+
logger$14.debug(`Added binding 'lmnrSendEvents' for page ${frameId}, context ${contextId}`);
|
|
3605
3652
|
} catch (error) {
|
|
3606
|
-
logger$
|
|
3653
|
+
logger$14.debug("Binding may already exist: " + require_dist.errorMessage(error));
|
|
3607
3654
|
}
|
|
3608
3655
|
if (bindingHandler) try {
|
|
3609
3656
|
const pageTargetId = page.targetId();
|
|
@@ -3613,26 +3660,26 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
3613
3660
|
const sessionTyped = session;
|
|
3614
3661
|
if (sessionTyped.on) {
|
|
3615
3662
|
sessionTyped.on("Runtime.bindingCalled", bindingHandler);
|
|
3616
|
-
logger$
|
|
3663
|
+
logger$14.debug(`Set up binding handler on session ${sessionId}`);
|
|
3617
3664
|
}
|
|
3618
3665
|
} catch (error) {
|
|
3619
|
-
logger$
|
|
3666
|
+
logger$14.debug(`Failed to set up binding handler on session ${sessionId}: ` + require_dist.errorMessage(error));
|
|
3620
3667
|
}
|
|
3621
3668
|
state.pageSessionHandlers.set(pageTargetId, bindingHandler);
|
|
3622
3669
|
}
|
|
3623
3670
|
} catch (error) {
|
|
3624
|
-
logger$
|
|
3671
|
+
logger$14.debug("Failed to set up binding handler: " + require_dist.errorMessage(error));
|
|
3625
3672
|
}
|
|
3626
3673
|
state.contextIdToSession.set(contextId, {
|
|
3627
3674
|
sessionId: state.sessionId,
|
|
3628
3675
|
traceId: state.traceId
|
|
3629
3676
|
});
|
|
3630
|
-
logger$
|
|
3677
|
+
logger$14.debug(`Registered context mapping: contextId=${contextId}, sessionId=${state.sessionId}`);
|
|
3631
3678
|
state.instrumentedPageIds.add(frameId);
|
|
3632
|
-
logger$
|
|
3679
|
+
logger$14.debug(`Successfully injected recorder into page ${frameId}`);
|
|
3633
3680
|
return contextId;
|
|
3634
3681
|
} catch (error) {
|
|
3635
|
-
logger$
|
|
3682
|
+
logger$14.debug("Error injecting recorder: " + require_dist.errorMessage(error));
|
|
3636
3683
|
return null;
|
|
3637
3684
|
}
|
|
3638
3685
|
}
|
|
@@ -3646,13 +3693,13 @@ function createBindingHandler(state) {
|
|
|
3646
3693
|
if (event.name !== "lmnrSendEvents") return;
|
|
3647
3694
|
const sessionInfo = state.contextIdToSession.get(event.executionContextId);
|
|
3648
3695
|
if (!sessionInfo) {
|
|
3649
|
-
logger$
|
|
3696
|
+
logger$14.debug("No session info found for context ID: " + event.executionContextId);
|
|
3650
3697
|
if (state.contextIdToSession.size > 0) {
|
|
3651
3698
|
const [, fallbackInfo] = state.contextIdToSession.entries().next().value;
|
|
3652
3699
|
if (fallbackInfo) try {
|
|
3653
3700
|
sendEvents(JSON.parse(event.payload), state.client, state.chunkBuffers, fallbackInfo.sessionId, fallbackInfo.traceId);
|
|
3654
3701
|
} catch (error) {
|
|
3655
|
-
logger$
|
|
3702
|
+
logger$14.debug("Failed to parse binding payload: " + require_dist.errorMessage(error));
|
|
3656
3703
|
}
|
|
3657
3704
|
}
|
|
3658
3705
|
return;
|
|
@@ -3660,7 +3707,7 @@ function createBindingHandler(state) {
|
|
|
3660
3707
|
try {
|
|
3661
3708
|
sendEvents(JSON.parse(event.payload), state.client, state.chunkBuffers, sessionInfo.sessionId, sessionInfo.traceId);
|
|
3662
3709
|
} catch (error) {
|
|
3663
|
-
logger$
|
|
3710
|
+
logger$14.debug("Failed to handle binding event: " + require_dist.errorMessage(error));
|
|
3664
3711
|
}
|
|
3665
3712
|
};
|
|
3666
3713
|
}
|
|
@@ -3676,10 +3723,10 @@ function createTargetCreatedHandler(context, state, sessionRecordingOptions) {
|
|
|
3676
3723
|
const pageId = page.mainFrameId();
|
|
3677
3724
|
if (!state.instrumentedPageIds.has(pageId)) await injectRecorderViaCDP(page, state, context.conn, sessionRecordingOptions, state.bindingHandler ?? void 0);
|
|
3678
3725
|
} catch (error) {
|
|
3679
|
-
logger$
|
|
3726
|
+
logger$14.debug("Error injecting recorder into new page: " + require_dist.errorMessage(error));
|
|
3680
3727
|
}
|
|
3681
3728
|
} catch (error) {
|
|
3682
|
-
logger$
|
|
3729
|
+
logger$14.debug("Error handling target created event: " + require_dist.errorMessage(error));
|
|
3683
3730
|
}
|
|
3684
3731
|
};
|
|
3685
3732
|
}
|
|
@@ -3691,7 +3738,7 @@ function createTargetInfoChangedHandler(context, state, sessionRecordingOptions)
|
|
|
3691
3738
|
if (event.targetInfo.type !== "page") return;
|
|
3692
3739
|
const url = event.targetInfo.url;
|
|
3693
3740
|
if (shouldSkipUrl(url)) return;
|
|
3694
|
-
logger$
|
|
3741
|
+
logger$14.debug(`Target URL changed to ${url}, checking if recorder injection needed`);
|
|
3695
3742
|
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3696
3743
|
try {
|
|
3697
3744
|
for (const page of context.pages()) if (page.targetId() === event.targetInfo.targetId) {
|
|
@@ -3699,7 +3746,7 @@ function createTargetInfoChangedHandler(context, state, sessionRecordingOptions)
|
|
|
3699
3746
|
break;
|
|
3700
3747
|
}
|
|
3701
3748
|
} catch (error) {
|
|
3702
|
-
logger$
|
|
3749
|
+
logger$14.debug("Error handling target info change: " + require_dist.errorMessage(error));
|
|
3703
3750
|
}
|
|
3704
3751
|
};
|
|
3705
3752
|
}
|
|
@@ -3824,13 +3871,13 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3824
3871
|
patchStagehandInit() {
|
|
3825
3872
|
const instrumentation = this;
|
|
3826
3873
|
return (original) => async function method() {
|
|
3827
|
-
const sessionId =
|
|
3874
|
+
const sessionId = require_dist.newUUID();
|
|
3828
3875
|
const parentSpan = Laminar.startSpan({ name: "Stagehand" });
|
|
3829
3876
|
instrumentation.sessionIdToParentSpan.set(sessionId, parentSpan);
|
|
3830
3877
|
instrumentation.stagehandInstanceToSessionId.set(this, sessionId);
|
|
3831
|
-
(_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan())?.setAttribute(
|
|
3878
|
+
(_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan())?.setAttribute(require_dist.TRACE_HAS_BROWSER_SESSION, true);
|
|
3832
3879
|
const otelTraceId = parentSpan.spanContext().traceId;
|
|
3833
|
-
const traceId =
|
|
3880
|
+
const traceId = require_dist.otelTraceIdToUUID(otelTraceId);
|
|
3834
3881
|
const result = await original.bind(this).apply(this);
|
|
3835
3882
|
safeWrap(instrumentation, this, "act", instrumentation.patchStagehandGlobalMethod("act", sessionId, parentSpan));
|
|
3836
3883
|
safeWrap(instrumentation, this, "extract", instrumentation.patchStagehandGlobalMethod("extract", sessionId, parentSpan));
|
|
@@ -3860,12 +3907,12 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3860
3907
|
*/
|
|
3861
3908
|
async setupSessionRecording(stagehandInstance, sessionId, traceId) {
|
|
3862
3909
|
if (!this._client) {
|
|
3863
|
-
logger$
|
|
3910
|
+
logger$14.debug("No Laminar client available, skipping session recording setup");
|
|
3864
3911
|
return;
|
|
3865
3912
|
}
|
|
3866
3913
|
const context = stagehandInstance.context;
|
|
3867
3914
|
if (!context || !context.conn) {
|
|
3868
|
-
logger$
|
|
3915
|
+
logger$14.debug("No context or connection available, skipping session recording setup");
|
|
3869
3916
|
return;
|
|
3870
3917
|
}
|
|
3871
3918
|
const recorderState = {
|
|
@@ -3895,11 +3942,11 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3895
3942
|
for (const page of pages) try {
|
|
3896
3943
|
if (await injectRecorderViaCDP(page, recorderState, context.conn, this._sessionRecordingOptions, bindingHandler) !== null) injectedCount++;
|
|
3897
3944
|
} catch (error) {
|
|
3898
|
-
logger$
|
|
3945
|
+
logger$14.debug("Error injecting recorder into page: " + require_dist.errorMessage(error));
|
|
3899
3946
|
}
|
|
3900
|
-
logger$
|
|
3947
|
+
logger$14.debug(`Injected session recorder into ${injectedCount} of ${pages.length} existing page(s)`);
|
|
3901
3948
|
} catch (error) {
|
|
3902
|
-
logger$
|
|
3949
|
+
logger$14.debug("Error accessing pages for recorder injection: " + require_dist.errorMessage(error));
|
|
3903
3950
|
}
|
|
3904
3951
|
}
|
|
3905
3952
|
patchStagehandClose() {
|
|
@@ -3929,12 +3976,12 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3929
3976
|
if (recorderState.targetCreatedHandler) try {
|
|
3930
3977
|
context.conn.off("Target.targetCreated", recorderState.targetCreatedHandler);
|
|
3931
3978
|
} catch (error) {
|
|
3932
|
-
logger$
|
|
3979
|
+
logger$14.debug("Error removing target created handler: " + require_dist.errorMessage(error));
|
|
3933
3980
|
}
|
|
3934
3981
|
if (recorderState.targetInfoChangedHandler) try {
|
|
3935
3982
|
context.conn.off("Target.targetInfoChanged", recorderState.targetInfoChangedHandler);
|
|
3936
3983
|
} catch (error) {
|
|
3937
|
-
logger$
|
|
3984
|
+
logger$14.debug("Error removing target info changed handler: " + require_dist.errorMessage(error));
|
|
3938
3985
|
}
|
|
3939
3986
|
}
|
|
3940
3987
|
recorderState.contextIdToSession.clear();
|
|
@@ -3945,7 +3992,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3945
3992
|
recorderState.targetCreatedHandler = null;
|
|
3946
3993
|
recorderState.targetInfoChangedHandler = null;
|
|
3947
3994
|
this.stagehandInstanceToRecorderState.delete(stagehandInstance);
|
|
3948
|
-
logger$
|
|
3995
|
+
logger$14.debug("Cleaned up session recording for Stagehand instance");
|
|
3949
3996
|
}
|
|
3950
3997
|
patchStagehandGlobalMethod(methodName, sessionId, parentSpan) {
|
|
3951
3998
|
return (original) => async function method(...args) {
|
|
@@ -3975,7 +4022,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3975
4022
|
name: `stagehand.${methodName}`,
|
|
3976
4023
|
input
|
|
3977
4024
|
}, async (thisArg, rest) => {
|
|
3978
|
-
(_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan())?.setAttribute(
|
|
4025
|
+
(_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan())?.setAttribute(require_dist.TRACE_HAS_BROWSER_SESSION, true);
|
|
3979
4026
|
return await original.apply(thisArg, rest);
|
|
3980
4027
|
}, this, args));
|
|
3981
4028
|
};
|
|
@@ -4085,7 +4132,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
4085
4132
|
spanType: "LLM"
|
|
4086
4133
|
}, async () => {
|
|
4087
4134
|
const span = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
4088
|
-
span?.setAttribute(
|
|
4135
|
+
span?.setAttribute(require_dist.TRACE_HAS_BROWSER_SESSION, true);
|
|
4089
4136
|
const agentOptions = instrumentation.globalAgentOptions.get(this);
|
|
4090
4137
|
const maybeModelName = agentOptions?.model?.modelName ?? (typeof agentOptions?.model === "string" ? agentOptions.model : void 0);
|
|
4091
4138
|
const provider = agentOptions?.model?.provider ?? (maybeModelName?.includes("/") ? maybeModelName?.split("/")[0] : instrumentation.globalLLMClientOptions.get(this)?.provider);
|
|
@@ -4187,7 +4234,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
4187
4234
|
ignoreOutput: true
|
|
4188
4235
|
}, async () => {
|
|
4189
4236
|
const span = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
4190
|
-
span?.setAttribute(
|
|
4237
|
+
span?.setAttribute(require_dist.TRACE_HAS_BROWSER_SESSION, true);
|
|
4191
4238
|
if (baseProvider) span?.setAttribute("gen_ai.system", baseProvider);
|
|
4192
4239
|
if (baseModel) span?.setAttribute("gen_ai.request.model", baseModel);
|
|
4193
4240
|
try {
|
|
@@ -4816,10 +4863,10 @@ const normalizeMessages = (data, role = "user") => {
|
|
|
4816
4863
|
};
|
|
4817
4864
|
//#endregion
|
|
4818
4865
|
//#region src/opentelemetry-lib/instrumentation/openai-agents/messages.ts
|
|
4819
|
-
const logger$
|
|
4866
|
+
const logger$13 = require_dist.initializeLogger();
|
|
4820
4867
|
const setLmnrSpanIo = (lmnrSpan, inputData, outputData) => {
|
|
4821
|
-
if (inputData !== void 0 && inputData !== null) lmnrSpan.setAttribute(
|
|
4822
|
-
if (outputData !== void 0 && outputData !== null) lmnrSpan.setAttribute(
|
|
4868
|
+
if (inputData !== void 0 && inputData !== null) lmnrSpan.setAttribute(require_dist.SPAN_INPUT, JSON.stringify(inputData));
|
|
4869
|
+
if (outputData !== void 0 && outputData !== null) lmnrSpan.setAttribute(require_dist.SPAN_OUTPUT, JSON.stringify(outputData));
|
|
4823
4870
|
};
|
|
4824
4871
|
const setGenAiInputMessages = (lmnrSpan, inputData, systemInstructions) => {
|
|
4825
4872
|
const hasInput = inputData !== void 0 && inputData !== null;
|
|
@@ -4845,7 +4892,7 @@ const setGenAiOutputMessagesFromResponse = (lmnrSpan, response) => {
|
|
|
4845
4892
|
if (!outputItems) return;
|
|
4846
4893
|
const id = response.id;
|
|
4847
4894
|
if (!Array.isArray(outputItems)) {
|
|
4848
|
-
logger$
|
|
4895
|
+
logger$13.debug("Laminar OpenAI agents instrumentation, failed to parse output items. Expected array");
|
|
4849
4896
|
outputItems = [];
|
|
4850
4897
|
}
|
|
4851
4898
|
const result = {
|
|
@@ -4882,9 +4929,9 @@ const applyLlmAttributes = (lmnrSpan, data) => {
|
|
|
4882
4929
|
if (!data) return;
|
|
4883
4930
|
const model = data.model;
|
|
4884
4931
|
if (model) {
|
|
4885
|
-
lmnrSpan.setAttribute(
|
|
4886
|
-
lmnrSpan.setAttribute(
|
|
4887
|
-
lmnrSpan.setAttribute(
|
|
4932
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.REQUEST_MODEL, model);
|
|
4933
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.RESPONSE_MODEL, model);
|
|
4934
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.PROVIDER, "openai");
|
|
4888
4935
|
}
|
|
4889
4936
|
const usage = data.usage;
|
|
4890
4937
|
if (usage != null) applyUsage$1(lmnrSpan, usage);
|
|
@@ -4903,12 +4950,12 @@ const applyUsage$1 = (lmnrSpan, usage) => {
|
|
|
4903
4950
|
let reasoningOutputTokens;
|
|
4904
4951
|
if (inputTokensDetails?.cached_tokens !== void 0 && inputTokensDetails?.cached_tokens !== null) cachedInputTokens = Number(inputTokensDetails.cached_tokens);
|
|
4905
4952
|
if (outputTokensDetails?.reasoning_tokens !== void 0 && outputTokensDetails?.reasoning_tokens !== null) reasoningOutputTokens = Number(outputTokensDetails.reasoning_tokens);
|
|
4906
|
-
if (inputTokens !== void 0 && inputTokens !== null) lmnrSpan.setAttribute(
|
|
4953
|
+
if (inputTokens !== void 0 && inputTokens !== null) lmnrSpan.setAttribute(require_dist.LaminarAttributes.INPUT_TOKEN_COUNT, Number(inputTokens));
|
|
4907
4954
|
if (cachedInputTokens !== void 0) lmnrSpan.setAttribute("gen_ai.usage.cache_read_input_tokens", cachedInputTokens);
|
|
4908
|
-
if (outputTokens !== void 0 && outputTokens !== null) lmnrSpan.setAttribute(
|
|
4955
|
+
if (outputTokens !== void 0 && outputTokens !== null) lmnrSpan.setAttribute(require_dist.LaminarAttributes.OUTPUT_TOKEN_COUNT, Number(outputTokens));
|
|
4909
4956
|
if (reasoningOutputTokens !== void 0) lmnrSpan.setAttribute("gen_ai.usage.reasoning_output_tokens", reasoningOutputTokens);
|
|
4910
|
-
if (totalTokens !== void 0 && totalTokens !== null) lmnrSpan.setAttribute(
|
|
4911
|
-
else if (inputTokens !== void 0 && inputTokens !== null && outputTokens !== void 0 && outputTokens !== null) lmnrSpan.setAttribute(
|
|
4957
|
+
if (totalTokens !== void 0 && totalTokens !== null) lmnrSpan.setAttribute(require_dist.LaminarAttributes.TOTAL_TOKEN_COUNT, Number(totalTokens));
|
|
4958
|
+
else if (inputTokens !== void 0 && inputTokens !== null && outputTokens !== void 0 && outputTokens !== null) lmnrSpan.setAttribute(require_dist.LaminarAttributes.TOTAL_TOKEN_COUNT, Number(inputTokens) + Number(outputTokens));
|
|
4912
4959
|
};
|
|
4913
4960
|
const responseToLlmData = (response) => {
|
|
4914
4961
|
if (response == null) return {};
|
|
@@ -5009,9 +5056,9 @@ const applyMcpSpanData = (lmnrSpan, spanData) => {
|
|
|
5009
5056
|
const applySpeechSpanData = (lmnrSpan, spanData) => {
|
|
5010
5057
|
const model = spanData?.model;
|
|
5011
5058
|
if (model) {
|
|
5012
|
-
lmnrSpan.setAttribute(
|
|
5013
|
-
lmnrSpan.setAttribute(
|
|
5014
|
-
lmnrSpan.setAttribute(
|
|
5059
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.REQUEST_MODEL, model);
|
|
5060
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.RESPONSE_MODEL, model);
|
|
5061
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.PROVIDER, "openai");
|
|
5015
5062
|
}
|
|
5016
5063
|
const inputText = spanData?.input;
|
|
5017
5064
|
if (inputText) setGenAiInputMessages(lmnrSpan, inputText);
|
|
@@ -5022,9 +5069,9 @@ const applySpeechSpanData = (lmnrSpan, spanData) => {
|
|
|
5022
5069
|
const applyTranscriptionSpanData = (lmnrSpan, spanData) => {
|
|
5023
5070
|
const model = spanData?.model;
|
|
5024
5071
|
if (model) {
|
|
5025
|
-
lmnrSpan.setAttribute(
|
|
5026
|
-
lmnrSpan.setAttribute(
|
|
5027
|
-
lmnrSpan.setAttribute(
|
|
5072
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.REQUEST_MODEL, model);
|
|
5073
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.RESPONSE_MODEL, model);
|
|
5074
|
+
lmnrSpan.setAttribute(require_dist.LaminarAttributes.PROVIDER, "openai");
|
|
5028
5075
|
}
|
|
5029
5076
|
const inputData = spanData?.input;
|
|
5030
5077
|
if (inputData) if (typeof inputData === "object" && !Array.isArray(inputData)) setGenAiInputMessages(lmnrSpan, inputData.data);
|
|
@@ -5040,7 +5087,7 @@ const applySpeechGroupSpanData = (lmnrSpan, spanData) => {
|
|
|
5040
5087
|
};
|
|
5041
5088
|
//#endregion
|
|
5042
5089
|
//#region src/opentelemetry-lib/instrumentation/openai-agents/processor.ts
|
|
5043
|
-
const logger$
|
|
5090
|
+
const logger$12 = require_dist.initializeLogger();
|
|
5044
5091
|
var LaminarAgentsTraceProcessor = class {
|
|
5045
5092
|
constructor() {
|
|
5046
5093
|
this.traces = /* @__PURE__ */ new Map();
|
|
@@ -5058,7 +5105,7 @@ var LaminarAgentsTraceProcessor = class {
|
|
|
5058
5105
|
} catch {}
|
|
5059
5106
|
this.applyTraceMetadata(state.rootSpan, agentsTrace);
|
|
5060
5107
|
} catch (e) {
|
|
5061
|
-
logger$
|
|
5108
|
+
logger$12.debug(`Error in onTraceStart: ${String(e)}`);
|
|
5062
5109
|
}
|
|
5063
5110
|
}
|
|
5064
5111
|
async onTraceEnd(agentsTrace) {
|
|
@@ -5107,7 +5154,7 @@ var LaminarAgentsTraceProcessor = class {
|
|
|
5107
5154
|
});
|
|
5108
5155
|
const key = span.spanId;
|
|
5109
5156
|
if (!key) {
|
|
5110
|
-
logger$
|
|
5157
|
+
logger$12.debug("Span missing spanId, cannot track");
|
|
5111
5158
|
try {
|
|
5112
5159
|
lmnrSpan.end();
|
|
5113
5160
|
} catch {}
|
|
@@ -5126,7 +5173,7 @@ var LaminarAgentsTraceProcessor = class {
|
|
|
5126
5173
|
activationContext
|
|
5127
5174
|
});
|
|
5128
5175
|
} catch (e) {
|
|
5129
|
-
logger$
|
|
5176
|
+
logger$12.debug(`Error in onSpanStart: ${String(e)}`);
|
|
5130
5177
|
if (lmnrSpan !== void 0) try {
|
|
5131
5178
|
lmnrSpan.end();
|
|
5132
5179
|
} catch {}
|
|
@@ -5244,7 +5291,7 @@ var LaminarAgentsTraceProcessor = class {
|
|
|
5244
5291
|
};
|
|
5245
5292
|
//#endregion
|
|
5246
5293
|
//#region src/opentelemetry-lib/instrumentation/openai-agents/index.ts
|
|
5247
|
-
const logger$
|
|
5294
|
+
const logger$11 = require_dist.initializeLogger();
|
|
5248
5295
|
const wrapGetResponse = (original) => function(request, ...rest) {
|
|
5249
5296
|
const systemInstructions = request?.systemInstructions;
|
|
5250
5297
|
return runWithSystemInstructions(systemInstructions, () => original.call(this, request, ...rest));
|
|
@@ -5264,7 +5311,7 @@ var OpenAIAgentsInstrumentation = class extends _opentelemetry_instrumentation.I
|
|
|
5264
5311
|
}
|
|
5265
5312
|
manuallyInstrument(agentsModule) {
|
|
5266
5313
|
if (!agentsModule) {
|
|
5267
|
-
logger$
|
|
5314
|
+
logger$11.debug("@openai/agents module not provided, skipping");
|
|
5268
5315
|
return;
|
|
5269
5316
|
}
|
|
5270
5317
|
this.registerProcessor(agentsModule);
|
|
@@ -5274,7 +5321,7 @@ var OpenAIAgentsInstrumentation = class extends _opentelemetry_instrumentation.I
|
|
|
5274
5321
|
if (this._processor !== void 0) return;
|
|
5275
5322
|
const addTraceProcessor = module.addTraceProcessor;
|
|
5276
5323
|
if (typeof addTraceProcessor !== "function") {
|
|
5277
|
-
logger$
|
|
5324
|
+
logger$11.debug("addTraceProcessor not found in @openai/agents module");
|
|
5278
5325
|
return;
|
|
5279
5326
|
}
|
|
5280
5327
|
try {
|
|
@@ -5282,7 +5329,7 @@ var OpenAIAgentsInstrumentation = class extends _opentelemetry_instrumentation.I
|
|
|
5282
5329
|
addTraceProcessor(processor);
|
|
5283
5330
|
this._processor = processor;
|
|
5284
5331
|
} catch (e) {
|
|
5285
|
-
logger$
|
|
5332
|
+
logger$11.debug(`Failed to register Laminar Agents processor: ${String(e)}`);
|
|
5286
5333
|
}
|
|
5287
5334
|
}
|
|
5288
5335
|
patchModel(module) {
|
|
@@ -5295,7 +5342,7 @@ var OpenAIAgentsInstrumentation = class extends _opentelemetry_instrumentation.I
|
|
|
5295
5342
|
try {
|
|
5296
5343
|
this._wrap(cls.prototype, method, wrapper);
|
|
5297
5344
|
} catch (e) {
|
|
5298
|
-
logger$
|
|
5345
|
+
logger$11.debug(`Failed to wrap ${method}: ${String(e)}`);
|
|
5299
5346
|
}
|
|
5300
5347
|
}
|
|
5301
5348
|
this._wrappedPrototypes.add(cls.prototype);
|
|
@@ -5401,7 +5448,7 @@ const getLangVersion = () => {
|
|
|
5401
5448
|
};
|
|
5402
5449
|
//#endregion
|
|
5403
5450
|
//#region src/opentelemetry-lib/tracing/exporter.ts
|
|
5404
|
-
const logger$
|
|
5451
|
+
const logger$10 = require_dist.initializeLogger();
|
|
5405
5452
|
var LaminarSpanExporter = class {
|
|
5406
5453
|
constructor(options = {}) {
|
|
5407
5454
|
let url = options.baseUrl ?? process?.env?.LMNR_BASE_URL;
|
|
@@ -5413,15 +5460,15 @@ var LaminarSpanExporter = class {
|
|
|
5413
5460
|
headers = forceHttp ? { "Authorization": `Bearer ${key}` } : { "authorization": `Bearer ${key}` };
|
|
5414
5461
|
if (!url) url = "https://api.lmnr.ai";
|
|
5415
5462
|
} else {
|
|
5416
|
-
const otelHeaders =
|
|
5417
|
-
if (otelHeaders) headers =
|
|
5418
|
-
const otelEndpoint =
|
|
5463
|
+
const otelHeaders = require_dist.getOtelEnvVar("HEADERS");
|
|
5464
|
+
if (otelHeaders) headers = require_dist.parseOtelHeaders(otelHeaders);
|
|
5465
|
+
const otelEndpoint = require_dist.getOtelEnvVar("ENDPOINT");
|
|
5419
5466
|
if (otelEndpoint && !url) {
|
|
5420
5467
|
url = otelEndpoint;
|
|
5421
|
-
const otelProtocol =
|
|
5468
|
+
const otelProtocol = require_dist.getOtelEnvVar("PROTOCOL") || "grpc/protobuf";
|
|
5422
5469
|
const otelExporter = process?.env?.OTEL_EXPORTER;
|
|
5423
5470
|
forceHttp = otelProtocol === "http/protobuf" || otelProtocol === "http/json" || otelExporter === "otlp_http";
|
|
5424
|
-
} else if (otelEndpoint && url) logger$
|
|
5471
|
+
} else if (otelEndpoint && url) logger$10.warn("OTEL_ENDPOINT is set, but Laminar base URL is also set. Ignoring OTEL_ENDPOINT.");
|
|
5425
5472
|
}
|
|
5426
5473
|
if (!url) throw new Error("Laminar base URL is not set and OTEL_ENDPOINT is not set. Please either\n- set the LMNR_BASE_URL environment variable\n- set the OTEL_ENDPOINT environment variable (if you are not using a Laminar API key)\n- pass the baseUrl parameter to Laminar.initialize");
|
|
5427
5474
|
if (!port) port = url.match(/:\d{1,5}$/g) ? parseInt(url.match(/:\d{1,5}$/g)[0].slice(1)) : forceHttp ? 443 : 8443;
|
|
@@ -5475,7 +5522,7 @@ var LaminarSpanProcessor = class LaminarSpanProcessor {
|
|
|
5475
5522
|
constructor(options = {}) {
|
|
5476
5523
|
this._spanIdToPath = /* @__PURE__ */ new Map();
|
|
5477
5524
|
this._spanIdLists = /* @__PURE__ */ new Map();
|
|
5478
|
-
this.logger =
|
|
5525
|
+
this.logger = require_dist.initializeLogger();
|
|
5479
5526
|
if (options.spanProcessor && options.spanProcessor instanceof LaminarSpanProcessor) {
|
|
5480
5527
|
this.instance = options.spanProcessor.instance;
|
|
5481
5528
|
this._spanIdToPath = options.spanProcessor._spanIdToPath;
|
|
@@ -5497,37 +5544,37 @@ var LaminarSpanProcessor = class LaminarSpanProcessor {
|
|
|
5497
5544
|
}
|
|
5498
5545
|
onStart(spanArg, parentContext) {
|
|
5499
5546
|
const span = spanArg;
|
|
5500
|
-
const parentPathFromAttribute = span.attributes?.[
|
|
5501
|
-
const parentIdsPathFromAttribute = span.attributes?.[
|
|
5547
|
+
const parentPathFromAttribute = span.attributes?.[require_dist.PARENT_SPAN_PATH];
|
|
5548
|
+
const parentIdsPathFromAttribute = span.attributes?.[require_dist.PARENT_SPAN_IDS_PATH];
|
|
5502
5549
|
const parentSpanId = getParentSpanId(span);
|
|
5503
5550
|
const parentSpanPath = parentPathFromAttribute ?? (parentSpanId !== void 0 ? this._spanIdToPath.get(parentSpanId) : void 0);
|
|
5504
5551
|
const spanId = span.spanContext().spanId;
|
|
5505
5552
|
const parentSpanIdsPath = parentIdsPathFromAttribute ?? (parentSpanId ? this._spanIdLists.get(parentSpanId) : []);
|
|
5506
5553
|
const spanPath = parentSpanPath ? [...parentSpanPath, span.name] : [span.name];
|
|
5507
|
-
const spanIdUuid =
|
|
5554
|
+
const spanIdUuid = require_dist.otelSpanIdToUUID(spanId);
|
|
5508
5555
|
const spanIdsPath = parentSpanIdsPath ? [...parentSpanIdsPath, spanIdUuid] : [spanIdUuid];
|
|
5509
|
-
span.setAttribute(
|
|
5556
|
+
span.setAttribute(require_dist.SPAN_IDS_PATH, spanIdsPath);
|
|
5510
5557
|
this._spanIdLists.set(spanId, spanIdsPath);
|
|
5511
|
-
span.setAttribute(
|
|
5558
|
+
span.setAttribute(require_dist.SPAN_PATH, spanPath);
|
|
5512
5559
|
_opentelemetry_api.context.active().setValue(CONTEXT_SPAN_PATH_KEY, spanPath);
|
|
5513
5560
|
this._spanIdToPath.set(spanId, spanPath);
|
|
5514
|
-
span.setAttribute(
|
|
5515
|
-
span.setAttribute(
|
|
5561
|
+
span.setAttribute(require_dist.SPAN_INSTRUMENTATION_SOURCE, "javascript");
|
|
5562
|
+
span.setAttribute(require_dist.SPAN_SDK_VERSION, require_dist.version);
|
|
5516
5563
|
const langVersion = getLangVersion();
|
|
5517
|
-
if (langVersion) span.setAttribute(
|
|
5564
|
+
if (langVersion) span.setAttribute(require_dist.SPAN_LANGUAGE_VERSION, langVersion);
|
|
5518
5565
|
const globalMetadata = LaminarContextManager.getGlobalMetadata();
|
|
5519
|
-
if (globalMetadata && Object.keys(globalMetadata).length > 0) span.setAttributes(
|
|
5566
|
+
if (globalMetadata && Object.keys(globalMetadata).length > 0) span.setAttributes(require_dist.metadataToAttributes(globalMetadata));
|
|
5520
5567
|
const associationProperties = _opentelemetry_api.context.active().getValue(ASSOCIATION_PROPERTIES_KEY);
|
|
5521
|
-
if (associationProperties) for (const [key, value] of Object.entries(associationProperties)) if (Object.keys(
|
|
5568
|
+
if (associationProperties) for (const [key, value] of Object.entries(associationProperties)) if (Object.keys(require_dist.ASSOCIATION_PROPERTIES_OVERRIDES).includes(key)) span.setAttribute(require_dist.ASSOCIATION_PROPERTIES_OVERRIDES[key], value);
|
|
5522
5569
|
else if (key === "tracing_level") span.setAttribute("lmnr.internal.tracing_level", value);
|
|
5523
5570
|
else if (key === "metadata" && typeof value === "object" && value !== null) {
|
|
5524
|
-
const metadataAttrs =
|
|
5571
|
+
const metadataAttrs = require_dist.metadataToAttributes(value);
|
|
5525
5572
|
span.setAttributes(metadataAttrs);
|
|
5526
|
-
} else if (key === "userId") span.setAttribute(
|
|
5527
|
-
else if (key === "sessionId") span.setAttribute(
|
|
5528
|
-
else if (key === "traceType") span.setAttribute(
|
|
5573
|
+
} else if (key === "userId") span.setAttribute(require_dist.USER_ID, value);
|
|
5574
|
+
else if (key === "sessionId") span.setAttribute(require_dist.SESSION_ID, value);
|
|
5575
|
+
else if (key === "traceType") span.setAttribute(require_dist.TRACE_TYPE, value);
|
|
5529
5576
|
else if (key === "tracingLevel") span.setAttribute("lmnr.internal.tracing_level", value);
|
|
5530
|
-
else span.setAttribute(`${
|
|
5577
|
+
else span.setAttribute(`${require_dist.ASSOCIATION_PROPERTIES}.${key}`, value);
|
|
5531
5578
|
makeSpanOtelV2Compatible(span);
|
|
5532
5579
|
if (parentSpanId === void 0) this.recordDebugTraceId(span);
|
|
5533
5580
|
this.instance.onStart(span, parentContext);
|
|
@@ -5541,7 +5588,7 @@ var LaminarSpanProcessor = class LaminarSpanProcessor {
|
|
|
5541
5588
|
try {
|
|
5542
5589
|
const runtime = getRuntime();
|
|
5543
5590
|
if (runtime === null) return;
|
|
5544
|
-
runtime.recordTraceId(
|
|
5591
|
+
runtime.recordTraceId(require_dist.otelTraceIdToUUID(span.spanContext().traceId));
|
|
5545
5592
|
} catch (e) {
|
|
5546
5593
|
this.logger.debug(`Failed to record debug trace id: ${String(e)}`);
|
|
5547
5594
|
}
|
|
@@ -5582,7 +5629,7 @@ var LaminarSpanProcessor = class LaminarSpanProcessor {
|
|
|
5582
5629
|
};
|
|
5583
5630
|
//#endregion
|
|
5584
5631
|
//#region src/opentelemetry-lib/instrumentation/temporal/helpers.ts
|
|
5585
|
-
const logger$
|
|
5632
|
+
const logger$9 = require_dist.initializeLogger();
|
|
5586
5633
|
const _enc = new TextEncoder();
|
|
5587
5634
|
const _dec = new TextDecoder();
|
|
5588
5635
|
const encodePayload = (value) => ({
|
|
@@ -5634,13 +5681,13 @@ const restoreContextFromHeaders = (headers) => {
|
|
|
5634
5681
|
if (!headers) return void 0;
|
|
5635
5682
|
const laminarRaw = decodePayload(headers[require_consts.LAMINAR_SPAN_CONTEXT_HEADER]);
|
|
5636
5683
|
if (laminarRaw) try {
|
|
5637
|
-
const ctx =
|
|
5684
|
+
const ctx = require_dist.deserializeLaminarSpanContext(laminarRaw);
|
|
5638
5685
|
return {
|
|
5639
5686
|
laminarCtx: ctx,
|
|
5640
5687
|
otelContext: pushLaminarContext(ctx)
|
|
5641
5688
|
};
|
|
5642
5689
|
} catch (e) {
|
|
5643
|
-
logger$
|
|
5690
|
+
logger$9.warn(`[Laminar] Could not restore ${require_consts.LAMINAR_SPAN_CONTEXT_HEADER}: ${require_dist.errorMessage(e)}`);
|
|
5644
5691
|
}
|
|
5645
5692
|
const traceparent = decodePayload(headers[require_consts.TRACEPARENT_HEADER]);
|
|
5646
5693
|
if (traceparent) {
|
|
@@ -5649,8 +5696,8 @@ const restoreContextFromHeaders = (headers) => {
|
|
|
5649
5696
|
const [, traceHex, spanHex] = parts;
|
|
5650
5697
|
try {
|
|
5651
5698
|
const ctx = {
|
|
5652
|
-
traceId:
|
|
5653
|
-
spanId:
|
|
5699
|
+
traceId: require_dist.otelTraceIdToUUID(traceHex),
|
|
5700
|
+
spanId: require_dist.otelSpanIdToUUID(spanHex),
|
|
5654
5701
|
isRemote: true
|
|
5655
5702
|
};
|
|
5656
5703
|
return {
|
|
@@ -5658,7 +5705,7 @@ const restoreContextFromHeaders = (headers) => {
|
|
|
5658
5705
|
otelContext: pushLaminarContext(ctx)
|
|
5659
5706
|
};
|
|
5660
5707
|
} catch (e) {
|
|
5661
|
-
logger$
|
|
5708
|
+
logger$9.warn(`[Laminar] Could not restore traceparent: ${require_dist.errorMessage(e)}`);
|
|
5662
5709
|
}
|
|
5663
5710
|
}
|
|
5664
5711
|
}
|
|
@@ -5668,7 +5715,7 @@ const restoreContextFromHeaders = (headers) => {
|
|
|
5668
5715
|
* return the enriched OTel `Context` that was pushed.
|
|
5669
5716
|
*/
|
|
5670
5717
|
const pushLaminarContext = (laminarCtx) => {
|
|
5671
|
-
const otelCtx =
|
|
5718
|
+
const otelCtx = require_dist.tryToOtelSpanContext(laminarCtx);
|
|
5672
5719
|
otelCtx.isRemote = true;
|
|
5673
5720
|
const processor = getSpanProcessor();
|
|
5674
5721
|
if (processor instanceof LaminarSpanProcessor && laminarCtx.spanPath && laminarCtx.spanIdsPath) processor.setParentPathInfo(otelCtx.spanId, laminarCtx.spanPath, laminarCtx.spanIdsPath);
|
|
@@ -5837,7 +5884,7 @@ var ActivityInboundInterceptor = class {
|
|
|
5837
5884
|
if (this.recordActivityOutput) try {
|
|
5838
5885
|
span.setOutput(res);
|
|
5839
5886
|
} catch (e) {
|
|
5840
|
-
this.logger.debug(`failed to set output to activity span: ${
|
|
5887
|
+
this.logger.debug(`failed to set output to activity span: ${require_dist.errorMessage(e)}`);
|
|
5841
5888
|
}
|
|
5842
5889
|
return res;
|
|
5843
5890
|
}, true);
|
|
@@ -5846,13 +5893,13 @@ var ActivityInboundInterceptor = class {
|
|
|
5846
5893
|
this.recordActivityArgs = options.recordActivityArgs ?? true;
|
|
5847
5894
|
this.recordActivityOutput = options.recordActivityOutput ?? true;
|
|
5848
5895
|
this.activityType = activityContext?.info?.activityType;
|
|
5849
|
-
this.logger =
|
|
5896
|
+
this.logger = require_dist.initializeLogger();
|
|
5850
5897
|
}
|
|
5851
5898
|
};
|
|
5852
5899
|
const ActivityInterceptorFactory = (options) => (ctx) => ({ inbound: new ActivityInboundInterceptor(options, ctx) });
|
|
5853
5900
|
//#endregion
|
|
5854
5901
|
//#region src/opentelemetry-lib/instrumentation/temporal/workflow-span.ts
|
|
5855
|
-
const logger$
|
|
5902
|
+
const logger$8 = require_dist.initializeLogger();
|
|
5856
5903
|
const _patchedWorkflowClients = /* @__PURE__ */ new WeakSet();
|
|
5857
5904
|
const workflowName = (args) => {
|
|
5858
5905
|
const wf = args[0];
|
|
@@ -5876,7 +5923,7 @@ const wrapHandle = (handle, span) => {
|
|
|
5876
5923
|
try {
|
|
5877
5924
|
return Laminar.serializeLaminarSpanContext(span) ?? void 0;
|
|
5878
5925
|
} catch (e) {
|
|
5879
|
-
logger$
|
|
5926
|
+
logger$8.debug(`failed to derive workflow child span parent: ${require_dist.errorMessage(e)}`);
|
|
5880
5927
|
return;
|
|
5881
5928
|
}
|
|
5882
5929
|
};
|
|
@@ -5888,7 +5935,7 @@ const wrapHandle = (handle, span) => {
|
|
|
5888
5935
|
try {
|
|
5889
5936
|
span.setOutput(res);
|
|
5890
5937
|
} catch (e) {
|
|
5891
|
-
logger$
|
|
5938
|
+
logger$8.debug(`failed to set workflow span output: ${require_dist.errorMessage(e)}`);
|
|
5892
5939
|
}
|
|
5893
5940
|
});
|
|
5894
5941
|
return res;
|
|
@@ -5965,7 +6012,7 @@ const patchWorkflowClient = (clientModule) => {
|
|
|
5965
6012
|
try {
|
|
5966
6013
|
span.setOutput(res);
|
|
5967
6014
|
} catch (e) {
|
|
5968
|
-
logger$
|
|
6015
|
+
logger$8.debug(`failed to set workflow span output: ${require_dist.errorMessage(e)}`);
|
|
5969
6016
|
}
|
|
5970
6017
|
span.end();
|
|
5971
6018
|
return res;
|
|
@@ -6049,14 +6096,14 @@ const patchWorkflowClient = (clientModule) => {
|
|
|
6049
6096
|
* const client = new temporalClient.Client({ ... });
|
|
6050
6097
|
* ```
|
|
6051
6098
|
*/
|
|
6052
|
-
const logger$
|
|
6099
|
+
const logger$7 = require_dist.initializeLogger();
|
|
6053
6100
|
const _patchedWorkerModules = /* @__PURE__ */ new WeakSet();
|
|
6054
6101
|
const _patchedClientModules = /* @__PURE__ */ new WeakSet();
|
|
6055
6102
|
let _warnedWorkflowBundleOnce = false;
|
|
6056
6103
|
const warnWorkflowBundleOnce = () => {
|
|
6057
6104
|
if (_warnedWorkflowBundleOnce) return;
|
|
6058
6105
|
_warnedWorkflowBundleOnce = true;
|
|
6059
|
-
logger$
|
|
6106
|
+
logger$7.warn("[Laminar] Temporal Worker.create was called with a pre-built `workflowBundle`; Temporal ignores `interceptors.workflowModules` in that case, so Laminar's workflow interceptor cannot be auto-injected. Trace context from workflow start will NOT propagate to activities or child workflows scheduled inside the workflow. Register the interceptor at bundle time: bundleWorkflowCode({ workflowInterceptorModules: [require.resolve('@lmnr-ai/lmnr/temporal-workflow-interceptors')], ... }).");
|
|
6060
6107
|
};
|
|
6061
6108
|
/**
|
|
6062
6109
|
* Patch a `@temporalio/worker` module object so that every `Worker.create()`
|
|
@@ -6127,7 +6174,7 @@ const LaminarTemporalInterceptors = {
|
|
|
6127
6174
|
};
|
|
6128
6175
|
//#endregion
|
|
6129
6176
|
//#region src/opentelemetry-lib/tracing/instrumentations.ts
|
|
6130
|
-
const logger$
|
|
6177
|
+
const logger$6 = require_dist.initializeLogger();
|
|
6131
6178
|
/**
|
|
6132
6179
|
* Initialize and return Laminar instrumentations.
|
|
6133
6180
|
* Useful to use with libraries that initialize tracing and can register passed
|
|
@@ -6238,7 +6285,7 @@ const manuallyInitInstrumentations = (client, instrumentModules, suppressContent
|
|
|
6238
6285
|
instrumentations.push(anthropicInstrumentation);
|
|
6239
6286
|
anthropicInstrumentation.manuallyInstrument(instrumentModules.anthropic);
|
|
6240
6287
|
}
|
|
6241
|
-
if (instrumentModules?.azureOpenAI) logger$
|
|
6288
|
+
if (instrumentModules?.azureOpenAI) logger$6.warn("Azure OpenAI instrumentation is no longer supported. Not enabling any instrumentation.");
|
|
6242
6289
|
if (instrumentModules?.cohere) {
|
|
6243
6290
|
const cohereInstrumentation = new _traceloop_instrumentation_cohere.CohereInstrumentation({ traceContent: !suppressContentTracing });
|
|
6244
6291
|
instrumentations.push(cohereInstrumentation);
|
|
@@ -6269,7 +6316,7 @@ const manuallyInitInstrumentations = (client, instrumentModules, suppressContent
|
|
|
6269
6316
|
instrumentations.push(langchainInstrumentation);
|
|
6270
6317
|
langchainInstrumentation.manuallyInstrument(instrumentModules.langchain);
|
|
6271
6318
|
}
|
|
6272
|
-
if (instrumentModules?.llamaIndex) logger$
|
|
6319
|
+
if (instrumentModules?.llamaIndex) logger$6.warn("Llamaindex JS is deprecated. Not enabling any instrumentation.");
|
|
6273
6320
|
if (instrumentModules?.chromadb) {
|
|
6274
6321
|
const chromadbInstrumentation = new _traceloop_instrumentation_chromadb.ChromaDBInstrumentation({ traceContent: !suppressContentTracing });
|
|
6275
6322
|
instrumentations.push(chromadbInstrumentation);
|
|
@@ -6379,7 +6426,7 @@ const isGlobalContextManagerConfigured = () => {
|
|
|
6379
6426
|
};
|
|
6380
6427
|
//#endregion
|
|
6381
6428
|
//#region src/opentelemetry-lib/tracing/index.ts
|
|
6382
|
-
const logger$
|
|
6429
|
+
const logger$5 = require_dist.initializeLogger();
|
|
6383
6430
|
let spanProcessor;
|
|
6384
6431
|
let tracerProvider;
|
|
6385
6432
|
let _baseHttpUrl = "https://api.lmnr.ai:443";
|
|
@@ -6427,10 +6474,10 @@ const startTracing = (options) => {
|
|
|
6427
6474
|
const contextManager = new _opentelemetry_context_async_hooks.AsyncLocalStorageContextManager();
|
|
6428
6475
|
contextManager.enable();
|
|
6429
6476
|
_opentelemetry_api.context.setGlobalContextManager(contextManager);
|
|
6430
|
-
logger$
|
|
6477
|
+
logger$5.debug("Laminar set global OTel Context Manager");
|
|
6431
6478
|
}
|
|
6432
|
-
logger$
|
|
6433
|
-
logger$
|
|
6479
|
+
logger$5.debug("Global OTel Context Manager exists");
|
|
6480
|
+
logger$5.debug(`Laminar registering ${instrumentations.length} instrumentations`);
|
|
6434
6481
|
(0, _opentelemetry_instrumentation.registerInstrumentations)({
|
|
6435
6482
|
instrumentations,
|
|
6436
6483
|
tracerProvider: newProvider
|
|
@@ -6541,17 +6588,17 @@ const _resetConfiguration = () => {
|
|
|
6541
6588
|
};
|
|
6542
6589
|
//#endregion
|
|
6543
6590
|
//#region src/opentelemetry-lib/tracing/decorators.ts
|
|
6544
|
-
const logger$
|
|
6591
|
+
const logger$4 = require_dist.initializeLogger();
|
|
6545
6592
|
function observeBase({ name, contextProperties, spanAttributes, input, ignoreInput, ignoreOutput, inputParameters, suppressTracing: shouldSuppressTracing, parentSpanContext }, fn, thisArg, ...args) {
|
|
6546
6593
|
let entityContext = LaminarContextManager.getContext();
|
|
6547
6594
|
if (shouldSuppressTracing) entityContext = (0, _opentelemetry_core.suppressTracing)(entityContext);
|
|
6548
6595
|
if (parentSpanContext) try {
|
|
6549
|
-
const laminarContext = typeof parentSpanContext === "string" ?
|
|
6596
|
+
const laminarContext = typeof parentSpanContext === "string" ? require_dist.deserializeLaminarSpanContext(parentSpanContext) : parentSpanContext;
|
|
6550
6597
|
Laminar._armDebugRuntimeFromContext(laminarContext.debug);
|
|
6551
|
-
const spanContext =
|
|
6598
|
+
const spanContext = require_dist.tryToOtelSpanContext(laminarContext);
|
|
6552
6599
|
entityContext = _opentelemetry_api.trace.setSpan(entityContext, _opentelemetry_api.trace.wrapSpanContext(spanContext));
|
|
6553
6600
|
} catch (e) {
|
|
6554
|
-
logger$
|
|
6601
|
+
logger$4.warn("Failed to parse parent span context: " + require_dist.errorMessage(e));
|
|
6555
6602
|
}
|
|
6556
6603
|
try {
|
|
6557
6604
|
if (contextProperties && Object.keys(contextProperties).length > 0) {
|
|
@@ -6562,16 +6609,16 @@ function observeBase({ name, contextProperties, spanAttributes, input, ignoreInp
|
|
|
6562
6609
|
});
|
|
6563
6610
|
}
|
|
6564
6611
|
} catch (e) {
|
|
6565
|
-
logger$
|
|
6612
|
+
logger$4.warn("Failed to set context properties: " + require_dist.errorMessage(e));
|
|
6566
6613
|
}
|
|
6567
6614
|
return _opentelemetry_api.context.with(entityContext, () => getTracer().startActiveSpan(name, { attributes: spanAttributes }, entityContext, (span) => {
|
|
6568
6615
|
if (shouldSendTraces() && !ignoreInput) try {
|
|
6569
6616
|
const spanInput = inputParameters ?? args;
|
|
6570
|
-
if (input !== void 0) span.setAttribute(
|
|
6571
|
-
else if (spanInput.length === 1 && typeof spanInput[0] === "object" && !(spanInput[0] instanceof Map)) span.setAttribute(
|
|
6572
|
-
else span.setAttribute(
|
|
6617
|
+
if (input !== void 0) span.setAttribute(require_dist.SPAN_INPUT, typeof input === "string" ? input : serialize(input));
|
|
6618
|
+
else if (spanInput.length === 1 && typeof spanInput[0] === "object" && !(spanInput[0] instanceof Map)) span.setAttribute(require_dist.SPAN_INPUT, typeof spanInput[0] === "string" ? spanInput[0] : serialize(spanInput[0]));
|
|
6619
|
+
else span.setAttribute(require_dist.SPAN_INPUT, serialize(spanInput.length > 0 ? spanInput : {}));
|
|
6573
6620
|
} catch (error) {
|
|
6574
|
-
logger$
|
|
6621
|
+
logger$4.warn("Failed to serialize input: " + require_dist.errorMessage(error));
|
|
6575
6622
|
}
|
|
6576
6623
|
let res;
|
|
6577
6624
|
try {
|
|
@@ -6581,7 +6628,7 @@ function observeBase({ name, contextProperties, spanAttributes, input, ignoreInp
|
|
|
6581
6628
|
span.recordException(error);
|
|
6582
6629
|
span.end();
|
|
6583
6630
|
} catch (error) {
|
|
6584
|
-
logger$
|
|
6631
|
+
logger$4.warn("Failed to record exception and end span: " + require_dist.errorMessage(error));
|
|
6585
6632
|
}
|
|
6586
6633
|
throw error;
|
|
6587
6634
|
}
|
|
@@ -6590,18 +6637,18 @@ function observeBase({ name, contextProperties, spanAttributes, input, ignoreInp
|
|
|
6590
6637
|
try {
|
|
6591
6638
|
streamInfo = getStream(resolvedRes);
|
|
6592
6639
|
} catch (error) {
|
|
6593
|
-
logger$
|
|
6640
|
+
logger$4.warn("Failed to get stream info: " + require_dist.errorMessage(error));
|
|
6594
6641
|
}
|
|
6595
6642
|
if (streamInfo.type !== null) return handleStreamResult(resolvedRes, streamInfo, span, ignoreOutput, serialize);
|
|
6596
6643
|
try {
|
|
6597
|
-
if (shouldSendTraces() && !ignoreOutput) span.setAttribute(
|
|
6644
|
+
if (shouldSendTraces() && !ignoreOutput) span.setAttribute(require_dist.SPAN_OUTPUT, serialize(resolvedRes));
|
|
6598
6645
|
} catch (error) {
|
|
6599
|
-
logger$
|
|
6646
|
+
logger$4.warn("Failed to serialize async output: " + require_dist.errorMessage(error));
|
|
6600
6647
|
} finally {
|
|
6601
6648
|
try {
|
|
6602
6649
|
span.end();
|
|
6603
6650
|
} catch (error) {
|
|
6604
|
-
logger$
|
|
6651
|
+
logger$4.warn("Failed to end span: " + require_dist.errorMessage(error));
|
|
6605
6652
|
}
|
|
6606
6653
|
}
|
|
6607
6654
|
return resolvedRes;
|
|
@@ -6610,7 +6657,7 @@ function observeBase({ name, contextProperties, spanAttributes, input, ignoreInp
|
|
|
6610
6657
|
span.recordException(error);
|
|
6611
6658
|
span.end();
|
|
6612
6659
|
} catch (error) {
|
|
6613
|
-
logger$
|
|
6660
|
+
logger$4.warn("Failed to record exception and end span: " + require_dist.errorMessage(error));
|
|
6614
6661
|
}
|
|
6615
6662
|
throw error;
|
|
6616
6663
|
});
|
|
@@ -6618,18 +6665,18 @@ function observeBase({ name, contextProperties, spanAttributes, input, ignoreInp
|
|
|
6618
6665
|
try {
|
|
6619
6666
|
streamInfo = getStream(res);
|
|
6620
6667
|
} catch (error) {
|
|
6621
|
-
logger$
|
|
6668
|
+
logger$4.warn("Failed to get stream info: " + require_dist.errorMessage(error));
|
|
6622
6669
|
}
|
|
6623
6670
|
if (streamInfo.type !== null) return handleStreamResult(res, streamInfo, span, ignoreOutput, serialize);
|
|
6624
6671
|
try {
|
|
6625
|
-
if (shouldSendTraces() && !ignoreOutput) span.setAttribute(
|
|
6672
|
+
if (shouldSendTraces() && !ignoreOutput) span.setAttribute(require_dist.SPAN_OUTPUT, typeof res === "string" ? res : serialize(res));
|
|
6626
6673
|
} catch (error) {
|
|
6627
|
-
logger$
|
|
6674
|
+
logger$4.warn("Failed to serialize output: " + require_dist.errorMessage(error));
|
|
6628
6675
|
} finally {
|
|
6629
6676
|
try {
|
|
6630
6677
|
span.end();
|
|
6631
6678
|
} catch (error) {
|
|
6632
|
-
logger$
|
|
6679
|
+
logger$4.warn("Failed to end span: " + require_dist.errorMessage(error));
|
|
6633
6680
|
}
|
|
6634
6681
|
}
|
|
6635
6682
|
return res;
|
|
@@ -6653,7 +6700,7 @@ const normalizePayload = (payload, seen) => {
|
|
|
6653
6700
|
const serialize = (payload) => JSON.stringify(normalizePayload(payload, /* @__PURE__ */ new WeakSet()));
|
|
6654
6701
|
//#endregion
|
|
6655
6702
|
//#region src/decorators.ts
|
|
6656
|
-
const logger$
|
|
6703
|
+
const logger$3 = require_dist.initializeLogger();
|
|
6657
6704
|
/**
|
|
6658
6705
|
* The main decorator entrypoint for Laminar. This is used to wrap
|
|
6659
6706
|
* functions and methods to create spans.
|
|
@@ -6759,14 +6806,14 @@ const buildContextProperties = (options) => {
|
|
|
6759
6806
|
let parentUserId;
|
|
6760
6807
|
let parentSessionId;
|
|
6761
6808
|
if (parentSpanContext) try {
|
|
6762
|
-
const laminarContext = typeof parentSpanContext === "string" ?
|
|
6809
|
+
const laminarContext = typeof parentSpanContext === "string" ? require_dist.deserializeLaminarSpanContext(parentSpanContext) : parentSpanContext;
|
|
6763
6810
|
parentMetadata = laminarContext.metadata;
|
|
6764
6811
|
parentTraceType = laminarContext.traceType;
|
|
6765
6812
|
parentTracingLevel = laminarContext.tracingLevel;
|
|
6766
6813
|
parentUserId = laminarContext.userId;
|
|
6767
6814
|
parentSessionId = laminarContext.sessionId;
|
|
6768
6815
|
} catch (e) {
|
|
6769
|
-
logger$
|
|
6816
|
+
logger$3.warn("Failed to parse parent span context: " + require_dist.errorMessage(e));
|
|
6770
6817
|
}
|
|
6771
6818
|
const contextProperties = {};
|
|
6772
6819
|
const sessionIdValue = options.sessionId ?? parentSessionId ?? ctxAssociationProperties.sessionId;
|
|
@@ -6796,14 +6843,14 @@ const buildContextProperties = (options) => {
|
|
|
6796
6843
|
*/
|
|
6797
6844
|
const buildSpanAttributes = (options) => {
|
|
6798
6845
|
const spanAttributes = {};
|
|
6799
|
-
if (options.spanType) spanAttributes[
|
|
6800
|
-
if (options.tags) spanAttributes[`${
|
|
6846
|
+
if (options.spanType) spanAttributes[require_dist.SPAN_TYPE] = options.spanType;
|
|
6847
|
+
if (options.tags) spanAttributes[`${require_dist.ASSOCIATION_PROPERTIES}.tags`] = Array.from(new Set(options.tags));
|
|
6801
6848
|
if (options.parentSpanContext) try {
|
|
6802
|
-
const laminarContext = typeof options.parentSpanContext === "string" ?
|
|
6803
|
-
if (laminarContext.spanPath) spanAttributes[
|
|
6804
|
-
if (laminarContext.spanIdsPath) spanAttributes[
|
|
6849
|
+
const laminarContext = typeof options.parentSpanContext === "string" ? require_dist.deserializeLaminarSpanContext(options.parentSpanContext) : options.parentSpanContext;
|
|
6850
|
+
if (laminarContext.spanPath) spanAttributes[require_dist.PARENT_SPAN_PATH] = laminarContext.spanPath;
|
|
6851
|
+
if (laminarContext.spanIdsPath) spanAttributes[require_dist.PARENT_SPAN_IDS_PATH] = laminarContext.spanIdsPath;
|
|
6805
6852
|
} catch (e) {
|
|
6806
|
-
logger$
|
|
6853
|
+
logger$3.warn("Failed to parse parent span context for span attributes: " + require_dist.errorMessage(e));
|
|
6807
6854
|
}
|
|
6808
6855
|
return spanAttributes;
|
|
6809
6856
|
};
|
|
@@ -6935,12 +6982,12 @@ function observeExperimentalDecorator(config) {
|
|
|
6935
6982
|
}
|
|
6936
6983
|
//#endregion
|
|
6937
6984
|
//#region src/evaluations.ts
|
|
6938
|
-
|
|
6985
|
+
require_dist.loadEnv();
|
|
6939
6986
|
const DEFAULT_CONCURRENCY = 5;
|
|
6940
6987
|
const MAX_EXPORT_BATCH_SIZE = 64;
|
|
6941
|
-
const logger$
|
|
6988
|
+
const logger$2 = require_dist.initializeLogger();
|
|
6942
6989
|
const getEvaluationUrl = (projectId, evaluationId, baseUrl, frontendPort) => {
|
|
6943
|
-
return `${
|
|
6990
|
+
return `${require_dist.getFrontendUrl(baseUrl, frontendPort)}/project/${projectId}/evaluations/${evaluationId}`;
|
|
6944
6991
|
};
|
|
6945
6992
|
const getAverageScores = (results) => {
|
|
6946
6993
|
const perScoreValues = {};
|
|
@@ -7011,7 +7058,7 @@ var Evaluation = class {
|
|
|
7011
7058
|
this.name = name;
|
|
7012
7059
|
if (config) {
|
|
7013
7060
|
if (config.concurrencyLimit !== void 0 && config.concurrencyLimit < 1) {
|
|
7014
|
-
logger$
|
|
7061
|
+
logger$2.warn(`concurrencyLimit must be greater than 0. Setting to default of ${DEFAULT_CONCURRENCY}`);
|
|
7015
7062
|
this.concurrencyLimit = DEFAULT_CONCURRENCY;
|
|
7016
7063
|
} else this.concurrencyLimit = config.concurrencyLimit ?? DEFAULT_CONCURRENCY;
|
|
7017
7064
|
this.traceDisableBatch = config.traceDisableBatch ?? false;
|
|
@@ -7023,7 +7070,7 @@ var Evaluation = class {
|
|
|
7023
7070
|
baseUrl: Laminar.getHttpUrl(),
|
|
7024
7071
|
projectApiKey: Laminar.getProjectApiKey()
|
|
7025
7072
|
});
|
|
7026
|
-
if (config?.projectApiKey && config.projectApiKey !== Laminar.getProjectApiKey()) logger$
|
|
7073
|
+
if (config?.projectApiKey && config.projectApiKey !== Laminar.getProjectApiKey()) logger$2.warn("Laminar was already initialized with a different project API key. Ignoring the project API key from the evaluation config.");
|
|
7027
7074
|
return;
|
|
7028
7075
|
}
|
|
7029
7076
|
const key = config?.projectApiKey ?? process.env.LMNR_PROJECT_API_KEY;
|
|
@@ -7055,9 +7102,9 @@ var Evaluation = class {
|
|
|
7055
7102
|
if (!this.data.id) try {
|
|
7056
7103
|
const datasets = await this.client.datasets.getDatasetByName(this.data.name);
|
|
7057
7104
|
if (datasets.length > 0) this.data.id = datasets[0].id;
|
|
7058
|
-
else logger$
|
|
7105
|
+
else logger$2.warn(`Dataset ${this.data.name} not found`);
|
|
7059
7106
|
} catch (error) {
|
|
7060
|
-
logger$
|
|
7107
|
+
logger$2.warn(`Error getting dataset ${this.data.name}: ` + require_dist.errorMessage(error));
|
|
7061
7108
|
}
|
|
7062
7109
|
}
|
|
7063
7110
|
let resultDatapoints;
|
|
@@ -7090,7 +7137,7 @@ var Evaluation = class {
|
|
|
7090
7137
|
projectId: "",
|
|
7091
7138
|
evaluationId: "",
|
|
7092
7139
|
url: "",
|
|
7093
|
-
errorMessage:
|
|
7140
|
+
errorMessage: require_dist.errorMessage(e)
|
|
7094
7141
|
};
|
|
7095
7142
|
}
|
|
7096
7143
|
}
|
|
@@ -7105,7 +7152,7 @@ var Evaluation = class {
|
|
|
7105
7152
|
}
|
|
7106
7153
|
});
|
|
7107
7154
|
return LaminarContextManager.runWithIsolatedContext([entityContext], async () => {
|
|
7108
|
-
const semaphore = new
|
|
7155
|
+
const semaphore = new require_dist.Semaphore(this.concurrencyLimit);
|
|
7109
7156
|
const tasks = [];
|
|
7110
7157
|
const evaluateTask = async (datapoint, index) => {
|
|
7111
7158
|
try {
|
|
@@ -7129,20 +7176,20 @@ var Evaluation = class {
|
|
|
7129
7176
|
name: "evaluation",
|
|
7130
7177
|
traceType: "EVALUATION"
|
|
7131
7178
|
}, async () => {
|
|
7132
|
-
_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()).setAttribute(
|
|
7179
|
+
_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()).setAttribute(require_dist.SPAN_TYPE, "EVALUATION");
|
|
7133
7180
|
const executorSpan = Laminar.startSpan({
|
|
7134
7181
|
name: "executor",
|
|
7135
7182
|
input: datapoint.data
|
|
7136
7183
|
});
|
|
7137
|
-
executorSpan.setAttribute(
|
|
7138
|
-
const executorSpanId =
|
|
7139
|
-
const datapointId =
|
|
7184
|
+
executorSpan.setAttribute(require_dist.SPAN_TYPE, "EXECUTOR");
|
|
7185
|
+
const executorSpanId = require_dist.otelSpanIdToUUID(executorSpan.spanContext().spanId);
|
|
7186
|
+
const datapointId = require_dist.newUUID();
|
|
7140
7187
|
const partialDatapoint = {
|
|
7141
7188
|
id: datapointId,
|
|
7142
7189
|
data: datapoint.data,
|
|
7143
7190
|
target: datapoint.target,
|
|
7144
7191
|
metadata: datapoint.metadata,
|
|
7145
|
-
traceId:
|
|
7192
|
+
traceId: require_dist.otelTraceIdToUUID(_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()).spanContext().traceId),
|
|
7146
7193
|
executorSpanId,
|
|
7147
7194
|
index
|
|
7148
7195
|
};
|
|
@@ -7168,13 +7215,13 @@ var Evaluation = class {
|
|
|
7168
7215
|
if (evaluator instanceof HumanEvaluator) {
|
|
7169
7216
|
const activeSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext());
|
|
7170
7217
|
if (activeSpan) {
|
|
7171
|
-
activeSpan.setAttribute(
|
|
7172
|
-
if (evaluator.options) activeSpan.setAttribute(
|
|
7218
|
+
activeSpan.setAttribute(require_dist.SPAN_TYPE, "HUMAN_EVALUATOR");
|
|
7219
|
+
if (evaluator.options) activeSpan.setAttribute(require_dist.HUMAN_EVALUATOR_OPTIONS, JSON.stringify(evaluator.options));
|
|
7173
7220
|
}
|
|
7174
7221
|
return null;
|
|
7175
7222
|
} else {
|
|
7176
7223
|
const activeSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext());
|
|
7177
|
-
if (activeSpan) activeSpan.setAttribute(
|
|
7224
|
+
if (activeSpan) activeSpan.setAttribute(require_dist.SPAN_TYPE, "EVALUATOR");
|
|
7178
7225
|
return await evaluator(output, target, data);
|
|
7179
7226
|
}
|
|
7180
7227
|
}, output, datapoint.target, datapoint.data);
|
|
@@ -7197,7 +7244,7 @@ var Evaluation = class {
|
|
|
7197
7244
|
target,
|
|
7198
7245
|
metadata: datapoint.metadata,
|
|
7199
7246
|
scores,
|
|
7200
|
-
traceId:
|
|
7247
|
+
traceId: require_dist.otelTraceIdToUUID(_opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()).spanContext().traceId),
|
|
7201
7248
|
executorSpanId,
|
|
7202
7249
|
index
|
|
7203
7250
|
};
|
|
@@ -8080,6 +8127,62 @@ var LaminarLanguageModelV4 = class extends BaseLaminarLanguageModel {
|
|
|
8080
8127
|
}
|
|
8081
8128
|
};
|
|
8082
8129
|
//#endregion
|
|
8130
|
+
//#region src/opentelemetry-lib/instrumentation/aisdk/index.ts
|
|
8131
|
+
const AI_FUNCTIONS = [
|
|
8132
|
+
"generateText",
|
|
8133
|
+
"generateObject",
|
|
8134
|
+
"streamText",
|
|
8135
|
+
"streamObject",
|
|
8136
|
+
"embed",
|
|
8137
|
+
"embedMany",
|
|
8138
|
+
"rerank"
|
|
8139
|
+
];
|
|
8140
|
+
/**
|
|
8141
|
+
* Detect AI SDK v7 by the presence of `registerTelemetry` (added only in v7).
|
|
8142
|
+
* On v7 the wrapper injects `integrations: [laminarTelemetry()]`; on v6 it
|
|
8143
|
+
* falls back to the older `experimental_telemetry: { tracer }` path.
|
|
8144
|
+
*/
|
|
8145
|
+
const isAISDKv7 = (ai) => typeof ai.registerTelemetry === "function";
|
|
8146
|
+
const logger$1 = require_dist.initializeLogger();
|
|
8147
|
+
let wrapAISDKv7WarnedOnce = false;
|
|
8148
|
+
const wrapAISDK = (ai) => {
|
|
8149
|
+
const wrapped = {};
|
|
8150
|
+
if (isAISDKv7(ai)) {
|
|
8151
|
+
if (!wrapAISDKv7WarnedOnce) {
|
|
8152
|
+
wrapAISDKv7WarnedOnce = true;
|
|
8153
|
+
logger$1.warn("wrapAISDK() is not supported for AI SDK v7. Use LaminarAiSdkTelemetry instead:\n import { LaminarAiSdkTelemetry } from '@lmnr-ai/lmnr';\n import { registerTelemetry } from 'ai';\n registerTelemetry(new LaminarAiSdkTelemetry());");
|
|
8154
|
+
}
|
|
8155
|
+
return ai;
|
|
8156
|
+
}
|
|
8157
|
+
Object.entries(ai).forEach(([key, value]) => {
|
|
8158
|
+
if (typeof value === "function" && AI_FUNCTIONS.includes(key)) {
|
|
8159
|
+
const originalFn = value;
|
|
8160
|
+
wrapped[key] = (...args) => {
|
|
8161
|
+
if (args[0] && typeof args[0] === "object") {
|
|
8162
|
+
const defaultTelemetry = {
|
|
8163
|
+
isEnabled: true,
|
|
8164
|
+
tracer: getTracer()
|
|
8165
|
+
};
|
|
8166
|
+
args[0] = {
|
|
8167
|
+
...args[0],
|
|
8168
|
+
experimental_telemetry: {
|
|
8169
|
+
...defaultTelemetry,
|
|
8170
|
+
...args[0].experimental_telemetry
|
|
8171
|
+
}
|
|
8172
|
+
};
|
|
8173
|
+
}
|
|
8174
|
+
return originalFn(...args);
|
|
8175
|
+
};
|
|
8176
|
+
} else wrapped[key] = value;
|
|
8177
|
+
});
|
|
8178
|
+
return wrapped;
|
|
8179
|
+
};
|
|
8180
|
+
function wrapLanguageModel(languageModel) {
|
|
8181
|
+
if (languageModel.specificationVersion === "v4") return new LaminarLanguageModelV4(languageModel);
|
|
8182
|
+
if (languageModel.specificationVersion === "v3") return new LaminarLanguageModelV3(languageModel);
|
|
8183
|
+
return new LaminarLanguageModelV2(languageModel);
|
|
8184
|
+
}
|
|
8185
|
+
//#endregion
|
|
8083
8186
|
//#region src/opentelemetry-lib/instrumentation/aisdk/v7-integration/types.ts
|
|
8084
8187
|
const stepKey = (callId, stepNumber) => `${callId}:${stepNumber}`;
|
|
8085
8188
|
//#endregion
|
|
@@ -8098,10 +8201,10 @@ const normalizeProvider$1 = (provider) => {
|
|
|
8098
8201
|
};
|
|
8099
8202
|
const applyUsage = (attributes, usage) => {
|
|
8100
8203
|
if (!usage || typeof usage !== "object") return;
|
|
8101
|
-
if (typeof usage.inputTokens === "number") attributes[
|
|
8102
|
-
if (typeof usage.outputTokens === "number") attributes[
|
|
8103
|
-
if (typeof usage.totalTokens === "number") attributes[
|
|
8104
|
-
else if (typeof usage.inputTokens === "number" || typeof usage.outputTokens === "number") attributes[
|
|
8204
|
+
if (typeof usage.inputTokens === "number") attributes[require_dist.LaminarAttributes.INPUT_TOKEN_COUNT] = usage.inputTokens;
|
|
8205
|
+
if (typeof usage.outputTokens === "number") attributes[require_dist.LaminarAttributes.OUTPUT_TOKEN_COUNT] = usage.outputTokens;
|
|
8206
|
+
if (typeof usage.totalTokens === "number") attributes[require_dist.LaminarAttributes.TOTAL_TOKEN_COUNT] = usage.totalTokens;
|
|
8207
|
+
else if (typeof usage.inputTokens === "number" || typeof usage.outputTokens === "number") attributes[require_dist.LaminarAttributes.TOTAL_TOKEN_COUNT] = (usage.inputTokens ?? 0) + (usage.outputTokens ?? 0);
|
|
8105
8208
|
if (typeof usage.reasoningTokens === "number") attributes["gen_ai.usage.reasoning_tokens"] = usage.reasoningTokens;
|
|
8106
8209
|
else if (typeof usage.outputTokenDetails?.reasoningTokens === "number") attributes["gen_ai.usage.reasoning_tokens"] = usage.outputTokenDetails.reasoningTokens;
|
|
8107
8210
|
if (typeof usage.cachedInputTokens === "number") attributes["gen_ai.usage.cache_read_input_tokens"] = usage.cachedInputTokens;
|
|
@@ -8184,11 +8287,11 @@ const applyFinishReason = (span, finishReason) => {
|
|
|
8184
8287
|
const applyRequestModelAttributes = (span, event) => {
|
|
8185
8288
|
if (typeof event.provider === "string") {
|
|
8186
8289
|
const provider = normalizeProvider$1(event.provider);
|
|
8187
|
-
if (provider) span.setAttribute(
|
|
8290
|
+
if (provider) span.setAttribute(require_dist.LaminarAttributes.PROVIDER, provider);
|
|
8188
8291
|
span.setAttribute("ai.model.provider", event.provider);
|
|
8189
8292
|
}
|
|
8190
8293
|
if (typeof event.modelId === "string") {
|
|
8191
|
-
span.setAttribute(
|
|
8294
|
+
span.setAttribute(require_dist.LaminarAttributes.REQUEST_MODEL, event.modelId);
|
|
8192
8295
|
span.setAttribute("ai.model.id", event.modelId);
|
|
8193
8296
|
}
|
|
8194
8297
|
};
|
|
@@ -8197,7 +8300,7 @@ const applyPromptMessages = (span, event) => {
|
|
|
8197
8300
|
if (msgs.length === 0) return;
|
|
8198
8301
|
const serialized = serializeJSON$1(msgs);
|
|
8199
8302
|
span.setAttribute("ai.prompt.messages", serialized);
|
|
8200
|
-
span.setAttribute(
|
|
8303
|
+
span.setAttribute(require_dist.SPAN_INPUT, serialized);
|
|
8201
8304
|
};
|
|
8202
8305
|
const compareHrTime = (a, b) => {
|
|
8203
8306
|
if (a[0] !== b[0]) return a[0] - b[0];
|
|
@@ -8235,24 +8338,36 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8235
8338
|
const callId = event?.callId;
|
|
8236
8339
|
if (!callId) return;
|
|
8237
8340
|
const parentCtx = LaminarContextManager.getContext();
|
|
8238
|
-
const
|
|
8341
|
+
const tracer = getTracer();
|
|
8342
|
+
let spanName = event.operationId ?? "ai.operation";
|
|
8343
|
+
if (typeof event.functionId === "string") spanName += ` ${event.functionId}`;
|
|
8344
|
+
const span = tracer.startSpan(spanName, {
|
|
8345
|
+
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
8346
|
+
attributes: {
|
|
8347
|
+
[require_dist.SPAN_TYPE]: "DEFAULT",
|
|
8348
|
+
...typeof event.functionId === "string" ? {
|
|
8349
|
+
"operation.name": event.functionId,
|
|
8350
|
+
"ai.prompt": "_"
|
|
8351
|
+
} : {}
|
|
8352
|
+
}
|
|
8353
|
+
}, parentCtx);
|
|
8239
8354
|
const spanCtx = _opentelemetry_api.trace.setSpan(parentCtx, span);
|
|
8240
|
-
span.setAttribute(
|
|
8355
|
+
span.setAttribute(require_dist.SPAN_TYPE, "DEFAULT");
|
|
8241
8356
|
if (typeof event.operationId === "string") span.setAttribute("ai.operation", event.operationId);
|
|
8242
8357
|
if (typeof event.provider === "string") {
|
|
8243
8358
|
const provider = normalizeProvider$1(event.provider);
|
|
8244
|
-
if (provider) span.setAttribute(
|
|
8359
|
+
if (provider) span.setAttribute(require_dist.LaminarAttributes.PROVIDER, provider);
|
|
8245
8360
|
}
|
|
8246
8361
|
if (typeof event.modelId === "string") {
|
|
8247
|
-
span.setAttribute(
|
|
8362
|
+
span.setAttribute(require_dist.LaminarAttributes.REQUEST_MODEL, event.modelId);
|
|
8248
8363
|
span.setAttribute("ai.model.id", event.modelId);
|
|
8249
8364
|
}
|
|
8250
8365
|
if (typeof event.functionId === "string") span.setAttribute("ai.functionId", event.functionId);
|
|
8251
|
-
if (event.operationId === "ai.embed" || event.operationId === "ai.embedMany" || event.operationId === "ai.rerank") span.setAttribute(
|
|
8366
|
+
if (event.operationId === "ai.embed" || event.operationId === "ai.embedMany" || event.operationId === "ai.rerank") span.setAttribute(require_dist.SPAN_TYPE, "LLM");
|
|
8252
8367
|
if (this.recordInputs) {
|
|
8253
8368
|
if (Array.isArray(event.messages) || event.system !== void 0 || event.instructions !== void 0) applyPromptMessages(span, event);
|
|
8254
|
-
else if (event.value !== void 0) span.setAttribute(
|
|
8255
|
-
else if (event.query !== void 0 || event.documents !== void 0) span.setAttribute(
|
|
8369
|
+
else if (event.value !== void 0) span.setAttribute(require_dist.SPAN_INPUT, serializeJSON$1(event.value));
|
|
8370
|
+
else if (event.query !== void 0 || event.documents !== void 0) span.setAttribute(require_dist.SPAN_INPUT, serializeJSON$1({
|
|
8256
8371
|
query: event.query,
|
|
8257
8372
|
documents: event.documents
|
|
8258
8373
|
}));
|
|
@@ -8272,9 +8387,9 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8272
8387
|
if (!callId) return;
|
|
8273
8388
|
const op = this.operationByCallId.get(callId);
|
|
8274
8389
|
if (!op) return;
|
|
8275
|
-
const span = getTracer().startSpan(`ai.step
|
|
8390
|
+
const span = getTracer().startSpan(`ai.step`, { kind: _opentelemetry_api.SpanKind.CLIENT }, op.ctx);
|
|
8276
8391
|
const spanCtx = _opentelemetry_api.trace.setSpan(op.ctx, span);
|
|
8277
|
-
span.setAttribute(
|
|
8392
|
+
span.setAttribute(require_dist.SPAN_TYPE, "DEFAULT");
|
|
8278
8393
|
span.setAttribute("ai.step.number", stepNumber);
|
|
8279
8394
|
if (this.recordInputs) applyPromptMessages(span, event);
|
|
8280
8395
|
this.stepByKey.set(stepKey(callId, stepNumber), {
|
|
@@ -8291,7 +8406,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8291
8406
|
const parentCtx = step?.ctx ?? this.operationByCallId.get(callId)?.ctx;
|
|
8292
8407
|
if (!parentCtx) return;
|
|
8293
8408
|
const span = getTracer().startSpan(`ai.llm ${event.provider ?? ""}:${event.modelId ?? ""}`, { kind: _opentelemetry_api.SpanKind.CLIENT }, parentCtx);
|
|
8294
|
-
span.setAttribute(
|
|
8409
|
+
span.setAttribute(require_dist.SPAN_TYPE, "LLM");
|
|
8295
8410
|
applyRequestModelAttributes(span, event);
|
|
8296
8411
|
if (this.recordInputs) applyPromptMessages(span, event);
|
|
8297
8412
|
this.llmByKey.set(stepKey(callId, stepNumber), {
|
|
@@ -8309,9 +8424,9 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8309
8424
|
const span = llm.span;
|
|
8310
8425
|
if (typeof event.provider === "string") {
|
|
8311
8426
|
const provider = normalizeProvider$1(event.provider);
|
|
8312
|
-
if (provider) span.setAttribute(
|
|
8427
|
+
if (provider) span.setAttribute(require_dist.LaminarAttributes.PROVIDER, provider);
|
|
8313
8428
|
}
|
|
8314
|
-
if (typeof event.modelId === "string") span.setAttribute(
|
|
8429
|
+
if (typeof event.modelId === "string") span.setAttribute(require_dist.LaminarAttributes.RESPONSE_MODEL, event.modelId);
|
|
8315
8430
|
if (typeof event.finishReason === "string") applyFinishReason(span, event.finishReason);
|
|
8316
8431
|
if (typeof event.responseId === "string") span.setAttribute("gen_ai.response.id", event.responseId);
|
|
8317
8432
|
applyUsageToSpan(span, event.usage);
|
|
@@ -8378,7 +8493,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8378
8493
|
outputPayload.toolCalls = normalizedToolCallsList;
|
|
8379
8494
|
step.span.setAttribute("ai.response.toolCalls", serializeJSON$1(normalizedToolCallsList));
|
|
8380
8495
|
}
|
|
8381
|
-
if (Object.keys(outputPayload).length > 0) step.span.setAttribute(
|
|
8496
|
+
if (Object.keys(outputPayload).length > 0) step.span.setAttribute(require_dist.SPAN_OUTPUT, serializeJSON$1(outputPayload));
|
|
8382
8497
|
}
|
|
8383
8498
|
step.span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
|
|
8384
8499
|
step.span.end();
|
|
@@ -8390,7 +8505,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8390
8505
|
const op = this.operationByCallId.get(callId);
|
|
8391
8506
|
if (!op) return;
|
|
8392
8507
|
const span = getTracer().startSpan(`ai.llm ${event.provider ?? ""}:${event.modelId ?? ""}`, { kind: _opentelemetry_api.SpanKind.CLIENT }, op.ctx);
|
|
8393
|
-
span.setAttribute(
|
|
8508
|
+
span.setAttribute(require_dist.SPAN_TYPE, "LLM");
|
|
8394
8509
|
applyRequestModelAttributes(span, event);
|
|
8395
8510
|
this.llmByKey.set(stepKey(callId, 0), {
|
|
8396
8511
|
span,
|
|
@@ -8406,7 +8521,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8406
8521
|
if (typeof event.finishReason === "string") applyFinishReason(llm.span, event.finishReason);
|
|
8407
8522
|
const response = event?.response;
|
|
8408
8523
|
if (response && typeof response === "object") {
|
|
8409
|
-
if (typeof response.modelId === "string") llm.span.setAttribute(
|
|
8524
|
+
if (typeof response.modelId === "string") llm.span.setAttribute(require_dist.LaminarAttributes.RESPONSE_MODEL, response.modelId);
|
|
8410
8525
|
if (typeof response.id === "string") llm.span.setAttribute("gen_ai.response.id", response.id);
|
|
8411
8526
|
}
|
|
8412
8527
|
applyUsageToSpan(llm.span, event.usage);
|
|
@@ -8429,13 +8544,13 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8429
8544
|
if (!parentCtx) return;
|
|
8430
8545
|
const span = getTracer().startSpan(`ai.tool ${toolName ?? "unknown"}`, { kind: _opentelemetry_api.SpanKind.CLIENT }, parentCtx);
|
|
8431
8546
|
const spanCtx = _opentelemetry_api.trace.setSpan(parentCtx, span);
|
|
8432
|
-
span.setAttribute(
|
|
8547
|
+
span.setAttribute(require_dist.SPAN_TYPE, "TOOL");
|
|
8433
8548
|
if (toolName) span.setAttribute("ai.toolCall.name", toolName);
|
|
8434
8549
|
span.setAttribute("ai.toolCall.id", toolCallId);
|
|
8435
8550
|
if (this.recordInputs && toolCall?.input !== void 0) {
|
|
8436
8551
|
const serialized = serializeJSON$1(toolCall.input);
|
|
8437
8552
|
span.setAttribute("ai.toolCall.args", serialized);
|
|
8438
|
-
span.setAttribute(
|
|
8553
|
+
span.setAttribute(require_dist.SPAN_INPUT, serialized);
|
|
8439
8554
|
}
|
|
8440
8555
|
this.toolByCallId.set(toolCallId, {
|
|
8441
8556
|
span,
|
|
@@ -8460,14 +8575,14 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8460
8575
|
message
|
|
8461
8576
|
});
|
|
8462
8577
|
if (this.recordOutputs) {
|
|
8463
|
-
tool.span.setAttribute(
|
|
8578
|
+
tool.span.setAttribute(require_dist.SPAN_OUTPUT, message);
|
|
8464
8579
|
tool.span.setAttribute("ai.toolCall.error", message);
|
|
8465
8580
|
}
|
|
8466
8581
|
} else if (output.type === "tool-result") {
|
|
8467
8582
|
if (this.recordOutputs && output.output !== void 0) {
|
|
8468
8583
|
const serialized = serializeJSON$1(output.output);
|
|
8469
8584
|
tool.span.setAttribute("ai.toolCall.result", serialized);
|
|
8470
|
-
tool.span.setAttribute(
|
|
8585
|
+
tool.span.setAttribute(require_dist.SPAN_OUTPUT, serialized);
|
|
8471
8586
|
}
|
|
8472
8587
|
tool.span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
|
|
8473
8588
|
}
|
|
@@ -8488,7 +8603,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8488
8603
|
if (!callId) return;
|
|
8489
8604
|
const op = this.operationByCallId.get(callId);
|
|
8490
8605
|
if (!op) return;
|
|
8491
|
-
if (typeof event.modelId === "string") op.span.setAttribute(
|
|
8606
|
+
if (typeof event.modelId === "string") op.span.setAttribute(require_dist.LaminarAttributes.REQUEST_MODEL, event.modelId);
|
|
8492
8607
|
};
|
|
8493
8608
|
this.onEmbedEnd = (event) => {
|
|
8494
8609
|
const callId = event?.callId;
|
|
@@ -8510,13 +8625,13 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8510
8625
|
const hasText = typeof event.text === "string" && event.text.length > 0;
|
|
8511
8626
|
if (hasText) {
|
|
8512
8627
|
op.span.setAttribute("ai.response.text", event.text);
|
|
8513
|
-
op.span.setAttribute(
|
|
8628
|
+
op.span.setAttribute(require_dist.SPAN_OUTPUT, event.text);
|
|
8514
8629
|
}
|
|
8515
8630
|
const normalizedToolCallsList = normalizeToolCalls(event.toolCalls);
|
|
8516
8631
|
if (normalizedToolCallsList.length > 0) {
|
|
8517
8632
|
const serialized = serializeJSON$1(normalizedToolCallsList);
|
|
8518
8633
|
op.span.setAttribute("ai.response.toolCalls", serialized);
|
|
8519
|
-
if (!hasText) op.span.setAttribute(
|
|
8634
|
+
if (!hasText) op.span.setAttribute(require_dist.SPAN_OUTPUT, serialized);
|
|
8520
8635
|
}
|
|
8521
8636
|
if (event.embedding !== void 0) {
|
|
8522
8637
|
const emb = event.embedding;
|
|
@@ -8525,7 +8640,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8525
8640
|
}
|
|
8526
8641
|
if (Array.isArray(event.ranking)) {
|
|
8527
8642
|
op.span.setAttribute("ai.rerank.ranking", serializeJSON$1(event.ranking));
|
|
8528
|
-
op.span.setAttribute(
|
|
8643
|
+
op.span.setAttribute(require_dist.SPAN_OUTPUT, serializeJSON$1(event.ranking));
|
|
8529
8644
|
}
|
|
8530
8645
|
}
|
|
8531
8646
|
if (event.finishReason === "error") op.span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
|
|
@@ -8574,6 +8689,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
8574
8689
|
this.recordInputs = options.recordInputs ?? true;
|
|
8575
8690
|
this.recordOutputs = options.recordOutputs ?? true;
|
|
8576
8691
|
this.createStepSpan = options.createStepSpan ?? false;
|
|
8692
|
+
if (!Laminar.initialized()) Laminar.initialize(options.laminarOptions ?? {});
|
|
8577
8693
|
}
|
|
8578
8694
|
/** End child spans, end the operation span, and clean up both maps. */
|
|
8579
8695
|
closeOperation(callId, op) {
|
|
@@ -8692,69 +8808,6 @@ const enableAiSdkTelemetryDebug = (log = (e) => console.log("[aisdk:telemetry]",
|
|
|
8692
8808
|
return () => channel.unsubscribe(handler);
|
|
8693
8809
|
};
|
|
8694
8810
|
//#endregion
|
|
8695
|
-
//#region src/opentelemetry-lib/instrumentation/aisdk/index.ts
|
|
8696
|
-
const AI_FUNCTIONS = [
|
|
8697
|
-
"generateText",
|
|
8698
|
-
"generateObject",
|
|
8699
|
-
"streamText",
|
|
8700
|
-
"streamObject",
|
|
8701
|
-
"embed",
|
|
8702
|
-
"embedMany",
|
|
8703
|
-
"rerank"
|
|
8704
|
-
];
|
|
8705
|
-
/**
|
|
8706
|
-
* Detect AI SDK v7 by the presence of `registerTelemetry` (added only in v7).
|
|
8707
|
-
* On v7 the wrapper injects `integrations: [laminarTelemetry()]`; on v6 it
|
|
8708
|
-
* falls back to the older `experimental_telemetry: { tracer }` path.
|
|
8709
|
-
*/
|
|
8710
|
-
const isAISDKv7 = (ai) => typeof ai.registerTelemetry === "function";
|
|
8711
|
-
const wrapAISDK = (ai) => {
|
|
8712
|
-
const wrapped = {};
|
|
8713
|
-
const v7 = isAISDKv7(ai);
|
|
8714
|
-
const v7Integration = v7 ? aiSdkTelemetry() : void 0;
|
|
8715
|
-
Object.entries(ai).forEach(([key, value]) => {
|
|
8716
|
-
if (typeof value === "function" && AI_FUNCTIONS.includes(key)) {
|
|
8717
|
-
const originalFn = value;
|
|
8718
|
-
wrapped[key] = (...args) => {
|
|
8719
|
-
if (args[0] && typeof args[0] === "object") if (v7) {
|
|
8720
|
-
const userTelemetry = args[0].telemetry ?? args[0].experimental_telemetry ?? {};
|
|
8721
|
-
const mergedIntegrations = [v7Integration];
|
|
8722
|
-
const userIntegrations = userTelemetry.integrations;
|
|
8723
|
-
if (Array.isArray(userIntegrations)) mergedIntegrations.push(...userIntegrations);
|
|
8724
|
-
else if (userIntegrations) mergedIntegrations.push(userIntegrations);
|
|
8725
|
-
args[0] = {
|
|
8726
|
-
...args[0],
|
|
8727
|
-
telemetry: {
|
|
8728
|
-
isEnabled: true,
|
|
8729
|
-
...userTelemetry,
|
|
8730
|
-
integrations: mergedIntegrations
|
|
8731
|
-
}
|
|
8732
|
-
};
|
|
8733
|
-
} else {
|
|
8734
|
-
const defaultTelemetry = {
|
|
8735
|
-
isEnabled: true,
|
|
8736
|
-
tracer: getTracer()
|
|
8737
|
-
};
|
|
8738
|
-
args[0] = {
|
|
8739
|
-
...args[0],
|
|
8740
|
-
experimental_telemetry: {
|
|
8741
|
-
...defaultTelemetry,
|
|
8742
|
-
...args[0].experimental_telemetry
|
|
8743
|
-
}
|
|
8744
|
-
};
|
|
8745
|
-
}
|
|
8746
|
-
return originalFn(...args);
|
|
8747
|
-
};
|
|
8748
|
-
} else wrapped[key] = value;
|
|
8749
|
-
});
|
|
8750
|
-
return wrapped;
|
|
8751
|
-
};
|
|
8752
|
-
function wrapLanguageModel(languageModel) {
|
|
8753
|
-
if (languageModel.specificationVersion === "v4") return new LaminarLanguageModelV4(languageModel);
|
|
8754
|
-
if (languageModel.specificationVersion === "v3") return new LaminarLanguageModelV3(languageModel);
|
|
8755
|
-
return new LaminarLanguageModelV2(languageModel);
|
|
8756
|
-
}
|
|
8757
|
-
//#endregion
|
|
8758
8811
|
//#region src/opentelemetry-lib/instrumentation/mastra/types.ts
|
|
8759
8812
|
const MastraSpanType = {
|
|
8760
8813
|
MODEL_GENERATION: "model_generation",
|
|
@@ -8861,10 +8914,10 @@ const stringifyArgs = (raw) => {
|
|
|
8861
8914
|
const formatUsage = (usage) => {
|
|
8862
8915
|
if (!usage) return {};
|
|
8863
8916
|
const out = {};
|
|
8864
|
-
if (typeof usage.inputTokens === "number") out[
|
|
8865
|
-
if (typeof usage.outputTokens === "number") out[
|
|
8917
|
+
if (typeof usage.inputTokens === "number") out[require_dist.LaminarAttributes.INPUT_TOKEN_COUNT] = usage.inputTokens;
|
|
8918
|
+
if (typeof usage.outputTokens === "number") out[require_dist.LaminarAttributes.OUTPUT_TOKEN_COUNT] = usage.outputTokens;
|
|
8866
8919
|
const total = (usage.inputTokens ?? 0) + (usage.outputTokens ?? 0);
|
|
8867
|
-
if (total > 0) out[
|
|
8920
|
+
if (total > 0) out[require_dist.LaminarAttributes.TOTAL_TOKEN_COUNT] = total;
|
|
8868
8921
|
if (typeof usage.inputDetails?.cacheWrite === "number") out["gen_ai.usage.cache_creation_input_tokens"] = usage.inputDetails.cacheWrite;
|
|
8869
8922
|
if (typeof usage.inputDetails?.cacheRead === "number") out["gen_ai.usage.cache_read_input_tokens"] = usage.inputDetails.cacheRead;
|
|
8870
8923
|
if (typeof usage.outputDetails?.reasoning === "number") out["gen_ai.usage.reasoning_tokens"] = usage.outputDetails.reasoning;
|
|
@@ -8872,7 +8925,7 @@ const formatUsage = (usage) => {
|
|
|
8872
8925
|
};
|
|
8873
8926
|
//#endregion
|
|
8874
8927
|
//#region src/opentelemetry-lib/instrumentation/mastra/exporter.ts
|
|
8875
|
-
const logger =
|
|
8928
|
+
const logger = require_dist.initializeLogger();
|
|
8876
8929
|
/**
|
|
8877
8930
|
* Bridges Mastra's ObservabilityExporter contract to Laminar's OTLP ingestion.
|
|
8878
8931
|
*
|
|
@@ -8936,7 +8989,7 @@ var MastraExporter = class {
|
|
|
8936
8989
|
try {
|
|
8937
8990
|
await processor.forceFlush();
|
|
8938
8991
|
} catch (err) {
|
|
8939
|
-
logger.error(`[MastraExporter] forceFlush failed: ${
|
|
8992
|
+
logger.error(`[MastraExporter] forceFlush failed: ${require_dist.errorMessage(err)}`);
|
|
8940
8993
|
}
|
|
8941
8994
|
}
|
|
8942
8995
|
shutdown() {
|
|
@@ -8966,7 +9019,7 @@ var MastraExporter = class {
|
|
|
8966
9019
|
const parentId = span.parentSpanId;
|
|
8967
9020
|
const parentPath = parentId ? traceState.spanPathById.get(parentId) : traceState.otelParentSpanPath;
|
|
8968
9021
|
const parentIdsPath = parentId ? traceState.spanIdsPathById.get(parentId) : traceState.otelParentSpanIdsPath;
|
|
8969
|
-
const spanUuid =
|
|
9022
|
+
const spanUuid = require_dist.otelSpanIdToUUID(require_dist.normalizeOtelSpanId(span.id));
|
|
8970
9023
|
const spanPath = parentPath ? [...parentPath, span.name] : [span.name];
|
|
8971
9024
|
const spanIdsPath = parentIdsPath ? [...parentIdsPath, spanUuid] : [spanUuid];
|
|
8972
9025
|
traceState.spanPathById.set(span.id, spanPath);
|
|
@@ -9005,7 +9058,7 @@ var MastraExporter = class {
|
|
|
9005
9058
|
otelSpan.end(endTime);
|
|
9006
9059
|
if (this.config.realtime) await getSpanProcessor()?.forceFlush();
|
|
9007
9060
|
} catch (err) {
|
|
9008
|
-
logger.error(`[MastraExporter] failed to export span ${span.id}: ${
|
|
9061
|
+
logger.error(`[MastraExporter] failed to export span ${span.id}: ${require_dist.errorMessage(err)}`);
|
|
9009
9062
|
} finally {
|
|
9010
9063
|
traceState.activeSpanIds.delete(span.id);
|
|
9011
9064
|
if (traceState.activeSpanIds.size === 0) this.traceMap.delete(span.traceId);
|
|
@@ -9116,13 +9169,13 @@ var MastraExporter = class {
|
|
|
9116
9169
|
const activeSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
9117
9170
|
const ctx = activeSpan?.spanContext();
|
|
9118
9171
|
if (ctx && ctx.traceId && ctx.spanId) {
|
|
9119
|
-
created.otelTraceId =
|
|
9120
|
-
created.otelRootParentSpanId =
|
|
9172
|
+
created.otelTraceId = require_dist.normalizeOtelTraceId(ctx.traceId);
|
|
9173
|
+
created.otelRootParentSpanId = require_dist.normalizeOtelSpanId(ctx.spanId);
|
|
9121
9174
|
const attrs = activeSpan.attributes;
|
|
9122
9175
|
if (attrs) {
|
|
9123
|
-
const parentPath = attrs[
|
|
9176
|
+
const parentPath = attrs[require_dist.SPAN_PATH];
|
|
9124
9177
|
if (Array.isArray(parentPath) && parentPath.every((p) => typeof p === "string")) created.otelParentSpanPath = parentPath;
|
|
9125
|
-
const parentIdsPath = attrs[
|
|
9178
|
+
const parentIdsPath = attrs[require_dist.SPAN_IDS_PATH];
|
|
9126
9179
|
if (Array.isArray(parentIdsPath) && parentIdsPath.every((p) => typeof p === "string")) created.otelParentSpanIdsPath = parentIdsPath;
|
|
9127
9180
|
}
|
|
9128
9181
|
}
|
|
@@ -9142,14 +9195,14 @@ var MastraExporter = class {
|
|
|
9142
9195
|
return;
|
|
9143
9196
|
}
|
|
9144
9197
|
const sdkAllocatedSpanId = otelSpan.spanContext().spanId;
|
|
9145
|
-
const mastraSpanId =
|
|
9146
|
-
const mastraTraceId = traceState.otelTraceId ??
|
|
9198
|
+
const mastraSpanId = require_dist.normalizeOtelSpanId(span.id);
|
|
9199
|
+
const mastraTraceId = traceState.otelTraceId ?? require_dist.normalizeOtelTraceId(span.traceId);
|
|
9147
9200
|
Object.assign(otelSpan.spanContext(), {
|
|
9148
9201
|
traceId: mastraTraceId,
|
|
9149
9202
|
spanId: mastraSpanId
|
|
9150
9203
|
});
|
|
9151
9204
|
if (sdkAllocatedSpanId !== mastraSpanId) getSpanProcessor()?.dropPathInfo(sdkAllocatedSpanId);
|
|
9152
|
-
const parentSpanIdNormalized = span.parentSpanId ?
|
|
9205
|
+
const parentSpanIdNormalized = span.parentSpanId ? require_dist.normalizeOtelSpanId(span.parentSpanId) : traceState.otelRootParentSpanId;
|
|
9153
9206
|
if (parentSpanIdNormalized) {
|
|
9154
9207
|
const parentSpanContext = {
|
|
9155
9208
|
traceId: mastraTraceId,
|
|
@@ -9167,8 +9220,8 @@ var MastraExporter = class {
|
|
|
9167
9220
|
});
|
|
9168
9221
|
const spanPath = traceState.spanPathById.get(span.id);
|
|
9169
9222
|
const spanIdsPath = traceState.spanIdsPathById.get(span.id);
|
|
9170
|
-
if (spanPath) otelSpan.setAttribute(
|
|
9171
|
-
if (spanIdsPath) otelSpan.setAttribute(
|
|
9223
|
+
if (spanPath) otelSpan.setAttribute(require_dist.SPAN_PATH, spanPath);
|
|
9224
|
+
if (spanIdsPath) otelSpan.setAttribute(require_dist.SPAN_IDS_PATH, spanIdsPath);
|
|
9172
9225
|
this.liveOtelSpanByMastraId.set(span.id, otelSpan);
|
|
9173
9226
|
}
|
|
9174
9227
|
warnNotInitializedOnce() {
|
|
@@ -9195,39 +9248,39 @@ var MastraExporter = class {
|
|
|
9195
9248
|
}
|
|
9196
9249
|
applyEndAttributes(span, otelSpan, traceState) {
|
|
9197
9250
|
const attributes = this.buildLaminarAttributes(span, traceState);
|
|
9198
|
-
delete attributes[
|
|
9199
|
-
delete attributes[
|
|
9251
|
+
delete attributes[require_dist.SPAN_PATH];
|
|
9252
|
+
delete attributes[require_dist.SPAN_IDS_PATH];
|
|
9200
9253
|
otelSpan.setAttributes(attributes);
|
|
9201
9254
|
}
|
|
9202
9255
|
buildLaminarAttributes(span, traceState) {
|
|
9203
9256
|
const attributes = {};
|
|
9204
9257
|
const spanPath = traceState.spanPathById.get(span.id);
|
|
9205
9258
|
const spanIdsPath = traceState.spanIdsPathById.get(span.id);
|
|
9206
|
-
if (spanPath) attributes[
|
|
9207
|
-
if (spanIdsPath) attributes[
|
|
9259
|
+
if (spanPath) attributes[require_dist.SPAN_PATH] = spanPath;
|
|
9260
|
+
if (spanIdsPath) attributes[require_dist.SPAN_IDS_PATH] = spanIdsPath;
|
|
9208
9261
|
const laminarSpanType = mapLaminarSpanType(span.type);
|
|
9209
|
-
attributes[
|
|
9210
|
-
attributes[
|
|
9211
|
-
attributes[
|
|
9262
|
+
attributes[require_dist.SPAN_TYPE] = laminarSpanType;
|
|
9263
|
+
attributes[require_dist.SPAN_INSTRUMENTATION_SOURCE] = "javascript";
|
|
9264
|
+
attributes[require_dist.SPAN_SDK_VERSION] = require_dist.version;
|
|
9212
9265
|
const langVersion = getLangVersion();
|
|
9213
|
-
if (langVersion) attributes[
|
|
9266
|
+
if (langVersion) attributes[require_dist.SPAN_LANGUAGE_VERSION] = langVersion;
|
|
9214
9267
|
attributes["lmnr.internal.mastra.span_type"] = span.type;
|
|
9215
9268
|
const metadata = span.metadata ?? {};
|
|
9216
9269
|
const sessionId = metadata.sessionId ?? metadata.session_id;
|
|
9217
|
-
if (typeof sessionId === "string" && sessionId.length > 0) attributes[
|
|
9270
|
+
if (typeof sessionId === "string" && sessionId.length > 0) attributes[require_dist.SESSION_ID] = sessionId;
|
|
9218
9271
|
const userId = metadata.userId ?? metadata.user_id;
|
|
9219
|
-
if (typeof userId === "string" && userId.length > 0) attributes[
|
|
9272
|
+
if (typeof userId === "string" && userId.length > 0) attributes[require_dist.USER_ID] = userId;
|
|
9220
9273
|
for (const [key, value] of Object.entries(metadata)) {
|
|
9221
9274
|
if (key === "sessionId" || key === "session_id" || key === "userId" || key === "user_id" || value === void 0 || value === null) continue;
|
|
9222
9275
|
const av = toAttributeValue(value);
|
|
9223
|
-
if (av !== void 0) attributes[`${
|
|
9276
|
+
if (av !== void 0) attributes[`${require_dist.ASSOCIATION_PROPERTIES}.metadata.${key}`] = av;
|
|
9224
9277
|
}
|
|
9225
|
-
if (span.isRootSpan && span.tags?.length) attributes[`${
|
|
9278
|
+
if (span.isRootSpan && span.tags?.length) attributes[`${require_dist.ASSOCIATION_PROPERTIES}.tags`] = span.tags;
|
|
9226
9279
|
if (laminarSpanType === "LLM") this.applyLlmAttributes(span, attributes);
|
|
9227
9280
|
else if (laminarSpanType === "TOOL") this.applyToolAttributes(span, attributes);
|
|
9228
9281
|
else {
|
|
9229
|
-
if (span.input !== void 0) attributes[
|
|
9230
|
-
if (span.output !== void 0) attributes[
|
|
9282
|
+
if (span.input !== void 0) attributes[require_dist.SPAN_INPUT] = serializeJSON(span.input);
|
|
9283
|
+
if (span.output !== void 0) attributes[require_dist.SPAN_OUTPUT] = serializeJSON(span.output);
|
|
9231
9284
|
}
|
|
9232
9285
|
return attributes;
|
|
9233
9286
|
}
|
|
@@ -9240,10 +9293,10 @@ var MastraExporter = class {
|
|
|
9240
9293
|
const provider = generationAttrs?.provider;
|
|
9241
9294
|
const model = generationAttrs?.model;
|
|
9242
9295
|
const responseModel = generationAttrs?.responseModel;
|
|
9243
|
-
if (provider) attributes[
|
|
9244
|
-
if (model) attributes[
|
|
9245
|
-
if (responseModel) attributes[
|
|
9246
|
-
else if (model) attributes[
|
|
9296
|
+
if (provider) attributes[require_dist.LaminarAttributes.PROVIDER] = normalizeProvider(provider);
|
|
9297
|
+
if (model) attributes[require_dist.LaminarAttributes.REQUEST_MODEL] = model;
|
|
9298
|
+
if (responseModel) attributes[require_dist.LaminarAttributes.RESPONSE_MODEL] = responseModel;
|
|
9299
|
+
else if (model) attributes[require_dist.LaminarAttributes.RESPONSE_MODEL] = model;
|
|
9247
9300
|
const usage = stepAttrs.usage ?? generationAttrs?.usage;
|
|
9248
9301
|
Object.assign(attributes, formatUsage(usage));
|
|
9249
9302
|
if (typeof stepAttrs.finishReason === "string") {
|
|
@@ -9256,7 +9309,7 @@ var MastraExporter = class {
|
|
|
9256
9309
|
if (turn) messages.push(...turn);
|
|
9257
9310
|
}
|
|
9258
9311
|
if (messages.length > 0) attributes["ai.prompt.messages"] = serializeJSON(messages);
|
|
9259
|
-
else if (span.input !== void 0) attributes[
|
|
9312
|
+
else if (span.input !== void 0) attributes[require_dist.SPAN_INPUT] = serializeJSON(span.input);
|
|
9260
9313
|
const out = span.output;
|
|
9261
9314
|
const reasoningText = gen?.reasoningTextByStepIndex.get(stepIndex);
|
|
9262
9315
|
if (out && typeof out === "object") {
|
|
@@ -9295,11 +9348,11 @@ var MastraExporter = class {
|
|
|
9295
9348
|
parts
|
|
9296
9349
|
}]);
|
|
9297
9350
|
}
|
|
9298
|
-
} else if (out !== void 0) attributes[
|
|
9351
|
+
} else if (out !== void 0) attributes[require_dist.SPAN_OUTPUT] = serializeJSON(out);
|
|
9299
9352
|
}
|
|
9300
9353
|
applyToolAttributes(span, attributes) {
|
|
9301
|
-
if (span.input !== void 0) attributes[
|
|
9302
|
-
if (span.output !== void 0) attributes[
|
|
9354
|
+
if (span.input !== void 0) attributes[require_dist.SPAN_INPUT] = serializeJSON(span.input);
|
|
9355
|
+
if (span.output !== void 0) attributes[require_dist.SPAN_OUTPUT] = serializeJSON(span.output);
|
|
9303
9356
|
const toolAttrs = span.attributes ?? {};
|
|
9304
9357
|
const cleanedName = cleanMastraToolName(span.name) || span.name;
|
|
9305
9358
|
if (cleanedName) attributes["ai.toolCall.name"] = cleanedName;
|
|
@@ -9315,7 +9368,7 @@ exports.LAMINAR_TEMPORAL_SPAN_CONTEXT_HEADER = require_consts.LAMINAR_SPAN_CONTE
|
|
|
9315
9368
|
exports.LAMINAR_TEMPORAL_TRACEPARENT_HEADER = require_consts.TRACEPARENT_HEADER;
|
|
9316
9369
|
exports.Laminar = Laminar;
|
|
9317
9370
|
exports.LaminarAiSdkTelemetry = LaminarAiSdkTelemetry;
|
|
9318
|
-
exports.LaminarAttributes =
|
|
9371
|
+
exports.LaminarAttributes = require_dist.LaminarAttributes;
|
|
9319
9372
|
exports.LaminarClient = require_dist.LaminarClient;
|
|
9320
9373
|
exports.LaminarDataset = LaminarDataset;
|
|
9321
9374
|
exports.LaminarSpanProcessor = LaminarSpanProcessor;
|
|
@@ -9325,7 +9378,7 @@ exports.LaminarTemporalInterceptors = LaminarTemporalInterceptors;
|
|
|
9325
9378
|
exports.LaminarTemporalScheduleClientInterceptor = ScheduleClientInterceptor;
|
|
9326
9379
|
exports.LaminarTemporalWorkflowClientInterceptor = WorkflowClientInterceptor;
|
|
9327
9380
|
exports.MastraExporter = MastraExporter;
|
|
9328
|
-
exports.TracingLevel =
|
|
9381
|
+
exports.TracingLevel = require_dist.TracingLevel;
|
|
9329
9382
|
exports.aiSdkTelemetry = aiSdkTelemetry;
|
|
9330
9383
|
exports.enableAiSdkTelemetryDebug = enableAiSdkTelemetryDebug;
|
|
9331
9384
|
exports.evaluate = evaluate;
|