neatlogs 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/anthropic.cjs +167 -17
  2. package/dist/anthropic.cjs.map +1 -1
  3. package/dist/anthropic.mjs +177 -18
  4. package/dist/anthropic.mjs.map +1 -1
  5. package/dist/azure-openai.cjs +167 -17
  6. package/dist/azure-openai.cjs.map +1 -1
  7. package/dist/azure-openai.mjs +177 -18
  8. package/dist/azure-openai.mjs.map +1 -1
  9. package/dist/bedrock.cjs +171 -21
  10. package/dist/bedrock.cjs.map +1 -1
  11. package/dist/bedrock.mjs +181 -22
  12. package/dist/bedrock.mjs.map +1 -1
  13. package/dist/browser.cjs +27 -0
  14. package/dist/browser.cjs.map +1 -1
  15. package/dist/browser.d.ts +30 -0
  16. package/dist/browser.mjs +27 -0
  17. package/dist/browser.mjs.map +1 -1
  18. package/dist/index.cjs +530 -356
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +32 -2
  21. package/dist/index.mjs +419 -242
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/langchain.cjs +167 -23
  24. package/dist/langchain.cjs.map +1 -1
  25. package/dist/langchain.mjs +177 -24
  26. package/dist/langchain.mjs.map +1 -1
  27. package/dist/openai.cjs +167 -17
  28. package/dist/openai.cjs.map +1 -1
  29. package/dist/openai.mjs +177 -18
  30. package/dist/openai.mjs.map +1 -1
  31. package/dist/opencode-plugin.cjs +1 -1
  32. package/dist/opencode-plugin.cjs.map +1 -1
  33. package/dist/opencode-plugin.mjs +1 -1
  34. package/dist/opencode-plugin.mjs.map +1 -1
  35. package/dist/openrouter-agent.cjs +161 -11
  36. package/dist/openrouter-agent.cjs.map +1 -1
  37. package/dist/openrouter-agent.mjs +171 -12
  38. package/dist/openrouter-agent.mjs.map +1 -1
  39. package/dist/vertex-ai.cjs +175 -25
  40. package/dist/vertex-ai.cjs.map +1 -1
  41. package/dist/vertex-ai.mjs +185 -26
  42. package/dist/vertex-ai.mjs.map +1 -1
  43. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -86,7 +86,7 @@ module.exports = __toCommonJS(index_exports);
86
86
  // src/init.ts
87
87
  var import_node_crypto = require("crypto");
88
88
  var path3 = __toESM(require("path"));
89
- var import_api7 = require("@opentelemetry/api");
89
+ var import_api8 = require("@opentelemetry/api");
90
90
  var import_api_logs = require("@opentelemetry/api-logs");
91
91
  var import_resources = require("@opentelemetry/resources");
92
92
  var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
@@ -101,7 +101,7 @@ var import_exporter_logs_otlp_proto = require("@opentelemetry/exporter-logs-otlp
101
101
  var fs = __toESM(require("fs"));
102
102
  var path = __toESM(require("path"));
103
103
  var import_node_perf_hooks = require("perf_hooks");
104
- var import_api3 = require("@opentelemetry/api");
104
+ var import_api4 = require("@opentelemetry/api");
105
105
 
106
106
  // src/core/logger.ts
107
107
  var LOG_LEVELS = {
@@ -2370,11 +2370,46 @@ var UserPromptTemplate = class extends BasePromptTemplate {
2370
2370
  };
2371
2371
 
2372
2372
  // src/core/context.ts
2373
- var import_api2 = require("@opentelemetry/api");
2373
+ var import_api3 = require("@opentelemetry/api");
2374
2374
 
2375
- // src/decorators/base.ts
2375
+ // src/core/end-user.ts
2376
2376
  var import_api = require("@opentelemetry/api");
2377
2377
  var logger4 = getLogger();
2378
+ var END_USER_ID_KEY = "neatlogs.end_user.id";
2379
+ var END_USER_METADATA_KEY = "neatlogs.end_user.metadata";
2380
+ function normalizeEndUserMetadata(metadata) {
2381
+ if (metadata === void 0 || metadata === null) return void 0;
2382
+ if (typeof metadata === "string") return metadata || void 0;
2383
+ try {
2384
+ return JSON.stringify(metadata);
2385
+ } catch {
2386
+ return JSON.stringify(String(metadata));
2387
+ }
2388
+ }
2389
+ function isRootSpan() {
2390
+ const current = import_api.trace.getSpan(import_api.context.active());
2391
+ return !(current && current.isRecording());
2392
+ }
2393
+ function applyEndUserAttributes(span2, endUserId, endUserMetadata, isRoot = true) {
2394
+ if (!endUserId && !endUserMetadata) return;
2395
+ if (!isRoot) {
2396
+ logger4.debug(
2397
+ "[end_user] Ignoring endUserId/endUserMetadata on a non-root span \u2014 declare it on the trace root (top-level trace()/span()) or init()."
2398
+ );
2399
+ return;
2400
+ }
2401
+ if (endUserId) {
2402
+ span2.setAttribute(END_USER_ID_KEY, String(endUserId));
2403
+ }
2404
+ const metaJson = normalizeEndUserMetadata(endUserMetadata);
2405
+ if (metaJson) {
2406
+ span2.setAttribute(END_USER_METADATA_KEY, metaJson);
2407
+ }
2408
+ }
2409
+
2410
+ // src/decorators/base.ts
2411
+ var import_api2 = require("@opentelemetry/api");
2412
+ var logger5 = getLogger();
2378
2413
  var TRACER_NAME = "neatlogs";
2379
2414
  function safeJsonDumps(value) {
2380
2415
  try {
@@ -2423,21 +2458,23 @@ function setCommonSpanAttrs(span2, opts) {
2423
2458
  }
2424
2459
  }
2425
2460
  function decorateSpan(opts, fn) {
2426
- const tracer = import_api.trace.getTracer(TRACER_NAME);
2461
+ const tracer = import_api2.trace.getTracer(TRACER_NAME);
2427
2462
  const spanName = opts.spanName ?? opts.name ?? (fn.name || "anonymous");
2428
2463
  const captureInput = opts.captureInput !== false;
2429
2464
  const captureOutput = opts.captureOutput !== false;
2430
2465
  const doCapture = shouldCaptureContent();
2431
2466
  const wrapped = (...args) => {
2467
+ const isRoot = isRootSpan();
2432
2468
  return tracer.startActiveSpan(spanName, (span2) => {
2433
2469
  try {
2434
2470
  setCommonSpanAttrs(span2, opts);
2471
+ applyEndUserAttributes(span2, opts.endUserId, opts.endUserMetadata, isRoot);
2435
2472
  if (captureInput && doCapture && args.length > 0) {
2436
2473
  try {
2437
2474
  const inputValue = args.length === 1 ? serializeObj(args[0]) : args.map(serializeObj);
2438
2475
  span2.setAttribute("input.value", safeJsonDumps(inputValue));
2439
2476
  } catch (err) {
2440
- logger4.debug(`Failed to capture input: ${err}`);
2477
+ logger5.debug(`Failed to capture input: ${err}`);
2441
2478
  }
2442
2479
  }
2443
2480
  const result = fn(...args);
@@ -2447,7 +2484,7 @@ function decorateSpan(opts, fn) {
2447
2484
  try {
2448
2485
  span2.setAttribute("output.value", safeJsonDumps(serializeObj(resolved)));
2449
2486
  } catch (err) {
2450
- logger4.debug(`Failed to capture output: ${err}`);
2487
+ logger5.debug(`Failed to capture output: ${err}`);
2451
2488
  }
2452
2489
  }
2453
2490
  if (opts.postprocessResult) {
@@ -2455,15 +2492,15 @@ function decorateSpan(opts, fn) {
2455
2492
  const boundInputs = _extractBoundInputs(fn, args);
2456
2493
  opts.postprocessResult(span2, resolved, boundInputs);
2457
2494
  } catch (err) {
2458
- logger4.debug(`Postprocess failed: ${err}`);
2495
+ logger5.debug(`Postprocess failed: ${err}`);
2459
2496
  }
2460
2497
  }
2461
- span2.setStatus({ code: import_api.SpanStatusCode.OK });
2498
+ span2.setStatus({ code: import_api2.SpanStatusCode.OK });
2462
2499
  span2.end();
2463
2500
  return resolved;
2464
2501
  }).catch((error) => {
2465
2502
  span2.setStatus({
2466
- code: import_api.SpanStatusCode.ERROR,
2503
+ code: import_api2.SpanStatusCode.ERROR,
2467
2504
  message: error?.message ?? String(error)
2468
2505
  });
2469
2506
  span2.recordException(error instanceof Error ? error : new Error(String(error)));
@@ -2475,7 +2512,7 @@ function decorateSpan(opts, fn) {
2475
2512
  try {
2476
2513
  span2.setAttribute("output.value", safeJsonDumps(serializeObj(result)));
2477
2514
  } catch (err) {
2478
- logger4.debug(`Failed to capture output: ${err}`);
2515
+ logger5.debug(`Failed to capture output: ${err}`);
2479
2516
  }
2480
2517
  }
2481
2518
  if (opts.postprocessResult) {
@@ -2483,15 +2520,15 @@ function decorateSpan(opts, fn) {
2483
2520
  const boundInputs = _extractBoundInputs(fn, args);
2484
2521
  opts.postprocessResult(span2, result, boundInputs);
2485
2522
  } catch (err) {
2486
- logger4.debug(`Postprocess failed: ${err}`);
2523
+ logger5.debug(`Postprocess failed: ${err}`);
2487
2524
  }
2488
2525
  }
2489
- span2.setStatus({ code: import_api.SpanStatusCode.OK });
2526
+ span2.setStatus({ code: import_api2.SpanStatusCode.OK });
2490
2527
  span2.end();
2491
2528
  return result;
2492
2529
  } catch (error) {
2493
2530
  span2.setStatus({
2494
- code: import_api.SpanStatusCode.ERROR,
2531
+ code: import_api2.SpanStatusCode.ERROR,
2495
2532
  message: error?.message ?? String(error)
2496
2533
  });
2497
2534
  span2.recordException(error instanceof Error ? error : new Error(String(error)));
@@ -2517,7 +2554,7 @@ function _extractBoundInputs(fn, args) {
2517
2554
  }
2518
2555
 
2519
2556
  // src/core/context.ts
2520
- var logger5 = getLogger();
2557
+ var logger6 = getLogger();
2521
2558
  var _sessionConfig = {};
2522
2559
  function _setSessionConfig(config) {
2523
2560
  _sessionConfig = config;
@@ -2525,11 +2562,11 @@ function _setSessionConfig(config) {
2525
2562
  function getSessionConfig() {
2526
2563
  return { ..._sessionConfig };
2527
2564
  }
2528
- var PROMPT_VARIABLES_KEY = (0, import_api2.createContextKey)("neatlogs.prompt_variables");
2529
- var PROMPT_TEMPLATE_KEY = (0, import_api2.createContextKey)("neatlogs.prompt_template");
2530
- var PROMPT_VERSION_KEY = (0, import_api2.createContextKey)("neatlogs.prompt_version");
2531
- var USER_PROMPT_TEMPLATE_KEY = (0, import_api2.createContextKey)("neatlogs.user_prompt_template");
2532
- var USER_PROMPT_VARIABLES_KEY = (0, import_api2.createContextKey)("neatlogs.user_prompt_variables");
2565
+ var PROMPT_VARIABLES_KEY = (0, import_api3.createContextKey)("neatlogs.prompt_variables");
2566
+ var PROMPT_TEMPLATE_KEY = (0, import_api3.createContextKey)("neatlogs.prompt_template");
2567
+ var PROMPT_VERSION_KEY = (0, import_api3.createContextKey)("neatlogs.prompt_version");
2568
+ var USER_PROMPT_TEMPLATE_KEY = (0, import_api3.createContextKey)("neatlogs.user_prompt_template");
2569
+ var USER_PROMPT_VARIABLES_KEY = (0, import_api3.createContextKey)("neatlogs.user_prompt_variables");
2533
2570
  var KNOWN_OPTION_KEYS = /* @__PURE__ */ new Set([
2534
2571
  "name",
2535
2572
  "kind",
@@ -2540,7 +2577,9 @@ var KNOWN_OPTION_KEYS = /* @__PURE__ */ new Set([
2540
2577
  "userPromptVariables",
2541
2578
  "version",
2542
2579
  "mask",
2543
- "attributes"
2580
+ "attributes",
2581
+ "endUserId",
2582
+ "endUserMetadata"
2544
2583
  ]);
2545
2584
  function _setSpanAttributes(span2, kind, attributes) {
2546
2585
  span2.setAttribute("neatlogs.internal", true);
@@ -2557,7 +2596,7 @@ function _finalizePromptCapture(span2, isPromptTemplateObj, isUserPromptTemplate
2557
2596
  "llm.prompt_template_variables",
2558
2597
  JSON.stringify(capturedVars)
2559
2598
  );
2560
- logger5.debug(
2599
+ logger6.debug(
2561
2600
  `[trace] Auto-captured variables from PromptContext: ${Object.keys(capturedVars).join(", ")}`
2562
2601
  );
2563
2602
  }
@@ -2569,7 +2608,7 @@ function _finalizePromptCapture(span2, isPromptTemplateObj, isUserPromptTemplate
2569
2608
  "llm.user_prompt_template_variables",
2570
2609
  JSON.stringify(capturedUserVars)
2571
2610
  );
2572
- logger5.debug(
2611
+ logger6.debug(
2573
2612
  `[trace] Auto-captured variables from UserPromptContext: ${Object.keys(capturedUserVars).join(", ")}`
2574
2613
  );
2575
2614
  }
@@ -2586,12 +2625,14 @@ async function trace2(options, fn) {
2586
2625
  userPromptVariables,
2587
2626
  version,
2588
2627
  mask,
2628
+ endUserId,
2629
+ endUserMetadata,
2589
2630
  attributes: explicitAttributes,
2590
2631
  ...extraOptions
2591
2632
  } = options;
2592
2633
  const sessionConfig = getSessionConfig();
2593
2634
  const sessionId = sessionConfig.sessionId;
2594
- const currentSpan = import_api2.trace.getSpan(import_api2.context.active());
2635
+ const currentSpan = import_api3.trace.getSpan(import_api3.context.active());
2595
2636
  const isInActiveTrace = currentSpan !== void 0 && currentSpan.isRecording();
2596
2637
  const shouldCreateRootTrace = !!sessionId && !isInActiveTrace;
2597
2638
  let templateString;
@@ -2601,7 +2642,7 @@ async function trace2(options, fn) {
2601
2642
  isPromptTemplateObj = true;
2602
2643
  const t = promptTemplate.template;
2603
2644
  templateString = typeof t === "string" ? t : JSON.stringify(t);
2604
- logger5.debug(
2645
+ logger6.debug(
2605
2646
  `[trace] Using PromptTemplate object with variables: ${promptTemplate.variables.join(", ")}`
2606
2647
  );
2607
2648
  } else if (typeof promptTemplate === "string") {
@@ -2618,7 +2659,7 @@ async function trace2(options, fn) {
2618
2659
  isUserPromptTemplateObj = true;
2619
2660
  const t = userPromptTemplate.template;
2620
2661
  userTemplateString = typeof t === "string" ? t : JSON.stringify(t);
2621
- logger5.debug(
2662
+ logger6.debug(
2622
2663
  `[trace] Using UserPromptTemplate object with variables: ${userPromptTemplate.variables.join(", ")}`
2623
2664
  );
2624
2665
  } else if (typeof userPromptTemplate === "string") {
@@ -2628,28 +2669,28 @@ async function trace2(options, fn) {
2628
2669
  userTemplateString = typeof t === "string" ? t : JSON.stringify(t);
2629
2670
  }
2630
2671
  }
2631
- let ctx = import_api2.context.active();
2672
+ let ctx = import_api3.context.active();
2632
2673
  const variablesJson = promptVariables ? JSON.stringify(promptVariables) : void 0;
2633
2674
  const userVariablesJson = userPromptVariables ? JSON.stringify(userPromptVariables) : void 0;
2634
2675
  if (variablesJson) {
2635
2676
  ctx = ctx.setValue(PROMPT_VARIABLES_KEY, variablesJson);
2636
- logger5.debug(`[trace] Set neatlogs.prompt_variables in context: ${variablesJson}`);
2677
+ logger6.debug(`[trace] Set neatlogs.prompt_variables in context: ${variablesJson}`);
2637
2678
  }
2638
2679
  if (templateString) {
2639
2680
  ctx = ctx.setValue(PROMPT_TEMPLATE_KEY, templateString);
2640
- logger5.debug(`[trace] Set neatlogs.prompt_template in context: ${templateString}`);
2681
+ logger6.debug(`[trace] Set neatlogs.prompt_template in context: ${templateString}`);
2641
2682
  }
2642
2683
  if (userVariablesJson) {
2643
2684
  ctx = ctx.setValue(USER_PROMPT_VARIABLES_KEY, userVariablesJson);
2644
- logger5.debug(`[trace] Set neatlogs.user_prompt_variables in context: ${userVariablesJson}`);
2685
+ logger6.debug(`[trace] Set neatlogs.user_prompt_variables in context: ${userVariablesJson}`);
2645
2686
  }
2646
2687
  if (userTemplateString) {
2647
2688
  ctx = ctx.setValue(USER_PROMPT_TEMPLATE_KEY, userTemplateString);
2648
- logger5.debug(`[trace] Set neatlogs.user_prompt_template in context: ${userTemplateString}`);
2689
+ logger6.debug(`[trace] Set neatlogs.user_prompt_template in context: ${userTemplateString}`);
2649
2690
  }
2650
2691
  if (version) {
2651
2692
  ctx = ctx.setValue(PROMPT_VERSION_KEY, version);
2652
- logger5.debug(`[trace] Set neatlogs.prompt_version in context: ${version}`);
2693
+ logger6.debug(`[trace] Set neatlogs.prompt_version in context: ${version}`);
2653
2694
  }
2654
2695
  const extraAttributes = { ...explicitAttributes ?? {} };
2655
2696
  for (const [key, value] of Object.entries(extraOptions)) {
@@ -2657,9 +2698,11 @@ async function trace2(options, fn) {
2657
2698
  extraAttributes[key] = value;
2658
2699
  }
2659
2700
  }
2660
- const tracer = import_api2.trace.getTracer("neatlogs.trace");
2701
+ const isRootTrace = shouldCreateRootTrace || !isInActiveTrace;
2702
+ const tracer = import_api3.trace.getTracer("neatlogs.trace");
2661
2703
  const spanCallback = async (span2) => {
2662
2704
  _setSpanAttributes(span2, kind, extraAttributes);
2705
+ applyEndUserAttributes(span2, endUserId, endUserMetadata, isRootTrace);
2663
2706
  if (input !== void 0 && input !== null) {
2664
2707
  span2.setAttribute("input.value", safeJsonDumps(serializeObj(input)));
2665
2708
  }
@@ -2680,7 +2723,7 @@ async function trace2(options, fn) {
2680
2723
  return result;
2681
2724
  } catch (error) {
2682
2725
  span2.setStatus({
2683
- code: import_api2.SpanStatusCode.ERROR,
2726
+ code: import_api3.SpanStatusCode.ERROR,
2684
2727
  message: error instanceof Error ? error.message : String(error)
2685
2728
  });
2686
2729
  span2.recordException(
@@ -2698,23 +2741,23 @@ async function trace2(options, fn) {
2698
2741
  }
2699
2742
  };
2700
2743
  if (shouldCreateRootTrace) {
2701
- logger5.debug(`[trace] Creating NEW root trace '${name}' (sessionId=${sessionId})`);
2702
- return tracer.startActiveSpan(name, {}, import_api2.ROOT_CONTEXT, spanCallback);
2744
+ logger6.debug(`[trace] Creating NEW root trace '${name}' (sessionId=${sessionId})`);
2745
+ return tracer.startActiveSpan(name, {}, import_api3.ROOT_CONTEXT, spanCallback);
2703
2746
  } else {
2704
- logger5.debug(`[trace] Creating child span '${name}'`);
2747
+ logger6.debug(`[trace] Creating child span '${name}'`);
2705
2748
  return tracer.startActiveSpan(name, {}, ctx, spanCallback);
2706
2749
  }
2707
2750
  }
2708
2751
 
2709
2752
  // src/core/crewai-task-registry.ts
2710
- var logger6 = getLogger();
2753
+ var logger7 = getLogger();
2711
2754
  var _registry = /* @__PURE__ */ new Map();
2712
2755
  function registerCrewaiTask(task, userTpl, vars) {
2713
2756
  const taskId = String(task.id);
2714
2757
  const tplStr = String(userTpl.template);
2715
2758
  const varsJson = vars && Object.keys(vars).length > 0 ? JSON.stringify(vars, (_key, val) => typeof val === "undefined" ? null : val) : null;
2716
2759
  _registry.set(taskId, [tplStr, varsJson]);
2717
- logger6.debug(`Registered CrewAI task ${taskId}`);
2760
+ logger7.debug(`Registered CrewAI task ${taskId}`);
2718
2761
  }
2719
2762
  function popEntry(taskId) {
2720
2763
  const entry = _registry.get(taskId);
@@ -3856,7 +3899,7 @@ var attribute_mapping_default = {
3856
3899
  };
3857
3900
 
3858
3901
  // src/config/attribute-mapper.ts
3859
- var logger7 = getLogger();
3902
+ var logger8 = getLogger();
3860
3903
  function flattenSources(sources) {
3861
3904
  if (!sources) return [];
3862
3905
  if (Array.isArray(sources)) return sources;
@@ -4177,7 +4220,7 @@ var AttributeMapper = class {
4177
4220
  };
4178
4221
 
4179
4222
  // src/core/span-processor.ts
4180
- var logger8 = getLogger();
4223
+ var logger9 = getLogger();
4181
4224
  function resolveLogFilePath(configuredPath) {
4182
4225
  return path.isAbsolute(configuredPath) ? configuredPath : path.join(process.cwd(), configuredPath);
4183
4226
  }
@@ -4190,7 +4233,7 @@ function createLogStream(configuredPath) {
4190
4233
  const stream = fs.createWriteStream(logPath, { fd, autoClose: true });
4191
4234
  fd = null;
4192
4235
  stream.on("error", (error) => {
4193
- logger8.warn(`Failed to write span log file ${logPath}: ${error}`);
4236
+ logger9.warn(`Failed to write span log file ${logPath}: ${error}`);
4194
4237
  stream.destroy();
4195
4238
  });
4196
4239
  return stream;
@@ -4201,7 +4244,7 @@ function createLogStream(configuredPath) {
4201
4244
  } catch {
4202
4245
  }
4203
4246
  }
4204
- logger8.warn(`Failed to open span log file ${logPath}: ${error}`);
4247
+ logger9.warn(`Failed to open span log file ${logPath}: ${error}`);
4205
4248
  return null;
4206
4249
  }
4207
4250
  }
@@ -4222,11 +4265,11 @@ async function closeLogStream(stream, description) {
4222
4265
  };
4223
4266
  const closeHandler = settle;
4224
4267
  const errorHandler = (error) => {
4225
- logger8.warn(`Failed to close ${description} log file handle: ${error}`);
4268
+ logger9.warn(`Failed to close ${description} log file handle: ${error}`);
4226
4269
  settle();
4227
4270
  };
4228
4271
  const timer = setTimeout(() => {
4229
- logger8.warn(
4272
+ logger9.warn(
4230
4273
  `Timed out waiting for ${description} log stream to close; destroying`
4231
4274
  );
4232
4275
  stream.destroy();
@@ -4237,7 +4280,7 @@ async function closeLogStream(stream, description) {
4237
4280
  try {
4238
4281
  stream.end();
4239
4282
  } catch (error) {
4240
- logger8.warn(`Failed to close ${description} log file handle: ${error}`);
4283
+ logger9.warn(`Failed to close ${description} log file handle: ${error}`);
4241
4284
  settle();
4242
4285
  }
4243
4286
  });
@@ -4316,7 +4359,7 @@ var NeatlogsSpanProcessor = class {
4316
4359
  const rawPath = process.env.NEATLOGS_LOG_RAW_SPANS_FILE ?? "spans_raw_optimized.log";
4317
4360
  this._rawLogStream = createLogStream(rawPath);
4318
4361
  if (this._rawLogStream) {
4319
- logger8.info(
4362
+ logger9.info(
4320
4363
  `Raw span logging enabled: ${resolveLogFilePath(rawPath)}`
4321
4364
  );
4322
4365
  }
@@ -4328,7 +4371,7 @@ var NeatlogsSpanProcessor = class {
4328
4371
  const processedPath = process.env.NEATLOGS_LOG_SPANS_FILE ?? "spans_optimized.log";
4329
4372
  this._processedLogStream = createLogStream(processedPath);
4330
4373
  if (this._processedLogStream) {
4331
- logger8.info(
4374
+ logger9.info(
4332
4375
  `Processed span logging enabled: ${resolveLogFilePath(processedPath)}`
4333
4376
  );
4334
4377
  }
@@ -4343,7 +4386,7 @@ var NeatlogsSpanProcessor = class {
4343
4386
  const spanName = typeof span2.name === "string" ? span2.name : "";
4344
4387
  const isLlmSpan = spanKind === "LLM" || LLM_NAME_PATTERNS.test(spanName);
4345
4388
  if (!isLlmSpan) return;
4346
- const ctx = import_api3.context.active();
4389
+ const ctx = import_api4.context.active();
4347
4390
  let variablesJson = ctx.getValue(PROMPT_VARIABLES_KEY);
4348
4391
  let template = ctx.getValue(PROMPT_TEMPLATE_KEY);
4349
4392
  const versionVal = ctx.getValue(PROMPT_VERSION_KEY);
@@ -4374,14 +4417,14 @@ var NeatlogsSpanProcessor = class {
4374
4417
  }
4375
4418
  }
4376
4419
  if (this.debug) {
4377
- logger8.debug(
4420
+ logger9.debug(
4378
4421
  `[SpanProcessor.onStart] LLM span '${spanName}' starting`
4379
4422
  );
4380
- logger8.debug(` variables_json from context: ${variablesJson}`);
4381
- logger8.debug(` template from context: ${template}`);
4382
- logger8.debug(` version from context: ${versionVal}`);
4383
- logger8.debug(` user_template from context: ${userTemplate}`);
4384
- logger8.debug(
4423
+ logger9.debug(` variables_json from context: ${variablesJson}`);
4424
+ logger9.debug(` template from context: ${template}`);
4425
+ logger9.debug(` version from context: ${versionVal}`);
4426
+ logger9.debug(` user_template from context: ${userTemplate}`);
4427
+ logger9.debug(
4385
4428
  ` user_variables_json from context: ${userVariablesJson}`
4386
4429
  );
4387
4430
  }
@@ -4416,7 +4459,7 @@ var NeatlogsSpanProcessor = class {
4416
4459
  this.perfStats.spansProcessed += 1;
4417
4460
  try {
4418
4461
  if (this.debug) {
4419
- logger8.debug(`[SpanProcessor.onEnd] Span ending: ${span2.name}`);
4462
+ logger9.debug(`[SpanProcessor.onEnd] Span ending: ${span2.name}`);
4420
4463
  }
4421
4464
  if (this._rawLogStream && !this._rawLogStream.destroyed) {
4422
4465
  try {
@@ -4424,7 +4467,7 @@ var NeatlogsSpanProcessor = class {
4424
4467
  JSON.stringify(spanToDict(span2)) + "\n"
4425
4468
  );
4426
4469
  } catch (e) {
4427
- logger8.warn(`Failed to write span to raw log file: ${e}`);
4470
+ logger9.warn(`Failed to write span to raw log file: ${e}`);
4428
4471
  }
4429
4472
  }
4430
4473
  if (this.sampleRate < 1 && Math.random() > this.sampleRate) {
@@ -4447,7 +4490,7 @@ var NeatlogsSpanProcessor = class {
4447
4490
  delete unifiedAttrs[key];
4448
4491
  }
4449
4492
  if (this.debug && keysToRemove.length > 0) {
4450
- logger8.debug(
4493
+ logger9.debug(
4451
4494
  `[EMBEDDING Filter] Removed ${keysToRemove.length} large attribute keys from ${nlKind} span (skip_output=${skipOutput})`
4452
4495
  );
4453
4496
  }
@@ -4474,7 +4517,7 @@ var NeatlogsSpanProcessor = class {
4474
4517
  this._retrieversToSuppress.delete(spanId2);
4475
4518
  unifiedAttrs["neatlogs.internal"] = true;
4476
4519
  if (this.debug) {
4477
- logger8.debug(
4520
+ logger9.debug(
4478
4521
  `[Retriever Merge] Marked OI retriever '${span2.name}' as internal (had neatlogs retriever child)`
4479
4522
  );
4480
4523
  }
@@ -4492,7 +4535,7 @@ var NeatlogsSpanProcessor = class {
4492
4535
  }
4493
4536
  }
4494
4537
  if (this.debug && "neatlogs.tags" in resourceAttrs) {
4495
- logger8.debug(
4538
+ logger9.debug(
4496
4539
  `[Tags] Span ${span2.name}: resource.neatlogs.tags = ${resourceAttrs["neatlogs.tags"]}`
4497
4540
  );
4498
4541
  }
@@ -4502,7 +4545,7 @@ var NeatlogsSpanProcessor = class {
4502
4545
  let parentSpanId = span2.parentSpanId ?? null;
4503
4546
  if (parentSpanId === spanId) {
4504
4547
  if (this.debug) {
4505
- logger8.warn(
4548
+ logger9.warn(
4506
4549
  `[SpanProcessor] Detected self-parenting span. trace_id=${traceId} span_id=${spanId} name=${span2.name}. Setting parent_span_id=None.`
4507
4550
  );
4508
4551
  }
@@ -4523,7 +4566,7 @@ var NeatlogsSpanProcessor = class {
4523
4566
  attributes: unifiedAttrs,
4524
4567
  resource: { attributes: resourceAttrs },
4525
4568
  status: {
4526
- code: import_api3.SpanStatusCode[span2.status.code] ?? String(span2.status.code),
4569
+ code: import_api4.SpanStatusCode[span2.status.code] ?? String(span2.status.code),
4527
4570
  description: span2.status.message ?? null
4528
4571
  },
4529
4572
  events: span2.events ? span2.events.map((e) => ({
@@ -4565,7 +4608,7 @@ var NeatlogsSpanProcessor = class {
4565
4608
  }
4566
4609
  } catch (wbExc) {
4567
4610
  if (this.debug) {
4568
- logger8.debug(
4611
+ logger9.debug(
4569
4612
  `[SpanProcessor] Attr write-back failed: ${wbExc}`
4570
4613
  );
4571
4614
  }
@@ -4576,7 +4619,7 @@ var NeatlogsSpanProcessor = class {
4576
4619
  JSON.stringify(spanData) + "\n"
4577
4620
  );
4578
4621
  } catch (e) {
4579
- logger8.warn(`Failed to write span to processed log file: ${e}`);
4622
+ logger9.warn(`Failed to write span to processed log file: ${e}`);
4580
4623
  }
4581
4624
  }
4582
4625
  this.perfStats.spansExported += 1;
@@ -4594,11 +4637,11 @@ var NeatlogsSpanProcessor = class {
4594
4637
  traceId: rootSpan.spanContext().traceId,
4595
4638
  spanId: rootSpan.spanContext().spanId,
4596
4639
  isRemote: false,
4597
- traceFlags: import_api3.TraceFlags.SAMPLED
4640
+ traceFlags: import_api4.TraceFlags.SAMPLED
4598
4641
  };
4599
- const wrappedSpan = import_api3.trace.wrapSpanContext(spanCtx);
4600
- const ctx = import_api3.trace.setSpan(import_api3.context.active(), wrappedSpan);
4601
- const tracer = import_api3.trace.getTracer("neatlogs.internal");
4642
+ const wrappedSpan = import_api4.trace.wrapSpanContext(spanCtx);
4643
+ const ctx = import_api4.trace.setSpan(import_api4.context.active(), wrappedSpan);
4644
+ const tracer = import_api4.trace.getTracer("neatlogs.internal");
4602
4645
  const marker = tracer.startSpan("neatlogs.trace.complete", void 0, ctx);
4603
4646
  marker.setAttribute("neatlogs.trace.complete", true);
4604
4647
  marker.setAttribute("neatlogs.internal", true);
@@ -4608,12 +4651,12 @@ var NeatlogsSpanProcessor = class {
4608
4651
  }
4609
4652
  marker.end();
4610
4653
  if (this.debug) {
4611
- logger8.debug(
4654
+ logger9.debug(
4612
4655
  `[SpanProcessor] Emitted completion marker for trace ${traceId}`
4613
4656
  );
4614
4657
  }
4615
4658
  } catch (e) {
4616
- logger8.warn(`[SpanProcessor] Failed to emit completion marker: ${e}`);
4659
+ logger9.warn(`[SpanProcessor] Failed to emit completion marker: ${e}`);
4617
4660
  }
4618
4661
  }
4619
4662
  // ── Framework span name normalization ─────────────────
@@ -4680,7 +4723,7 @@ var NeatlogsSpanProcessor = class {
4680
4723
  if (respMeta?.model_name && respMeta.model_name !== currentModel) {
4681
4724
  attrs["neatlogs.llm.model_name"] = respMeta.model_name;
4682
4725
  if (this.debug) {
4683
- logger8.debug(
4726
+ logger9.debug(
4684
4727
  `[ModelResolve] LangChain span: ${currentModel} \u2192 ${respMeta.model_name}`
4685
4728
  );
4686
4729
  }
@@ -4690,13 +4733,13 @@ var NeatlogsSpanProcessor = class {
4690
4733
  if (output?.model && output.model !== currentModel) {
4691
4734
  attrs["neatlogs.llm.model_name"] = output.model;
4692
4735
  if (this.debug) {
4693
- logger8.debug(
4736
+ logger9.debug(
4694
4737
  `[ModelResolve] Direct response: ${currentModel} \u2192 ${output.model}`
4695
4738
  );
4696
4739
  }
4697
4740
  }
4698
4741
  } catch (e) {
4699
- logger8.warn(`[ModelResolve] Failed to parse LLM output for model extraction: ${e}`);
4742
+ logger9.warn(`[ModelResolve] Failed to parse LLM output for model extraction: ${e}`);
4700
4743
  }
4701
4744
  }
4702
4745
  // ── forceFlush / shutdown ─────────────────────────────
@@ -4717,7 +4760,7 @@ var NeatlogsSpanProcessor = class {
4717
4760
  const totalTime = stats.onStartTime + stats.onEndTime;
4718
4761
  const avgMs = totalTime / stats.spansProcessed;
4719
4762
  try {
4720
- logger8.info(
4763
+ logger9.info(
4721
4764
  `Neatlogs overhead: ${totalTime.toFixed(2)}ms total, ${avgMs.toFixed(3)}ms/span (${stats.spansProcessed} spans processed, ${stats.spansExported} spans logged)`
4722
4765
  );
4723
4766
  } catch {
@@ -4759,7 +4802,7 @@ var FilteringExporter = class {
4759
4802
  };
4760
4803
 
4761
4804
  // src/core/exporter.ts
4762
- var logger9 = getLogger();
4805
+ var logger10 = getLogger();
4763
4806
  var NeatlogsExporter = class {
4764
4807
  baseUrl;
4765
4808
  apiKey;
@@ -4788,7 +4831,7 @@ var NeatlogsExporter = class {
4788
4831
  this.buffer.push(spanData);
4789
4832
  if (this.buffer.length >= this.batchSize) {
4790
4833
  this.flush().catch((err) => {
4791
- logger9.warn(`Failed to flush batch: ${err}`);
4834
+ logger10.warn(`Failed to flush batch: ${err}`);
4792
4835
  });
4793
4836
  }
4794
4837
  }
@@ -4807,15 +4850,15 @@ var NeatlogsExporter = class {
4807
4850
  body: JSON.stringify({ spans: batch })
4808
4851
  });
4809
4852
  if (!response.ok) {
4810
- logger9.warn(
4853
+ logger10.warn(
4811
4854
  `Failed to export batch: ${response.status} ${response.statusText}`
4812
4855
  );
4813
4856
  this._requeueBatch(batch);
4814
4857
  } else {
4815
- logger9.debug(`Exported ${batch.length} log spans`);
4858
+ logger10.debug(`Exported ${batch.length} log spans`);
4816
4859
  }
4817
4860
  } catch (err) {
4818
- logger9.warn(`Failed to export batch: ${err}`);
4861
+ logger10.warn(`Failed to export batch: ${err}`);
4819
4862
  this._requeueBatch(batch);
4820
4863
  }
4821
4864
  }
@@ -4842,8 +4885,8 @@ var fs2 = __toESM(require("fs"));
4842
4885
  var path2 = __toESM(require("path"));
4843
4886
 
4844
4887
  // node_modules/@opentelemetry/core/build/esm/trace/suppress-tracing.js
4845
- var import_api4 = require("@opentelemetry/api");
4846
- var SUPPRESS_TRACING_KEY = (0, import_api4.createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
4888
+ var import_api5 = require("@opentelemetry/api");
4889
+ var SUPPRESS_TRACING_KEY = (0, import_api5.createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
4847
4890
  function suppressTracing(context3) {
4848
4891
  return context3.setValue(SUPPRESS_TRACING_KEY, true);
4849
4892
  }
@@ -4856,7 +4899,7 @@ var ExportResultCode;
4856
4899
  })(ExportResultCode || (ExportResultCode = {}));
4857
4900
 
4858
4901
  // src/core/log-exporter.ts
4859
- var logger10 = getLogger();
4902
+ var logger11 = getLogger();
4860
4903
  var NeatlogsLogExporter = class {
4861
4904
  exporter;
4862
4905
  logFileHandle = null;
@@ -4871,9 +4914,9 @@ var NeatlogsLogExporter = class {
4871
4914
  const filePath = path2.resolve(process.cwd(), logFile);
4872
4915
  try {
4873
4916
  this.logFileHandle = fs2.openSync(filePath, "a");
4874
- logger10.info(`Log record logging enabled: ${filePath}`);
4917
+ logger11.info(`Log record logging enabled: ${filePath}`);
4875
4918
  } catch (err) {
4876
- logger10.warn(`Failed to open log file ${filePath}: ${err}`);
4919
+ logger11.warn(`Failed to open log file ${filePath}: ${err}`);
4877
4920
  }
4878
4921
  }
4879
4922
  }
@@ -4886,7 +4929,7 @@ var NeatlogsLogExporter = class {
4886
4929
  }
4887
4930
  resultCallback({ code: ExportResultCode.SUCCESS });
4888
4931
  } catch (err) {
4889
- logger10.warn(`Failed to export log records: ${err}`);
4932
+ logger11.warn(`Failed to export log records: ${err}`);
4890
4933
  resultCallback({ code: ExportResultCode.FAILED });
4891
4934
  }
4892
4935
  }
@@ -4937,8 +4980,8 @@ var NeatlogsLogExporter = class {
4937
4980
  };
4938
4981
 
4939
4982
  // src/core/log.ts
4940
- var import_api5 = require("@opentelemetry/api");
4941
- var logger11 = getLogger();
4983
+ var import_api6 = require("@opentelemetry/api");
4984
+ var logger12 = getLogger();
4942
4985
  var _otelLogger = null;
4943
4986
  var _debugMode = false;
4944
4987
  function _setOtelLogger(otelLogger, debug) {
@@ -4955,7 +4998,7 @@ function log(msgTemplate, options) {
4955
4998
  console.log(`[neatlogs:log] ${rendered}`);
4956
4999
  }
4957
5000
  if (_otelLogger) {
4958
- const activeSpan = import_api5.trace.getSpan(import_api5.context.active());
5001
+ const activeSpan = import_api6.trace.getSpan(import_api6.context.active());
4959
5002
  const spanContext = activeSpan?.spanContext();
4960
5003
  const attributes = {
4961
5004
  "log.template": msgTemplate,
@@ -4971,7 +5014,7 @@ function log(msgTemplate, options) {
4971
5014
  ...spanContext ? { spanContext } : {}
4972
5015
  });
4973
5016
  } catch (err) {
4974
- logger11.warn(`Failed to emit log record: ${err}`);
5017
+ logger12.warn(`Failed to emit log record: ${err}`);
4975
5018
  }
4976
5019
  }
4977
5020
  }
@@ -5400,7 +5443,7 @@ function getLibraryInfo(library) {
5400
5443
  }
5401
5444
 
5402
5445
  // src/instrumentation/manager.ts
5403
- var logger12 = getLogger();
5446
+ var logger13 = getLogger();
5404
5447
  var InstrumentationManager = class {
5405
5448
  provider;
5406
5449
  _instrumented = [];
@@ -5419,7 +5462,7 @@ var InstrumentationManager = class {
5419
5462
  for (const lib of libraries) {
5420
5463
  const info = getLibraryInfo(lib);
5421
5464
  if (!info) {
5422
- logger12.warn(
5465
+ logger13.warn(
5423
5466
  `Unknown library '${lib}' \u2014 not in instrumentation registry. Skipping.`
5424
5467
  );
5425
5468
  continue;
@@ -5435,7 +5478,7 @@ var InstrumentationManager = class {
5435
5478
  if (typeof instrumentor.instrument === "function") {
5436
5479
  instrumentor.instrument({ tracerProvider: this.provider });
5437
5480
  this._instrumented.push(lib);
5438
- logger12.debug(
5481
+ logger13.debug(
5439
5482
  `Instrumented '${lib}' via neatlogs custom instrumentor`
5440
5483
  );
5441
5484
  continue;
@@ -5448,23 +5491,23 @@ var InstrumentationManager = class {
5448
5491
  const targetMod = await import(info.npm_package);
5449
5492
  instrumentor.patchEager(targetMod);
5450
5493
  } catch (e) {
5451
- logger12.debug(
5494
+ logger13.debug(
5452
5495
  `Eager patch for '${lib}' skipped \u2014 ${info.npm_package} not available: ${e}`
5453
5496
  );
5454
5497
  }
5455
5498
  }
5456
5499
  this._instrumented.push(lib);
5457
- logger12.debug(
5500
+ logger13.debug(
5458
5501
  `Instrumented '${lib}' via neatlogs OTel instrumentor`
5459
5502
  );
5460
5503
  continue;
5461
5504
  }
5462
5505
  }
5463
- logger12.debug(
5506
+ logger13.debug(
5464
5507
  `neatlogs instrumentor for '${lib}' loaded but has no instrument() method \u2014 trying OpenInference`
5465
5508
  );
5466
5509
  } catch (err) {
5467
- logger12.debug(
5510
+ logger13.debug(
5468
5511
  `neatlogs instrumentor for '${lib}' failed to load: ${err} \u2014 trying OpenInference`
5469
5512
  );
5470
5513
  }
@@ -5480,7 +5523,7 @@ var InstrumentationManager = class {
5480
5523
  if (typeof instrumentor.instrument === "function") {
5481
5524
  instrumentor.instrument({ tracerProvider: this.provider });
5482
5525
  this._instrumented.push(lib);
5483
- logger12.debug(`Instrumented '${lib}' via OpenInference`);
5526
+ logger13.debug(`Instrumented '${lib}' via OpenInference`);
5484
5527
  continue;
5485
5528
  }
5486
5529
  if (typeof instrumentor.setTracerProvider === "function" && typeof instrumentor.manuallyInstrument === "function") {
@@ -5490,16 +5533,16 @@ var InstrumentationManager = class {
5490
5533
  const targetMod = await import(info.npm_package);
5491
5534
  instrumentor.manuallyInstrument(targetMod);
5492
5535
  this._instrumented.push(lib);
5493
- logger12.debug(`Instrumented '${lib}' via OpenInference (manual patch)`);
5536
+ logger13.debug(`Instrumented '${lib}' via OpenInference (manual patch)`);
5494
5537
  continue;
5495
5538
  } catch (importErr) {
5496
- logger12.debug(
5539
+ logger13.debug(
5497
5540
  `Could not import '${info.npm_package}' for manual instrumentation of '${lib}': ${importErr}`
5498
5541
  );
5499
5542
  }
5500
5543
  }
5501
5544
  this._instrumented.push(lib);
5502
- logger12.debug(`Instrumented '${lib}' via OpenInference (tracer set, awaiting module hook)`);
5545
+ logger13.debug(`Instrumented '${lib}' via OpenInference (tracer set, awaiting module hook)`);
5503
5546
  continue;
5504
5547
  }
5505
5548
  }
@@ -5508,32 +5551,32 @@ var InstrumentationManager = class {
5508
5551
  tracerProvider: this.provider
5509
5552
  });
5510
5553
  this._instrumented.push(lib);
5511
- logger12.debug(`Instrumented '${lib}' via OpenInference`);
5554
+ logger13.debug(`Instrumented '${lib}' via OpenInference`);
5512
5555
  continue;
5513
5556
  }
5514
- logger12.warn(
5557
+ logger13.warn(
5515
5558
  `OpenInference package for '${lib}' loaded but could not find instrumentor class`
5516
5559
  );
5517
5560
  } catch (err) {
5518
- logger12.debug(
5561
+ logger13.debug(
5519
5562
  `OpenInference instrumentor for '${lib}' not available: ${err}`
5520
5563
  );
5521
5564
  }
5522
5565
  }
5523
5566
  if (!info.openinference && !info.neatlogs) {
5524
- logger12.debug(
5567
+ logger13.debug(
5525
5568
  `'${lib}' instrumentation not yet available for TypeScript \u2014 skipping`
5526
5569
  );
5527
5570
  }
5528
5571
  }
5529
5572
  if (this._instrumented.length > 0) {
5530
- logger12.info(`Instrumented: ${this._instrumented.join(", ")}`);
5573
+ logger13.info(`Instrumented: ${this._instrumented.join(", ")}`);
5531
5574
  }
5532
5575
  }
5533
5576
  };
5534
5577
 
5535
5578
  // src/prompt/client.ts
5536
- var import_api6 = require("@opentelemetry/api");
5579
+ var import_api7 = require("@opentelemetry/api");
5537
5580
  var PromptClientError = class extends Error {
5538
5581
  constructor(message) {
5539
5582
  super(message);
@@ -5843,8 +5886,8 @@ var PromptClient = class {
5843
5886
  };
5844
5887
  let response;
5845
5888
  try {
5846
- const suppressedContext = suppressTracing(import_api6.context.active());
5847
- response = await import_api6.context.with(suppressedContext, () => fetch(url, fetchOptions));
5889
+ const suppressedContext = suppressTracing(import_api7.context.active());
5890
+ response = await import_api7.context.with(suppressedContext, () => fetch(url, fetchOptions));
5848
5891
  } catch {
5849
5892
  response = await fetch(url, fetchOptions);
5850
5893
  }
@@ -5899,10 +5942,10 @@ async function removeTag(name, tag) {
5899
5942
  }
5900
5943
 
5901
5944
  // src/version.ts
5902
- var __version__ = "1.0.9";
5945
+ var __version__ = "1.1.0";
5903
5946
 
5904
5947
  // src/init.ts
5905
- var logger13 = getLogger();
5948
+ var logger14 = getLogger();
5906
5949
  var _initialized = false;
5907
5950
  var _tracerProvider = null;
5908
5951
  var _meterProvider = null;
@@ -5931,7 +5974,7 @@ function _randomHex(bytes) {
5931
5974
  }
5932
5975
  async function init(options = {}) {
5933
5976
  if (_initialized) {
5934
- logger13.warn("Neatlogs already initialized, skipping re-initialization");
5977
+ logger14.warn("Neatlogs already initialized, skipping re-initialization");
5935
5978
  return;
5936
5979
  }
5937
5980
  let resolvedKey;
@@ -5947,7 +5990,7 @@ async function init(options = {}) {
5947
5990
  disableExportResolved = true;
5948
5991
  resolvedKey = "disabled";
5949
5992
  if (options.debug) {
5950
- logger13.warn(
5993
+ logger14.warn(
5951
5994
  "No NEATLOGS_API_KEY set; HTTP export disabled. Set NEATLOGS_API_KEY (or pass apiKey) to send spans to the backend."
5952
5995
  );
5953
5996
  }
@@ -5961,7 +6004,7 @@ async function init(options = {}) {
5961
6004
  if (!sessionId && options.autoSession) {
5962
6005
  sessionId = `session_${Date.now()}_${_randomHex(4)}`;
5963
6006
  if (options.debug) {
5964
- logger13.debug(`Auto-generated session_id: ${sessionId}`);
6007
+ logger14.debug(`Auto-generated session_id: ${sessionId}`);
5965
6008
  }
5966
6009
  }
5967
6010
  const endpoint = options.endpoint ?? "https://staging-cloud.neatlogs.com";
@@ -5983,6 +6026,13 @@ async function init(options = {}) {
5983
6026
  };
5984
6027
  if (sessionId) resourceAttrs["session.id"] = sessionId;
5985
6028
  if (options.userId) resourceAttrs["user.id"] = options.userId;
6029
+ if (options.endUserId) {
6030
+ resourceAttrs[END_USER_ID_KEY] = String(options.endUserId);
6031
+ }
6032
+ if (options.endUserMetadata) {
6033
+ const euMeta = normalizeEndUserMetadata(options.endUserMetadata);
6034
+ if (euMeta) resourceAttrs[END_USER_METADATA_KEY] = euMeta;
6035
+ }
5986
6036
  const tags = options.tags;
5987
6037
  if (tags !== void 0) {
5988
6038
  if (!Array.isArray(tags) || !tags.every((t) => typeof t === "string")) {
@@ -6021,25 +6071,25 @@ async function init(options = {}) {
6021
6071
  });
6022
6072
  provider.addSpanProcessor(batchProcessor);
6023
6073
  if (options.debug) {
6024
- logger13.debug(`OTLP trace exporter configured: ${tracesEndpoint}`);
6074
+ logger14.debug(`OTLP trace exporter configured: ${tracesEndpoint}`);
6025
6075
  }
6026
6076
  } else if (options.debug) {
6027
- logger13.debug("Export disabled \u2014 spans will not be sent to backend");
6077
+ logger14.debug("Export disabled \u2014 spans will not be sent to backend");
6028
6078
  }
6029
6079
  provider.register();
6030
6080
  _tracerProvider = provider;
6031
6081
  if (options.debug) {
6032
- logger13.debug("Neatlogs tracer provider initialized");
6082
+ logger14.debug("Neatlogs tracer provider initialized");
6033
6083
  }
6034
6084
  try {
6035
6085
  _meterProvider = new import_sdk_metrics.MeterProvider({ resource });
6036
- import_api7.metrics.setGlobalMeterProvider(_meterProvider);
6086
+ import_api8.metrics.setGlobalMeterProvider(_meterProvider);
6037
6087
  if (options.debug) {
6038
- logger13.debug("Neatlogs meter provider initialized");
6088
+ logger14.debug("Neatlogs meter provider initialized");
6039
6089
  }
6040
6090
  } catch {
6041
6091
  if (options.debug) {
6042
- logger13.debug("MeterProvider not available \u2014 skipping");
6092
+ logger14.debug("MeterProvider not available \u2014 skipping");
6043
6093
  }
6044
6094
  }
6045
6095
  const captureLogs = options.captureLogs ?? false;
@@ -6065,17 +6115,17 @@ async function init(options = {}) {
6065
6115
  new import_sdk_logs.BatchLogRecordProcessor(otlpLogExporter)
6066
6116
  );
6067
6117
  if (options.debug) {
6068
- logger13.debug(`OTLP log exporter configured: ${logsEndpoint}`);
6118
+ logger14.debug(`OTLP log exporter configured: ${logsEndpoint}`);
6069
6119
  }
6070
6120
  }
6071
6121
  import_api_logs.logs.setGlobalLoggerProvider(_logProvider);
6072
6122
  const otelLogger = _logProvider.getLogger("neatlogs");
6073
6123
  _setOtelLogger(otelLogger, options.debug ?? false);
6074
6124
  if (options.debug) {
6075
- logger13.debug(`Neatlogs log capture enabled (endpoint: ${baseUrl}/v1/logs)`);
6125
+ logger14.debug(`Neatlogs log capture enabled (endpoint: ${baseUrl}/v1/logs)`);
6076
6126
  }
6077
6127
  } else if (options.debug) {
6078
- logger13.debug("Log capture disabled (pass captureLogs: true to enable)");
6128
+ logger14.debug("Log capture disabled (pass captureLogs: true to enable)");
6079
6129
  }
6080
6130
  const manager = new InstrumentationManager({
6081
6131
  provider,
@@ -6084,7 +6134,7 @@ async function init(options = {}) {
6084
6134
  if (options.instrumentations?.length) {
6085
6135
  await manager.instrument(options.instrumentations);
6086
6136
  if (options.debug) {
6087
- logger13.debug(`Instrumented libraries: ${manager.instrumented.join(", ")}`);
6137
+ logger14.debug(`Instrumented libraries: ${manager.instrumented.join(", ")}`);
6088
6138
  }
6089
6139
  }
6090
6140
  if (!_sigHandlersRegistered) {
@@ -6095,45 +6145,45 @@ async function init(options = {}) {
6095
6145
  }
6096
6146
  _initialized = true;
6097
6147
  if (options.debug) {
6098
- logger13.info("Neatlogs SDK initialized successfully");
6099
- logger13.info(`Endpoint: ${endpoint}`);
6100
- logger13.info(`Workflow: ${resolvedWorkflowName}`);
6101
- logger13.info(`Session: ${sessionId ?? "(none)"}`);
6102
- logger13.info(`User: ${options.userId ?? "(none)"}`);
6103
- logger13.info(`Tags: ${tags ?? []}`);
6104
- logger13.info(`Instrumentations: ${manager.instrumented.join(", ") || "(none)"}`);
6105
- logger13.info(`Sample Rate: ${options.sampleRate ?? 1}`);
6148
+ logger14.info("Neatlogs SDK initialized successfully");
6149
+ logger14.info(`Endpoint: ${endpoint}`);
6150
+ logger14.info(`Workflow: ${resolvedWorkflowName}`);
6151
+ logger14.info(`Session: ${sessionId ?? "(none)"}`);
6152
+ logger14.info(`User: ${options.userId ?? "(none)"}`);
6153
+ logger14.info(`Tags: ${tags ?? []}`);
6154
+ logger14.info(`Instrumentations: ${manager.instrumented.join(", ") || "(none)"}`);
6155
+ logger14.info(`Sample Rate: ${options.sampleRate ?? 1}`);
6106
6156
  }
6107
6157
  }
6108
6158
  async function flush() {
6109
6159
  let success = true;
6110
6160
  if (_tracerProvider) {
6111
6161
  try {
6112
- logger13.debug("Flushing tracer provider...");
6162
+ logger14.debug("Flushing tracer provider...");
6113
6163
  await _tracerProvider.forceFlush();
6114
- logger13.debug("Tracer provider flushed successfully");
6164
+ logger14.debug("Tracer provider flushed successfully");
6115
6165
  } catch (e) {
6116
- logger13.error(`Error flushing spans: ${e}`);
6166
+ logger14.error(`Error flushing spans: ${e}`);
6117
6167
  success = false;
6118
6168
  }
6119
6169
  }
6120
6170
  if (_meterProvider) {
6121
6171
  try {
6122
- logger13.debug("Flushing meter provider...");
6172
+ logger14.debug("Flushing meter provider...");
6123
6173
  await _meterProvider.forceFlush();
6124
- logger13.debug("Meter provider flushed successfully");
6174
+ logger14.debug("Meter provider flushed successfully");
6125
6175
  } catch (e) {
6126
- logger13.error(`Error flushing metrics: ${e}`);
6176
+ logger14.error(`Error flushing metrics: ${e}`);
6127
6177
  success = false;
6128
6178
  }
6129
6179
  }
6130
6180
  if (_logSpanExporter) {
6131
6181
  try {
6132
- logger13.debug("Flushing log span exporter...");
6182
+ logger14.debug("Flushing log span exporter...");
6133
6183
  await _logSpanExporter.flush();
6134
- logger13.debug("Log span exporter flushed successfully");
6184
+ logger14.debug("Log span exporter flushed successfully");
6135
6185
  } catch (e) {
6136
- logger13.error(`Error flushing logs: ${e}`);
6186
+ logger14.error(`Error flushing logs: ${e}`);
6137
6187
  success = false;
6138
6188
  }
6139
6189
  }
@@ -6149,41 +6199,41 @@ async function shutdown() {
6149
6199
  let success = true;
6150
6200
  if (_tracerProvider) {
6151
6201
  try {
6152
- logger13.debug("Shutting down tracer provider...");
6202
+ logger14.debug("Shutting down tracer provider...");
6153
6203
  await _tracerProvider.shutdown();
6154
- logger13.debug("Tracer provider shut down successfully");
6204
+ logger14.debug("Tracer provider shut down successfully");
6155
6205
  } catch (e) {
6156
- logger13.error(`Error shutting down tracer provider: ${e}`);
6206
+ logger14.error(`Error shutting down tracer provider: ${e}`);
6157
6207
  success = false;
6158
6208
  }
6159
6209
  }
6160
6210
  if (_meterProvider) {
6161
6211
  try {
6162
- logger13.debug("Shutting down meter provider...");
6212
+ logger14.debug("Shutting down meter provider...");
6163
6213
  await _meterProvider.shutdown();
6164
- logger13.debug("Meter provider shut down successfully");
6214
+ logger14.debug("Meter provider shut down successfully");
6165
6215
  } catch (e) {
6166
- logger13.error(`Error shutting down meter provider: ${e}`);
6216
+ logger14.error(`Error shutting down meter provider: ${e}`);
6167
6217
  success = false;
6168
6218
  }
6169
6219
  }
6170
6220
  if (_logProvider) {
6171
6221
  try {
6172
- logger13.debug("Shutting down log provider...");
6222
+ logger14.debug("Shutting down log provider...");
6173
6223
  await _logProvider.shutdown();
6174
- logger13.debug("Log provider shut down successfully");
6224
+ logger14.debug("Log provider shut down successfully");
6175
6225
  } catch (e) {
6176
- logger13.error(`Error shutting down log provider: ${e}`);
6226
+ logger14.error(`Error shutting down log provider: ${e}`);
6177
6227
  success = false;
6178
6228
  }
6179
6229
  }
6180
6230
  if (_logSpanExporter) {
6181
6231
  try {
6182
- logger13.debug("Shutting down log span exporter...");
6232
+ logger14.debug("Shutting down log span exporter...");
6183
6233
  await _logSpanExporter.shutdown();
6184
- logger13.debug("Log span exporter shut down successfully");
6234
+ logger14.debug("Log span exporter shut down successfully");
6185
6235
  } catch (e) {
6186
- logger13.error(`Error shutting down log span exporter: ${e}`);
6236
+ logger14.error(`Error shutting down log span exporter: ${e}`);
6187
6237
  success = false;
6188
6238
  }
6189
6239
  }
@@ -6195,7 +6245,7 @@ async function shutdown() {
6195
6245
  _spanProcessor = null;
6196
6246
  _debugMode2 = false;
6197
6247
  _setSessionConfig({});
6198
- logger13.info("Neatlogs SDK shutdown complete");
6248
+ logger14.info("Neatlogs SDK shutdown complete");
6199
6249
  return success;
6200
6250
  }
6201
6251
  function getTracerProvider() {
@@ -6211,7 +6261,7 @@ function isDebugEnabled() {
6211
6261
  }
6212
6262
 
6213
6263
  // src/decorators/orchestration.ts
6214
- var logger14 = getLogger();
6264
+ var logger15 = getLogger();
6215
6265
  function span(options, fn) {
6216
6266
  if (!VALID_SPAN_KINDS.has(options.kind)) {
6217
6267
  throw new Error(
@@ -6372,7 +6422,7 @@ async function getMastraObservability() {
6372
6422
  }
6373
6423
 
6374
6424
  // src/ai-sdk.ts
6375
- var import_api8 = require("@opentelemetry/api");
6425
+ var import_api9 = require("@opentelemetry/api");
6376
6426
  var TRACER_NAME2 = "neatlogs.ai-sdk";
6377
6427
  function createAITelemetry(opts = {}) {
6378
6428
  const userMeta = opts.metadata ?? {};
@@ -6380,7 +6430,7 @@ function createAITelemetry(opts = {}) {
6380
6430
  isEnabled: true,
6381
6431
  recordInputs: true,
6382
6432
  recordOutputs: true,
6383
- tracer: import_api8.trace.getTracer(TRACER_NAME2),
6433
+ tracer: import_api9.trace.getTracer(TRACER_NAME2),
6384
6434
  metadata: { ...userMeta, neatlogsWrapped: true }
6385
6435
  };
6386
6436
  }
@@ -6451,18 +6501,18 @@ function rootSpanKind(name) {
6451
6501
  return "WORKFLOW";
6452
6502
  }
6453
6503
  function getParentContext() {
6454
- const activeSpan = import_api8.trace.getActiveSpan();
6504
+ const activeSpan = import_api9.trace.getActiveSpan();
6455
6505
  if (activeSpan) {
6456
6506
  const instrScope = activeSpan.instrumentationLibrary?.name ?? "";
6457
6507
  if (instrScope === "next.js") {
6458
- return import_api8.ROOT_CONTEXT;
6508
+ return import_api9.ROOT_CONTEXT;
6459
6509
  }
6460
6510
  }
6461
- return import_api8.context.active();
6511
+ return import_api9.context.active();
6462
6512
  }
6463
6513
  function createAsyncWrapper(name, original) {
6464
6514
  return async function wrappedAsyncFn(opts) {
6465
- const tracer = import_api8.trace.getTracer(TRACER_NAME2);
6515
+ const tracer = import_api9.trace.getTracer(TRACER_NAME2);
6466
6516
  return tracer.startActiveSpan(
6467
6517
  `ai.${name}`,
6468
6518
  { attributes: { "openinference.span.kind": rootSpanKind(name) } },
@@ -6494,7 +6544,7 @@ function createAsyncWrapper(name, original) {
6494
6544
  }
6495
6545
  function createSyncWrapper(name, original) {
6496
6546
  return function wrappedSyncFn(opts) {
6497
- const tracer = import_api8.trace.getTracer(TRACER_NAME2);
6547
+ const tracer = import_api9.trace.getTracer(TRACER_NAME2);
6498
6548
  return tracer.startActiveSpan(`ai.${name}`, { attributes: { "openinference.span.kind": rootSpanKind(name) } }, getParentContext(), (span2) => {
6499
6549
  try {
6500
6550
  setInputValue(span2, opts);
@@ -6524,22 +6574,116 @@ function mergeTelemetry(opts) {
6524
6574
  }
6525
6575
  function recordSpanError(span2, err) {
6526
6576
  if (err instanceof Error) {
6527
- span2.setStatus({ code: import_api8.SpanStatusCode.ERROR, message: err.message });
6577
+ span2.setStatus({ code: import_api9.SpanStatusCode.ERROR, message: err.message });
6528
6578
  span2.recordException(err);
6529
6579
  } else {
6530
- span2.setStatus({ code: import_api8.SpanStatusCode.ERROR, message: String(err) });
6580
+ span2.setStatus({ code: import_api9.SpanStatusCode.ERROR, message: String(err) });
6531
6581
  }
6532
6582
  }
6533
6583
 
6534
6584
  // src/openai.ts
6535
- var import_api9 = require("@opentelemetry/api");
6585
+ var import_api11 = require("@opentelemetry/api");
6586
+
6587
+ // src/core/auto-root.ts
6588
+ var import_api10 = require("@opentelemetry/api");
6589
+ var ROOT_KINDS = /* @__PURE__ */ new Set(["workflow", "chain", "agent", "mcp_tool"]);
6590
+ function autoRootEnabled() {
6591
+ const val = (process.env.NEATLOGS_AUTO_ROOT ?? "").trim().toLowerCase();
6592
+ return !["false", "0", "no", "off"].includes(val);
6593
+ }
6594
+ function resolveRootWorkflowName() {
6595
+ try {
6596
+ const name = getSessionConfig()?.workflowName;
6597
+ if (typeof name === "string" && name.trim()) return name;
6598
+ } catch {
6599
+ }
6600
+ return "workflow";
6601
+ }
6602
+ function wrapSpanWithRoot(child, root) {
6603
+ let ended = false;
6604
+ return new Proxy(child, {
6605
+ get(target, prop, _receiver) {
6606
+ if (prop === "end") {
6607
+ return (...args) => {
6608
+ if (ended) return;
6609
+ ended = true;
6610
+ try {
6611
+ target.end(...args);
6612
+ } finally {
6613
+ try {
6614
+ root.end();
6615
+ } catch {
6616
+ }
6617
+ }
6618
+ };
6619
+ }
6620
+ const value = Reflect.get(target, prop, target);
6621
+ return typeof value === "function" ? value.bind(target) : value;
6622
+ }
6623
+ });
6624
+ }
6625
+ function maybeOpenAutoRoot(tracer, kind, baseCtx) {
6626
+ const k = String(kind ?? "").toLowerCase();
6627
+ const existing = import_api10.trace.getSpan(baseCtx);
6628
+ if (!autoRootEnabled() || ROOT_KINDS.has(k) || existing !== void 0 && existing.isRecording()) {
6629
+ return { root: void 0, ctx: baseCtx };
6630
+ }
6631
+ const root = tracer.startSpan(
6632
+ resolveRootWorkflowName(),
6633
+ { attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
6634
+ baseCtx
6635
+ );
6636
+ return { root, ctx: import_api10.trace.setSpan(baseCtx, root) };
6637
+ }
6638
+ function endAutoRoot(root) {
6639
+ if (!root) return;
6640
+ try {
6641
+ root.end();
6642
+ } catch {
6643
+ }
6644
+ }
6645
+ var AutoRootTracer = class {
6646
+ constructor(_tracer) {
6647
+ this._tracer = _tracer;
6648
+ }
6649
+ _tracer;
6650
+ startSpan(name, options, context3) {
6651
+ const kind = String(
6652
+ options?.attributes?.["neatlogs.span.kind"] ?? ""
6653
+ ).toLowerCase();
6654
+ const ctx = context3 ?? import_api10.context.active();
6655
+ const parent = import_api10.trace.getSpan(ctx);
6656
+ const needsRoot = autoRootEnabled() && !ROOT_KINDS.has(kind) && !(parent !== void 0 && parent.isRecording());
6657
+ if (!needsRoot) {
6658
+ return this._tracer.startSpan(name, options, context3);
6659
+ }
6660
+ const root = this._tracer.startSpan(
6661
+ resolveRootWorkflowName(),
6662
+ { attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
6663
+ ctx
6664
+ );
6665
+ const childCtx = import_api10.trace.setSpan(ctx, root);
6666
+ const child = this._tracer.startSpan(name, options, childCtx);
6667
+ return wrapSpanWithRoot(child, root);
6668
+ }
6669
+ // startActiveSpan is used by traceTool (callback-scoped, always under an
6670
+ // active span in practice) — pass straight through, no auto-root.
6671
+ startActiveSpan = ((...args) => this._tracer.startActiveSpan(
6672
+ ...args
6673
+ ));
6674
+ };
6675
+ function getProviderTracer(name) {
6676
+ return new AutoRootTracer(import_api10.trace.getTracer(name));
6677
+ }
6678
+
6679
+ // src/openai.ts
6536
6680
  var TRACER_NAME3 = "neatlogs.openai";
6537
6681
  function wrapOpenAI(client) {
6538
6682
  return wrapNamespace(client, []);
6539
6683
  }
6540
6684
  function traceTool(name, fn) {
6541
6685
  return async function tracedTool(args) {
6542
- const tracer = import_api9.trace.getTracer(TRACER_NAME3);
6686
+ const tracer = import_api11.trace.getTracer(TRACER_NAME3);
6543
6687
  return tracer.startActiveSpan(
6544
6688
  `tool.${name}`,
6545
6689
  {
@@ -6549,12 +6693,12 @@ function traceTool(name, fn) {
6549
6693
  "input.value": safeStringify3(args)
6550
6694
  }
6551
6695
  },
6552
- import_api9.context.active(),
6696
+ import_api11.context.active(),
6553
6697
  async (span2) => {
6554
6698
  try {
6555
6699
  const result = await fn(args);
6556
6700
  span2.setAttribute("output.value", safeStringify3(result));
6557
- span2.setStatus({ code: import_api9.SpanStatusCode.OK });
6701
+ span2.setStatus({ code: import_api11.SpanStatusCode.OK });
6558
6702
  return result;
6559
6703
  } catch (err) {
6560
6704
  recordError(span2, err);
@@ -6593,7 +6737,7 @@ function isNamespace(path4) {
6593
6737
  }
6594
6738
  function tracedChatCompletionsCreate(original) {
6595
6739
  return function(opts, ...rest) {
6596
- const tracer = import_api9.trace.getTracer(TRACER_NAME3);
6740
+ const tracer = getProviderTracer(TRACER_NAME3);
6597
6741
  const model = opts?.model ?? "";
6598
6742
  const messages = opts?.messages ?? [];
6599
6743
  const isStream = opts?.stream === true;
@@ -6605,7 +6749,7 @@ function tracedChatCompletionsCreate(original) {
6605
6749
  "neatlogs.llm.model_name": model,
6606
6750
  "neatlogs.llm.is_streaming": isStream
6607
6751
  }
6608
- }, import_api9.context.active());
6752
+ }, import_api11.context.active());
6609
6753
  for (let i = 0; i < messages.length; i++) {
6610
6754
  const msg = messages[i];
6611
6755
  span2.setAttribute(`neatlogs.llm.input_messages.${i}.role`, msg.role ?? "");
@@ -6634,8 +6778,8 @@ function tracedChatCompletionsCreate(original) {
6634
6778
  opts.stream_options = { ...streamOpts, include_usage: true };
6635
6779
  }
6636
6780
  }
6637
- const ctx = import_api9.trace.setSpan(import_api9.context.active(), span2);
6638
- const promise = import_api9.context.with(ctx, () => original(opts, ...rest));
6781
+ const ctx = import_api11.trace.setSpan(import_api11.context.active(), span2);
6782
+ const promise = import_api11.context.with(ctx, () => original(opts, ...rest));
6639
6783
  return promise.then(
6640
6784
  (response) => {
6641
6785
  if (isStream) {
@@ -6653,7 +6797,7 @@ function tracedChatCompletionsCreate(original) {
6653
6797
  }
6654
6798
  function tracedResponsesCreate(original) {
6655
6799
  return function(opts, ...rest) {
6656
- const tracer = import_api9.trace.getTracer(TRACER_NAME3);
6800
+ const tracer = getProviderTracer(TRACER_NAME3);
6657
6801
  const model = opts?.model ?? "";
6658
6802
  const span2 = tracer.startSpan("openai.responses.create", {
6659
6803
  attributes: {
@@ -6663,9 +6807,9 @@ function tracedResponsesCreate(original) {
6663
6807
  "neatlogs.llm.model_name": model,
6664
6808
  "input.value": safeStringify3(opts?.input ?? "")
6665
6809
  }
6666
- }, import_api9.context.active());
6667
- const ctx = import_api9.trace.setSpan(import_api9.context.active(), span2);
6668
- const promise = import_api9.context.with(ctx, () => original(opts, ...rest));
6810
+ }, import_api11.context.active());
6811
+ const ctx = import_api11.trace.setSpan(import_api11.context.active(), span2);
6812
+ const promise = import_api11.context.with(ctx, () => original(opts, ...rest));
6669
6813
  return promise.then(
6670
6814
  (response) => {
6671
6815
  if (response?.output_text) {
@@ -6677,7 +6821,7 @@ function tracedResponsesCreate(original) {
6677
6821
  if (response.usage.input_tokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.usage.input_tokens);
6678
6822
  if (response.usage.output_tokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", response.usage.output_tokens);
6679
6823
  }
6680
- span2.setStatus({ code: import_api9.SpanStatusCode.OK });
6824
+ span2.setStatus({ code: import_api11.SpanStatusCode.OK });
6681
6825
  span2.end();
6682
6826
  return response;
6683
6827
  },
@@ -6692,7 +6836,7 @@ function wrapAsyncIterableStream(stream, span2) {
6692
6836
  const chunks = [];
6693
6837
  const originalAsyncIterator = stream[Symbol.asyncIterator]?.bind(stream);
6694
6838
  if (!originalAsyncIterator) {
6695
- span2.setStatus({ code: import_api9.SpanStatusCode.OK });
6839
+ span2.setStatus({ code: import_api11.SpanStatusCode.OK });
6696
6840
  span2.end();
6697
6841
  return stream;
6698
6842
  }
@@ -6778,7 +6922,7 @@ function finalizeStreamChunks(span2, chunks) {
6778
6922
  span2.setAttribute("neatlogs.llm.token_count.reasoning", usage.completion_tokens_details.reasoning_tokens);
6779
6923
  }
6780
6924
  }
6781
- span2.setStatus({ code: import_api9.SpanStatusCode.OK });
6925
+ span2.setStatus({ code: import_api11.SpanStatusCode.OK });
6782
6926
  span2.end();
6783
6927
  }
6784
6928
  function finalizeChatResponse(span2, response) {
@@ -6815,7 +6959,7 @@ function finalizeChatResponse(span2, response) {
6815
6959
  }
6816
6960
  }
6817
6961
  if (response?.model) span2.setAttribute("neatlogs.llm.model_name", response.model);
6818
- span2.setStatus({ code: import_api9.SpanStatusCode.OK });
6962
+ span2.setStatus({ code: import_api11.SpanStatusCode.OK });
6819
6963
  span2.end();
6820
6964
  }
6821
6965
  function setInvocationParams(span2, opts) {
@@ -6835,23 +6979,23 @@ function safeStringify3(value) {
6835
6979
  }
6836
6980
  function recordError(span2, err) {
6837
6981
  if (err instanceof Error) {
6838
- span2.setStatus({ code: import_api9.SpanStatusCode.ERROR, message: err.message });
6982
+ span2.setStatus({ code: import_api11.SpanStatusCode.ERROR, message: err.message });
6839
6983
  span2.recordException(err);
6840
6984
  } else {
6841
- span2.setStatus({ code: import_api9.SpanStatusCode.ERROR, message: String(err) });
6985
+ span2.setStatus({ code: import_api11.SpanStatusCode.ERROR, message: String(err) });
6842
6986
  }
6843
6987
  span2.end();
6844
6988
  }
6845
6989
 
6846
6990
  // src/anthropic.ts
6847
- var import_api10 = require("@opentelemetry/api");
6991
+ var import_api12 = require("@opentelemetry/api");
6848
6992
  var TRACER_NAME4 = "neatlogs.anthropic";
6849
6993
  function wrapAnthropic(client) {
6850
6994
  return wrapNamespace2(client, []);
6851
6995
  }
6852
6996
  function traceTool2(name, fn) {
6853
6997
  return async function tracedTool(input) {
6854
- const tracer = import_api10.trace.getTracer(TRACER_NAME4);
6998
+ const tracer = getProviderTracer(TRACER_NAME4);
6855
6999
  return tracer.startActiveSpan(
6856
7000
  `tool.${name}`,
6857
7001
  {
@@ -6861,12 +7005,12 @@ function traceTool2(name, fn) {
6861
7005
  "input.value": safeStringify4(input)
6862
7006
  }
6863
7007
  },
6864
- import_api10.context.active(),
7008
+ import_api12.context.active(),
6865
7009
  async (span2) => {
6866
7010
  try {
6867
7011
  const result = await fn(input);
6868
7012
  span2.setAttribute("output.value", safeStringify4(result));
6869
- span2.setStatus({ code: import_api10.SpanStatusCode.OK });
7013
+ span2.setStatus({ code: import_api12.SpanStatusCode.OK });
6870
7014
  return result;
6871
7015
  } catch (err) {
6872
7016
  recordError2(span2, err);
@@ -6905,7 +7049,7 @@ function isNamespace2(path4) {
6905
7049
  }
6906
7050
  function tracedMessagesCreate(original) {
6907
7051
  return function(opts, ...rest) {
6908
- const tracer = import_api10.trace.getTracer(TRACER_NAME4);
7052
+ const tracer = getProviderTracer(TRACER_NAME4);
6909
7053
  const model = opts?.model ?? "";
6910
7054
  const messages = opts?.messages ?? [];
6911
7055
  const isStream = opts?.stream === true;
@@ -6917,12 +7061,12 @@ function tracedMessagesCreate(original) {
6917
7061
  "neatlogs.llm.model_name": model,
6918
7062
  "neatlogs.llm.is_streaming": isStream
6919
7063
  }
6920
- }, import_api10.context.active());
7064
+ }, import_api12.context.active());
6921
7065
  setInputMessages(span2, opts?.system, messages);
6922
7066
  setTools(span2, opts?.tools);
6923
7067
  setInvocationParams2(span2, opts);
6924
- const ctx = import_api10.trace.setSpan(import_api10.context.active(), span2);
6925
- const promise = import_api10.context.with(ctx, () => original(opts, ...rest));
7068
+ const ctx = import_api12.trace.setSpan(import_api12.context.active(), span2);
7069
+ const promise = import_api12.context.with(ctx, () => original(opts, ...rest));
6926
7070
  return promise.then(
6927
7071
  (response) => {
6928
7072
  if (isStream) {
@@ -6940,7 +7084,7 @@ function tracedMessagesCreate(original) {
6940
7084
  }
6941
7085
  function tracedMessagesStream(original) {
6942
7086
  return function(opts, ...rest) {
6943
- const tracer = import_api10.trace.getTracer(TRACER_NAME4);
7087
+ const tracer = getProviderTracer(TRACER_NAME4);
6944
7088
  const model = opts?.model ?? "";
6945
7089
  const messages = opts?.messages ?? [];
6946
7090
  const span2 = tracer.startSpan("anthropic.messages.stream", {
@@ -6951,12 +7095,12 @@ function tracedMessagesStream(original) {
6951
7095
  "neatlogs.llm.model_name": model,
6952
7096
  "neatlogs.llm.is_streaming": true
6953
7097
  }
6954
- }, import_api10.context.active());
7098
+ }, import_api12.context.active());
6955
7099
  setInputMessages(span2, opts?.system, messages);
6956
7100
  setTools(span2, opts?.tools);
6957
7101
  setInvocationParams2(span2, opts);
6958
- const ctx = import_api10.trace.setSpan(import_api10.context.active(), span2);
6959
- const messageStream = import_api10.context.with(ctx, () => original(opts, ...rest));
7102
+ const ctx = import_api12.trace.setSpan(import_api12.context.active(), span2);
7103
+ const messageStream = import_api12.context.with(ctx, () => original(opts, ...rest));
6960
7104
  return wrapMessageStream(messageStream, span2);
6961
7105
  };
6962
7106
  }
@@ -6964,7 +7108,7 @@ function wrapStreamIterable(stream, span2) {
6964
7108
  const events = [];
6965
7109
  const originalAsyncIterator = stream[Symbol.asyncIterator]?.bind(stream);
6966
7110
  if (!originalAsyncIterator) {
6967
- span2.setStatus({ code: import_api10.SpanStatusCode.OK });
7111
+ span2.setStatus({ code: import_api12.SpanStatusCode.OK });
6968
7112
  span2.end();
6969
7113
  return stream;
6970
7114
  }
@@ -7013,7 +7157,7 @@ function wrapMessageStream(messageStream, span2) {
7013
7157
  if (finalMsg) {
7014
7158
  finalizeMessageResponse(span2, finalMsg);
7015
7159
  } else {
7016
- span2.setStatus({ code: import_api10.SpanStatusCode.OK });
7160
+ span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7017
7161
  span2.end();
7018
7162
  }
7019
7163
  });
@@ -7091,7 +7235,7 @@ function finalizeStreamEvents(span2, events) {
7091
7235
  if (model) span2.setAttribute("neatlogs.llm.model_name", model);
7092
7236
  if (stopReason) span2.setAttribute("neatlogs.llm.stop_reason", stopReason);
7093
7237
  setUsageAttrs(span2, usage);
7094
- span2.setStatus({ code: import_api10.SpanStatusCode.OK });
7238
+ span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7095
7239
  span2.end();
7096
7240
  }
7097
7241
  function finalizeMessageResponse(span2, response) {
@@ -7125,7 +7269,7 @@ function finalizeMessageResponse(span2, response) {
7125
7269
  setUsageAttrs(span2, response?.usage);
7126
7270
  if (response?.model) span2.setAttribute("neatlogs.llm.model_name", response.model);
7127
7271
  if (response?.stop_reason) span2.setAttribute("neatlogs.llm.stop_reason", response.stop_reason);
7128
- span2.setStatus({ code: import_api10.SpanStatusCode.OK });
7272
+ span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7129
7273
  span2.end();
7130
7274
  }
7131
7275
  function setInputMessages(span2, system, messages) {
@@ -7178,16 +7322,16 @@ function safeStringify4(value) {
7178
7322
  }
7179
7323
  function recordError2(span2, err) {
7180
7324
  if (err instanceof Error) {
7181
- span2.setStatus({ code: import_api10.SpanStatusCode.ERROR, message: err.message });
7325
+ span2.setStatus({ code: import_api12.SpanStatusCode.ERROR, message: err.message });
7182
7326
  span2.recordException(err);
7183
7327
  } else {
7184
- span2.setStatus({ code: import_api10.SpanStatusCode.ERROR, message: String(err) });
7328
+ span2.setStatus({ code: import_api12.SpanStatusCode.ERROR, message: String(err) });
7185
7329
  }
7186
7330
  span2.end();
7187
7331
  }
7188
7332
 
7189
7333
  // src/azure-openai.ts
7190
- var import_api11 = require("@opentelemetry/api");
7334
+ var import_api13 = require("@opentelemetry/api");
7191
7335
  var TRACER_NAME5 = "neatlogs.azure_openai";
7192
7336
  var PROVIDER = "azure";
7193
7337
  var SYSTEM = "azure";
@@ -7196,7 +7340,7 @@ function wrapAzureOpenAI(client) {
7196
7340
  }
7197
7341
  function traceTool3(name, fn) {
7198
7342
  return async function tracedTool(args) {
7199
- const tracer = import_api11.trace.getTracer(TRACER_NAME5);
7343
+ const tracer = getProviderTracer(TRACER_NAME5);
7200
7344
  return tracer.startActiveSpan(
7201
7345
  `tool.${name}`,
7202
7346
  {
@@ -7206,12 +7350,12 @@ function traceTool3(name, fn) {
7206
7350
  "input.value": safeStringify5(args)
7207
7351
  }
7208
7352
  },
7209
- import_api11.context.active(),
7353
+ import_api13.context.active(),
7210
7354
  async (span2) => {
7211
7355
  try {
7212
7356
  const result = await fn(args);
7213
7357
  span2.setAttribute("output.value", safeStringify5(result));
7214
- span2.setStatus({ code: import_api11.SpanStatusCode.OK });
7358
+ span2.setStatus({ code: import_api13.SpanStatusCode.OK });
7215
7359
  return result;
7216
7360
  } catch (err) {
7217
7361
  recordError3(span2, err);
@@ -7250,7 +7394,7 @@ function isNamespace3(path4) {
7250
7394
  }
7251
7395
  function tracedChatCompletionsCreate2(original) {
7252
7396
  return function(opts, ...rest) {
7253
- const tracer = import_api11.trace.getTracer(TRACER_NAME5);
7397
+ const tracer = getProviderTracer(TRACER_NAME5);
7254
7398
  const model = opts?.model ?? "";
7255
7399
  const messages = opts?.messages ?? [];
7256
7400
  const isStream = opts?.stream === true;
@@ -7262,7 +7406,7 @@ function tracedChatCompletionsCreate2(original) {
7262
7406
  "neatlogs.llm.model_name": model,
7263
7407
  "neatlogs.llm.is_streaming": isStream
7264
7408
  }
7265
- }, import_api11.context.active());
7409
+ }, import_api13.context.active());
7266
7410
  for (let i = 0; i < messages.length; i++) {
7267
7411
  const msg = messages[i];
7268
7412
  span2.setAttribute(`neatlogs.llm.input_messages.${i}.role`, msg.role ?? "");
@@ -7291,8 +7435,8 @@ function tracedChatCompletionsCreate2(original) {
7291
7435
  opts.stream_options = { ...streamOpts, include_usage: true };
7292
7436
  }
7293
7437
  }
7294
- const ctx = import_api11.trace.setSpan(import_api11.context.active(), span2);
7295
- const promise = import_api11.context.with(ctx, () => original(opts, ...rest));
7438
+ const ctx = import_api13.trace.setSpan(import_api13.context.active(), span2);
7439
+ const promise = import_api13.context.with(ctx, () => original(opts, ...rest));
7296
7440
  return promise.then(
7297
7441
  (response) => {
7298
7442
  if (isStream) {
@@ -7310,7 +7454,7 @@ function tracedChatCompletionsCreate2(original) {
7310
7454
  }
7311
7455
  function tracedResponsesCreate2(original) {
7312
7456
  return function(opts, ...rest) {
7313
- const tracer = import_api11.trace.getTracer(TRACER_NAME5);
7457
+ const tracer = getProviderTracer(TRACER_NAME5);
7314
7458
  const model = opts?.model ?? "";
7315
7459
  const span2 = tracer.startSpan("azure_openai.responses.create", {
7316
7460
  attributes: {
@@ -7320,9 +7464,9 @@ function tracedResponsesCreate2(original) {
7320
7464
  "neatlogs.llm.model_name": model,
7321
7465
  "input.value": safeStringify5(opts?.input ?? "")
7322
7466
  }
7323
- }, import_api11.context.active());
7324
- const ctx = import_api11.trace.setSpan(import_api11.context.active(), span2);
7325
- const promise = import_api11.context.with(ctx, () => original(opts, ...rest));
7467
+ }, import_api13.context.active());
7468
+ const ctx = import_api13.trace.setSpan(import_api13.context.active(), span2);
7469
+ const promise = import_api13.context.with(ctx, () => original(opts, ...rest));
7326
7470
  return promise.then(
7327
7471
  (response) => {
7328
7472
  if (response?.output_text) {
@@ -7334,7 +7478,7 @@ function tracedResponsesCreate2(original) {
7334
7478
  if (response.usage.input_tokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.usage.input_tokens);
7335
7479
  if (response.usage.output_tokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", response.usage.output_tokens);
7336
7480
  }
7337
- span2.setStatus({ code: import_api11.SpanStatusCode.OK });
7481
+ span2.setStatus({ code: import_api13.SpanStatusCode.OK });
7338
7482
  span2.end();
7339
7483
  return response;
7340
7484
  },
@@ -7349,7 +7493,7 @@ function wrapAsyncIterableStream2(stream, span2) {
7349
7493
  const chunks = [];
7350
7494
  const originalAsyncIterator = stream?.[Symbol.asyncIterator]?.bind(stream);
7351
7495
  if (!originalAsyncIterator) {
7352
- span2.setStatus({ code: import_api11.SpanStatusCode.OK });
7496
+ span2.setStatus({ code: import_api13.SpanStatusCode.OK });
7353
7497
  span2.end();
7354
7498
  return stream;
7355
7499
  }
@@ -7435,7 +7579,7 @@ function finalizeStreamChunks2(span2, chunks) {
7435
7579
  span2.setAttribute("neatlogs.llm.token_count.reasoning", usage.completion_tokens_details.reasoning_tokens);
7436
7580
  }
7437
7581
  }
7438
- span2.setStatus({ code: import_api11.SpanStatusCode.OK });
7582
+ span2.setStatus({ code: import_api13.SpanStatusCode.OK });
7439
7583
  span2.end();
7440
7584
  }
7441
7585
  function finalizeChatResponse2(span2, response) {
@@ -7472,7 +7616,7 @@ function finalizeChatResponse2(span2, response) {
7472
7616
  }
7473
7617
  }
7474
7618
  if (response?.model) span2.setAttribute("neatlogs.llm.model_name", response.model);
7475
- span2.setStatus({ code: import_api11.SpanStatusCode.OK });
7619
+ span2.setStatus({ code: import_api13.SpanStatusCode.OK });
7476
7620
  span2.end();
7477
7621
  }
7478
7622
  function setInvocationParams3(span2, opts) {
@@ -7492,16 +7636,16 @@ function safeStringify5(value) {
7492
7636
  }
7493
7637
  function recordError3(span2, err) {
7494
7638
  if (err instanceof Error) {
7495
- span2.setStatus({ code: import_api11.SpanStatusCode.ERROR, message: err.message });
7639
+ span2.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: err.message });
7496
7640
  span2.recordException(err);
7497
7641
  } else {
7498
- span2.setStatus({ code: import_api11.SpanStatusCode.ERROR, message: String(err) });
7642
+ span2.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: String(err) });
7499
7643
  }
7500
7644
  span2.end();
7501
7645
  }
7502
7646
 
7503
7647
  // src/vertex-ai.ts
7504
- var import_api12 = require("@opentelemetry/api");
7648
+ var import_api14 = require("@opentelemetry/api");
7505
7649
  var TRACER_NAME6 = "neatlogs.vertex_ai";
7506
7650
  var PROVIDER2 = "vertex_ai";
7507
7651
  var SYSTEM2 = "vertexai";
@@ -7510,7 +7654,7 @@ function wrapVertexAI(client) {
7510
7654
  }
7511
7655
  function traceTool4(name, fn) {
7512
7656
  return async function tracedTool(args) {
7513
- const tracer = import_api12.trace.getTracer(TRACER_NAME6);
7657
+ const tracer = getProviderTracer(TRACER_NAME6);
7514
7658
  return tracer.startActiveSpan(
7515
7659
  `tool.${name}`,
7516
7660
  {
@@ -7520,12 +7664,12 @@ function traceTool4(name, fn) {
7520
7664
  "input.value": safeStringify6(args)
7521
7665
  }
7522
7666
  },
7523
- import_api12.context.active(),
7667
+ import_api14.context.active(),
7524
7668
  async (span2) => {
7525
7669
  try {
7526
7670
  const result = await fn(args);
7527
7671
  span2.setAttribute("output.value", safeStringify6(result));
7528
- span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7672
+ span2.setStatus({ code: import_api14.SpanStatusCode.OK });
7529
7673
  return result;
7530
7674
  } catch (err) {
7531
7675
  recordError4(span2, err);
@@ -7586,7 +7730,7 @@ function wrapVertexAIChat(chat) {
7586
7730
  return chat;
7587
7731
  }
7588
7732
  function tracedChatSend(original, chat, params, rest, isStream) {
7589
- const tracer = import_api12.trace.getTracer(TRACER_NAME6);
7733
+ const tracer = getProviderTracer(TRACER_NAME6);
7590
7734
  const model = chat?.model ?? chat?.modelVersion ?? "";
7591
7735
  const span2 = tracer.startSpan("vertex_ai.chat.send_message", {
7592
7736
  attributes: {
@@ -7596,15 +7740,15 @@ function tracedChatSend(original, chat, params, rest, isStream) {
7596
7740
  "neatlogs.llm.model_name": model,
7597
7741
  "neatlogs.llm.is_streaming": isStream
7598
7742
  }
7599
- }, import_api12.context.active());
7743
+ }, import_api14.context.active());
7600
7744
  const message = params?.message ?? params;
7601
7745
  span2.setAttribute("neatlogs.llm.input_messages.0.role", "user");
7602
7746
  span2.setAttribute(
7603
7747
  "neatlogs.llm.input_messages.0.content",
7604
7748
  typeof message === "string" ? message : safeStringify6(message)
7605
7749
  );
7606
- const ctx = import_api12.trace.setSpan(import_api12.context.active(), span2);
7607
- const result = import_api12.context.with(ctx, () => original(params, ...rest));
7750
+ const ctx = import_api14.trace.setSpan(import_api14.context.active(), span2);
7751
+ const result = import_api14.context.with(ctx, () => original(params, ...rest));
7608
7752
  return Promise.resolve(result).then(
7609
7753
  (response) => {
7610
7754
  if (isStream) return wrapStream(response, span2);
@@ -7619,7 +7763,7 @@ function tracedChatSend(original, chat, params, rest, isStream) {
7619
7763
  }
7620
7764
  function tracedEmbedContent(original) {
7621
7765
  return function(opts, ...rest) {
7622
- const tracer = import_api12.trace.getTracer(TRACER_NAME6);
7766
+ const tracer = getProviderTracer(TRACER_NAME6);
7623
7767
  const span2 = tracer.startSpan("vertex_ai.models.embed_content", {
7624
7768
  attributes: {
7625
7769
  "neatlogs.span.kind": "EMBEDDING",
@@ -7627,9 +7771,9 @@ function tracedEmbedContent(original) {
7627
7771
  "neatlogs.embedding.model_name": opts?.model ?? "",
7628
7772
  "neatlogs.embedding.text": safeStringify6(opts?.contents ?? "")
7629
7773
  }
7630
- }, import_api12.context.active());
7631
- const ctx = import_api12.trace.setSpan(import_api12.context.active(), span2);
7632
- const result = import_api12.context.with(ctx, () => original(opts, ...rest));
7774
+ }, import_api14.context.active());
7775
+ const ctx = import_api14.trace.setSpan(import_api14.context.active(), span2);
7776
+ const result = import_api14.context.with(ctx, () => original(opts, ...rest));
7633
7777
  return Promise.resolve(result).then(
7634
7778
  (response) => {
7635
7779
  const embeddings = response?.embeddings;
@@ -7638,7 +7782,7 @@ function tracedEmbedContent(original) {
7638
7782
  const vals = embeddings[0]?.values;
7639
7783
  if (Array.isArray(vals)) span2.setAttribute("neatlogs.embedding.dimensions", vals.length);
7640
7784
  }
7641
- span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7785
+ span2.setStatus({ code: import_api14.SpanStatusCode.OK });
7642
7786
  span2.end();
7643
7787
  return response;
7644
7788
  },
@@ -7651,7 +7795,7 @@ function tracedEmbedContent(original) {
7651
7795
  }
7652
7796
  function tracedCountTokens(original) {
7653
7797
  return function(opts, ...rest) {
7654
- const tracer = import_api12.trace.getTracer(TRACER_NAME6);
7798
+ const tracer = getProviderTracer(TRACER_NAME6);
7655
7799
  const span2 = tracer.startSpan("vertex_ai.models.count_tokens", {
7656
7800
  attributes: {
7657
7801
  "neatlogs.span.kind": "LLM",
@@ -7659,13 +7803,13 @@ function tracedCountTokens(original) {
7659
7803
  "neatlogs.llm.task": "count_tokens",
7660
7804
  "neatlogs.llm.model_name": opts?.model ?? ""
7661
7805
  }
7662
- }, import_api12.context.active());
7663
- const ctx = import_api12.trace.setSpan(import_api12.context.active(), span2);
7664
- const result = import_api12.context.with(ctx, () => original(opts, ...rest));
7806
+ }, import_api14.context.active());
7807
+ const ctx = import_api14.trace.setSpan(import_api14.context.active(), span2);
7808
+ const result = import_api14.context.with(ctx, () => original(opts, ...rest));
7665
7809
  return Promise.resolve(result).then(
7666
7810
  (response) => {
7667
7811
  if (response?.totalTokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.totalTokens);
7668
- span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7812
+ span2.setStatus({ code: import_api14.SpanStatusCode.OK });
7669
7813
  span2.end();
7670
7814
  return response;
7671
7815
  },
@@ -7678,7 +7822,7 @@ function tracedCountTokens(original) {
7678
7822
  }
7679
7823
  function tracedGenerateContent(original, isStream) {
7680
7824
  return function(opts, ...rest) {
7681
- const tracer = import_api12.trace.getTracer(TRACER_NAME6);
7825
+ const tracer = getProviderTracer(TRACER_NAME6);
7682
7826
  const model = opts?.model ?? "";
7683
7827
  const span2 = tracer.startSpan("vertex_ai.models.generate_content", {
7684
7828
  attributes: {
@@ -7688,10 +7832,10 @@ function tracedGenerateContent(original, isStream) {
7688
7832
  "neatlogs.llm.model_name": model,
7689
7833
  "neatlogs.llm.is_streaming": isStream
7690
7834
  }
7691
- }, import_api12.context.active());
7835
+ }, import_api14.context.active());
7692
7836
  setInputAttributes(span2, opts);
7693
- const ctx = import_api12.trace.setSpan(import_api12.context.active(), span2);
7694
- const result = import_api12.context.with(ctx, () => original(opts, ...rest));
7837
+ const ctx = import_api14.trace.setSpan(import_api14.context.active(), span2);
7838
+ const result = import_api14.context.with(ctx, () => original(opts, ...rest));
7695
7839
  return Promise.resolve(result).then(
7696
7840
  (response) => {
7697
7841
  if (isStream) {
@@ -7838,7 +7982,7 @@ function finalizeStreamChunks3(span2, chunks) {
7838
7982
  }
7839
7983
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
7840
7984
  setUsage(span2, usage);
7841
- span2.setStatus({ code: import_api12.SpanStatusCode.OK });
7985
+ span2.setStatus({ code: import_api14.SpanStatusCode.OK });
7842
7986
  span2.end();
7843
7987
  }
7844
7988
  function finalizeResponse(span2, response) {
@@ -7864,7 +8008,7 @@ function finalizeResponse(span2, response) {
7864
8008
  span2.setAttribute("neatlogs.llm.output_messages.0.content", textParts.join(""));
7865
8009
  }
7866
8010
  setUsage(span2, response?.usageMetadata);
7867
- span2.setStatus({ code: import_api12.SpanStatusCode.OK });
8011
+ span2.setStatus({ code: import_api14.SpanStatusCode.OK });
7868
8012
  span2.end();
7869
8013
  }
7870
8014
  function setUsage(span2, usage) {
@@ -7884,21 +8028,21 @@ function safeStringify6(value) {
7884
8028
  }
7885
8029
  function recordError4(span2, err) {
7886
8030
  if (err instanceof Error) {
7887
- span2.setStatus({ code: import_api12.SpanStatusCode.ERROR, message: err.message });
8031
+ span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: err.message });
7888
8032
  span2.recordException(err);
7889
8033
  } else {
7890
- span2.setStatus({ code: import_api12.SpanStatusCode.ERROR, message: String(err) });
8034
+ span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: String(err) });
7891
8035
  }
7892
8036
  span2.end();
7893
8037
  }
7894
8038
 
7895
8039
  // src/bedrock.ts
7896
- var import_api13 = require("@opentelemetry/api");
8040
+ var import_api15 = require("@opentelemetry/api");
7897
8041
  var TRACER_NAME7 = "neatlogs.bedrock";
7898
8042
  var PROVIDER3 = "bedrock";
7899
8043
  function traceTool5(name, fn) {
7900
8044
  return async function tracedTool(args) {
7901
- const tracer = import_api13.trace.getTracer(TRACER_NAME7);
8045
+ const tracer = getProviderTracer(TRACER_NAME7);
7902
8046
  return tracer.startActiveSpan(
7903
8047
  `tool.${name}`,
7904
8048
  {
@@ -7908,12 +8052,12 @@ function traceTool5(name, fn) {
7908
8052
  "input.value": safeStringify7(args)
7909
8053
  }
7910
8054
  },
7911
- import_api13.context.active(),
8055
+ import_api15.context.active(),
7912
8056
  async (span2) => {
7913
8057
  try {
7914
8058
  const result = await fn(args);
7915
8059
  span2.setAttribute("output.value", safeStringify7(result));
7916
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8060
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
7917
8061
  return result;
7918
8062
  } catch (err) {
7919
8063
  recordError5(span2, err);
@@ -7959,7 +8103,7 @@ function vendorFromModel(modelId) {
7959
8103
  return vendor || "bedrock";
7960
8104
  }
7961
8105
  function startSpan(name, modelId, isStream) {
7962
- return import_api13.trace.getTracer(TRACER_NAME7).startSpan(name, {
8106
+ return getProviderTracer(TRACER_NAME7).startSpan(name, {
7963
8107
  attributes: {
7964
8108
  "neatlogs.span.kind": "LLM",
7965
8109
  "neatlogs.llm.provider": PROVIDER3,
@@ -7967,7 +8111,7 @@ function startSpan(name, modelId, isStream) {
7967
8111
  "neatlogs.llm.model_name": String(modelId ?? ""),
7968
8112
  "neatlogs.llm.is_streaming": isStream
7969
8113
  }
7970
- }, import_api13.context.active());
8114
+ }, import_api15.context.active());
7971
8115
  }
7972
8116
  function tracedConverse(originalSend, command, input, rest, isStream) {
7973
8117
  const span2 = startSpan(
@@ -7976,8 +8120,8 @@ function tracedConverse(originalSend, command, input, rest, isStream) {
7976
8120
  isStream
7977
8121
  );
7978
8122
  setConverseInput(span2, input);
7979
- const ctx = import_api13.trace.setSpan(import_api13.context.active(), span2);
7980
- const promise = import_api13.context.with(ctx, () => originalSend(command, ...rest));
8123
+ const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
8124
+ const promise = import_api15.context.with(ctx, () => originalSend(command, ...rest));
7981
8125
  return promise.then(
7982
8126
  (response) => {
7983
8127
  if (isStream) {
@@ -8057,7 +8201,7 @@ function finalizeConverse(span2, response) {
8057
8201
  }
8058
8202
  if (response?.stopReason) span2.setAttribute("neatlogs.llm.finish_reason", String(response.stopReason));
8059
8203
  setConverseUsage(span2, response?.usage);
8060
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8204
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8061
8205
  span2.end();
8062
8206
  }
8063
8207
  function setConverseUsage(span2, usage) {
@@ -8071,7 +8215,7 @@ function setConverseUsage(span2, usage) {
8071
8215
  function wrapConverseStream(response, span2) {
8072
8216
  const stream = response?.stream;
8073
8217
  if (!stream || typeof stream[Symbol.asyncIterator] !== "function") {
8074
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8218
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8075
8219
  span2.end();
8076
8220
  return response;
8077
8221
  }
@@ -8139,7 +8283,7 @@ function finalizeConverseStream(span2, textParts, toolCalls, finishReason, usage
8139
8283
  }
8140
8284
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8141
8285
  setConverseUsage(span2, usage);
8142
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8286
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8143
8287
  span2.end();
8144
8288
  }
8145
8289
  function isEmbeddingModel(modelId) {
@@ -8151,13 +8295,13 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
8151
8295
  const bodyIn = decodeBody(input?.body);
8152
8296
  let span2;
8153
8297
  if (isEmbedding) {
8154
- span2 = import_api13.trace.getTracer(TRACER_NAME7).startSpan("bedrock.invoke_model", {
8298
+ span2 = getProviderTracer(TRACER_NAME7).startSpan("bedrock.invoke_model", {
8155
8299
  attributes: {
8156
8300
  "neatlogs.span.kind": "EMBEDDING",
8157
8301
  "neatlogs.llm.provider": PROVIDER3,
8158
8302
  "neatlogs.embedding.model_name": String(input?.modelId ?? "")
8159
8303
  }
8160
- }, import_api13.context.active());
8304
+ }, import_api15.context.active());
8161
8305
  const text = bodyIn?.inputText ?? bodyIn?.texts ?? bodyIn?.input_text;
8162
8306
  if (text) {
8163
8307
  span2.setAttribute("neatlogs.embedding.text", typeof text === "string" ? text : safeStringify7(text));
@@ -8170,8 +8314,8 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
8170
8314
  );
8171
8315
  setInvokeInput(span2, vendor, bodyIn);
8172
8316
  }
8173
- const ctx = import_api13.trace.setSpan(import_api13.context.active(), span2);
8174
- const promise = import_api13.context.with(ctx, () => originalSend(command, ...rest));
8317
+ const ctx = import_api15.trace.setSpan(import_api15.context.active(), span2);
8318
+ const promise = import_api15.context.with(ctx, () => originalSend(command, ...rest));
8175
8319
  return promise.then(
8176
8320
  (response) => {
8177
8321
  if (isStream) {
@@ -8184,7 +8328,7 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
8184
8328
  finalizeInvoke(span2, vendor, decodeBody(response?.body));
8185
8329
  }
8186
8330
  } catch {
8187
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8331
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8188
8332
  span2.end();
8189
8333
  }
8190
8334
  return response;
@@ -8209,7 +8353,7 @@ function finalizeInvokeEmbedding(span2, body) {
8209
8353
  span2.setAttribute("neatlogs.llm.token_count.prompt", body.inputTextTokenCount);
8210
8354
  span2.setAttribute("neatlogs.embedding.token_count", body.inputTextTokenCount);
8211
8355
  }
8212
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8356
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8213
8357
  span2.end();
8214
8358
  }
8215
8359
  function decodeBody(body) {
@@ -8317,13 +8461,13 @@ function finalizeInvoke(span2, vendor, body) {
8317
8461
  span2.setAttribute("neatlogs.llm.token_count.total", promptTokens + completionTokens);
8318
8462
  }
8319
8463
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8320
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8464
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8321
8465
  span2.end();
8322
8466
  }
8323
8467
  function wrapInvokeStream(response, span2, vendor) {
8324
8468
  const body = response?.body;
8325
8469
  if (!body || typeof body[Symbol.asyncIterator] !== "function") {
8326
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8470
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8327
8471
  span2.end();
8328
8472
  return response;
8329
8473
  }
@@ -8341,7 +8485,7 @@ function wrapInvokeStream(response, span2, vendor) {
8341
8485
  if (promptTokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", promptTokens);
8342
8486
  if (completionTokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", completionTokens);
8343
8487
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
8344
- span2.setStatus({ code: import_api13.SpanStatusCode.OK });
8488
+ span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8345
8489
  span2.end();
8346
8490
  };
8347
8491
  const wrappedBody = {
@@ -8394,16 +8538,16 @@ function safeStringify7(value) {
8394
8538
  }
8395
8539
  function recordError5(span2, err) {
8396
8540
  if (err instanceof Error) {
8397
- span2.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: err.message });
8541
+ span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: err.message });
8398
8542
  span2.recordException(err);
8399
8543
  } else {
8400
- span2.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: String(err) });
8544
+ span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: String(err) });
8401
8545
  }
8402
8546
  span2.end();
8403
8547
  }
8404
8548
 
8405
8549
  // src/langchain.ts
8406
- var import_api14 = require("@opentelemetry/api");
8550
+ var import_api16 = require("@opentelemetry/api");
8407
8551
  var TRACER_NAME8 = "neatlogs.langchain";
8408
8552
  function langchainHandler(opts) {
8409
8553
  return new NeatlogsCallbackHandler(opts);
@@ -8411,16 +8555,42 @@ function langchainHandler(opts) {
8411
8555
  var NeatlogsCallbackHandler = class {
8412
8556
  name = "neatlogs";
8413
8557
  _spans = /* @__PURE__ */ new Map();
8558
+ // Auto-root spans keyed by the run-id of the child that triggered them.
8559
+ _autoRoots = /* @__PURE__ */ new Map();
8414
8560
  _workflowName;
8415
8561
  constructor(opts) {
8416
8562
  this._workflowName = opts?.workflowName;
8417
8563
  }
8564
+ // --- Self-rooting ----------------------------------------------------------
8565
+ //
8566
+ // A LangChain run can begin with ANY callback. When it begins with a non-root
8567
+ // kind (a bare `llm.invoke()` fires handleChatModelStart/handleLLMStart with no
8568
+ // chain above it; a standalone tool/retriever similarly), the span we create is
8569
+ // parentless and non-root -> the backend can't anchor the trace and it never
8570
+ // renders. Open a WORKFLOW root transparently in that case so just adding the
8571
+ // handler yields a complete trace. A top-level CHAIN is already root-eligible.
8572
+ _startCtx(parentRunId, runId, kind) {
8573
+ const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8574
+ if (parentSpan) {
8575
+ return import_api16.trace.setSpan(import_api16.context.active(), parentSpan);
8576
+ }
8577
+ const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8578
+ const { root, ctx } = maybeOpenAutoRoot(tracer, kind, import_api16.context.active());
8579
+ if (root) this._autoRoots.set(runId, root);
8580
+ return ctx;
8581
+ }
8582
+ _endAutoRoot(runId) {
8583
+ const root = this._autoRoots.get(runId);
8584
+ if (root) {
8585
+ endAutoRoot(root);
8586
+ this._autoRoots.delete(runId);
8587
+ }
8588
+ }
8418
8589
  // --- Chain/Graph callbacks ---
8419
8590
  async handleChainStart(serialized, inputs, runId, parentRunId, tags, metadata) {
8420
- const tracer = import_api14.trace.getTracer(TRACER_NAME8);
8591
+ const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8421
8592
  const name = serialized?.name ?? serialized?.id?.at(-1) ?? "chain";
8422
- const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8423
- const parentCtx = parentSpan ? import_api14.trace.setSpan(import_api14.context.active(), parentSpan) : import_api14.context.active();
8593
+ const parentCtx = this._startCtx(parentRunId, runId, "chain");
8424
8594
  const attrs = {
8425
8595
  "neatlogs.span.kind": "CHAIN",
8426
8596
  "neatlogs.chain.name": name
@@ -8435,24 +8605,25 @@ var NeatlogsCallbackHandler = class {
8435
8605
  const span2 = this._spans.get(runId);
8436
8606
  if (!span2) return;
8437
8607
  if (outputs) span2.setAttribute("output.value", safeStringify8(outputs));
8438
- span2.setStatus({ code: import_api14.SpanStatusCode.OK });
8608
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8439
8609
  span2.end();
8440
8610
  this._spans.delete(runId);
8611
+ this._endAutoRoot(runId);
8441
8612
  }
8442
8613
  async handleChainError(error, runId) {
8443
8614
  const span2 = this._spans.get(runId);
8444
8615
  if (!span2) return;
8445
- span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: error.message });
8616
+ span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8446
8617
  span2.recordException(error);
8447
8618
  span2.end();
8448
8619
  this._spans.delete(runId);
8620
+ this._endAutoRoot(runId);
8449
8621
  }
8450
8622
  // --- LLM callbacks ---
8451
8623
  async handleLLMStart(serialized, prompts, runId, parentRunId, extraParams) {
8452
- const tracer = import_api14.trace.getTracer(TRACER_NAME8);
8624
+ const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8453
8625
  const model = serialized?.kwargs?.model_name ?? serialized?.kwargs?.model ?? serialized?.name ?? "";
8454
- const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8455
- const parentCtx = parentSpan ? import_api14.trace.setSpan(import_api14.context.active(), parentSpan) : import_api14.context.active();
8626
+ const parentCtx = this._startCtx(parentRunId, runId, "llm");
8456
8627
  const attrs = {
8457
8628
  "neatlogs.span.kind": "LLM",
8458
8629
  "neatlogs.llm.provider": detectProvider(model),
@@ -8472,10 +8643,9 @@ var NeatlogsCallbackHandler = class {
8472
8643
  this._spans.set(runId, span2);
8473
8644
  }
8474
8645
  async handleChatModelStart(serialized, messages, runId, parentRunId, extraParams) {
8475
- const tracer = import_api14.trace.getTracer(TRACER_NAME8);
8646
+ const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8476
8647
  const model = serialized?.kwargs?.model_name ?? serialized?.kwargs?.model ?? serialized?.name ?? "";
8477
- const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8478
- const parentCtx = parentSpan ? import_api14.trace.setSpan(import_api14.context.active(), parentSpan) : import_api14.context.active();
8648
+ const parentCtx = this._startCtx(parentRunId, runId, "llm");
8479
8649
  const attrs = {
8480
8650
  "neatlogs.span.kind": "LLM",
8481
8651
  "neatlogs.llm.provider": detectProvider(model),
@@ -8533,26 +8703,27 @@ var NeatlogsCallbackHandler = class {
8533
8703
  span2.setAttribute("neatlogs.llm.token_count.total", usage.totalTokens ?? usage.total_tokens);
8534
8704
  }
8535
8705
  }
8536
- span2.setStatus({ code: import_api14.SpanStatusCode.OK });
8706
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8537
8707
  span2.end();
8538
8708
  this._spans.delete(runId);
8709
+ this._endAutoRoot(runId);
8539
8710
  }
8540
8711
  async handleLLMNewToken(_token, _idx, _runId) {
8541
8712
  }
8542
8713
  async handleLLMError(error, runId) {
8543
8714
  const span2 = this._spans.get(runId);
8544
8715
  if (!span2) return;
8545
- span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: error.message });
8716
+ span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8546
8717
  span2.recordException(error);
8547
8718
  span2.end();
8548
8719
  this._spans.delete(runId);
8720
+ this._endAutoRoot(runId);
8549
8721
  }
8550
8722
  // --- Tool callbacks ---
8551
8723
  async handleToolStart(serialized, input, runId, parentRunId, _tags, _metadata, runName, toolCallId) {
8552
- const tracer = import_api14.trace.getTracer(TRACER_NAME8);
8724
+ const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8553
8725
  const name = serialized?.name || runName || (Array.isArray(serialized?.id) ? serialized.id[serialized.id.length - 1] : void 0) || "tool";
8554
- const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8555
- const parentCtx = parentSpan ? import_api14.trace.setSpan(import_api14.context.active(), parentSpan) : import_api14.context.active();
8726
+ const parentCtx = this._startCtx(parentRunId, runId, "tool");
8556
8727
  const attrs = {
8557
8728
  "neatlogs.span.kind": "TOOL",
8558
8729
  "neatlogs.tool.name": name,
@@ -8566,24 +8737,25 @@ var NeatlogsCallbackHandler = class {
8566
8737
  const span2 = this._spans.get(runId);
8567
8738
  if (!span2) return;
8568
8739
  span2.setAttribute("output.value", String(output));
8569
- span2.setStatus({ code: import_api14.SpanStatusCode.OK });
8740
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8570
8741
  span2.end();
8571
8742
  this._spans.delete(runId);
8743
+ this._endAutoRoot(runId);
8572
8744
  }
8573
8745
  async handleToolError(error, runId) {
8574
8746
  const span2 = this._spans.get(runId);
8575
8747
  if (!span2) return;
8576
- span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: error.message });
8748
+ span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8577
8749
  span2.recordException(error);
8578
8750
  span2.end();
8579
8751
  this._spans.delete(runId);
8752
+ this._endAutoRoot(runId);
8580
8753
  }
8581
8754
  // --- Retriever callbacks ---
8582
8755
  async handleRetrieverStart(serialized, query, runId, parentRunId) {
8583
- const tracer = import_api14.trace.getTracer(TRACER_NAME8);
8756
+ const tracer = import_api16.trace.getTracer(TRACER_NAME8);
8584
8757
  const name = serialized?.name ?? "retriever";
8585
- const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
8586
- const parentCtx = parentSpan ? import_api14.trace.setSpan(import_api14.context.active(), parentSpan) : import_api14.context.active();
8758
+ const parentCtx = this._startCtx(parentRunId, runId, "retriever");
8587
8759
  const attrs = {
8588
8760
  "neatlogs.span.kind": "RETRIEVER",
8589
8761
  "neatlogs.retriever.name": name,
@@ -8604,17 +8776,19 @@ var NeatlogsCallbackHandler = class {
8604
8776
  }
8605
8777
  }
8606
8778
  }
8607
- span2.setStatus({ code: import_api14.SpanStatusCode.OK });
8779
+ span2.setStatus({ code: import_api16.SpanStatusCode.OK });
8608
8780
  span2.end();
8609
8781
  this._spans.delete(runId);
8782
+ this._endAutoRoot(runId);
8610
8783
  }
8611
8784
  async handleRetrieverError(error, runId) {
8612
8785
  const span2 = this._spans.get(runId);
8613
8786
  if (!span2) return;
8614
- span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: error.message });
8787
+ span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: error.message });
8615
8788
  span2.recordException(error);
8616
8789
  span2.end();
8617
8790
  this._spans.delete(runId);
8791
+ this._endAutoRoot(runId);
8618
8792
  }
8619
8793
  };
8620
8794
  function detectProvider(model) {
@@ -8783,7 +8957,7 @@ function safeStringify9(value) {
8783
8957
  }
8784
8958
 
8785
8959
  // src/openai-agents.ts
8786
- var import_api15 = require("@opentelemetry/api");
8960
+ var import_api17 = require("@opentelemetry/api");
8787
8961
  var TRACER_NAME9 = "neatlogs.openai_agents";
8788
8962
  function openaiAgentsProcessor() {
8789
8963
  return new NeatlogsTraceProcessor();
@@ -8793,13 +8967,13 @@ var NeatlogsTraceProcessor = class {
8793
8967
  _startTimes = /* @__PURE__ */ new Map();
8794
8968
  // The @openai/agents SDK passes a Trace object: { traceId, name, groupId, metadata }.
8795
8969
  onTraceStart(traceData) {
8796
- const tracer = import_api15.trace.getTracer(TRACER_NAME9);
8970
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8797
8971
  const attrs = { "neatlogs.span.kind": "WORKFLOW" };
8798
8972
  const workflowName = traceData?.name ?? traceData?.workflow_name;
8799
8973
  if (workflowName) attrs["neatlogs.workflow.name"] = workflowName;
8800
8974
  const traceId = traceData?.traceId ?? traceData?.trace_id;
8801
8975
  if (traceId) attrs["neatlogs.agent.trace_id"] = String(traceId);
8802
- const span2 = tracer.startSpan("openai_agents.trace", { attributes: attrs }, import_api15.context.active());
8976
+ const span2 = tracer.startSpan("openai_agents.trace", { attributes: attrs }, import_api17.context.active());
8803
8977
  const key = String(traceId ?? `trace_${Date.now()}`);
8804
8978
  this._spans.set(key, span2);
8805
8979
  this._startTimes.set(key, Date.now());
@@ -8812,7 +8986,7 @@ var NeatlogsTraceProcessor = class {
8812
8986
  if (startTime) {
8813
8987
  span2.setAttribute("neatlogs.metrics.duration_ms", Date.now() - startTime);
8814
8988
  }
8815
- span2.setStatus({ code: import_api15.SpanStatusCode.OK });
8989
+ span2.setStatus({ code: import_api17.SpanStatusCode.OK });
8816
8990
  span2.end();
8817
8991
  this._spans.delete(key);
8818
8992
  this._startTimes.delete(key);
@@ -8820,13 +8994,13 @@ var NeatlogsTraceProcessor = class {
8820
8994
  // The SDK passes a Span object: { type, spanId, traceId, parentId?, spanData: {...} }.
8821
8995
  // The meaningful payload (type, name, input, output, usage, ...) lives in `spanData`.
8822
8996
  onSpanStart(span2) {
8823
- const tracer = import_api15.trace.getTracer(TRACER_NAME9);
8997
+ const tracer = import_api17.trace.getTracer(TRACER_NAME9);
8824
8998
  const data = span2?.spanData ?? span2 ?? {};
8825
8999
  const spanType = data?.type ?? data?.span_type ?? span2?.type ?? "";
8826
9000
  const spanId = String(span2?.spanId ?? span2?.span_id ?? data?.span_id ?? `span_${Date.now()}`);
8827
9001
  const parentKey = String(span2?.parentId ?? span2?.traceId ?? span2?.trace_id ?? "");
8828
9002
  const parentSpan = this._spans.get(parentKey);
8829
- const parentCtx = parentSpan ? import_api15.trace.setSpan(import_api15.context.active(), parentSpan) : import_api15.context.active();
9003
+ const parentCtx = parentSpan ? import_api17.trace.setSpan(import_api17.context.active(), parentSpan) : import_api17.context.active();
8830
9004
  let otelSpan;
8831
9005
  if (spanType === "agent" || spanType === "agent_run") {
8832
9006
  const agentName = data?.name ?? data?.agent_name ?? "agent";
@@ -8935,13 +9109,13 @@ var NeatlogsTraceProcessor = class {
8935
9109
  const error = data?.error ?? span2?.error;
8936
9110
  if (error) {
8937
9111
  if (error instanceof Error) {
8938
- otelSpan.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: error.message });
9112
+ otelSpan.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: error.message });
8939
9113
  otelSpan.recordException(error);
8940
9114
  } else {
8941
- otelSpan.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: String(error) });
9115
+ otelSpan.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: String(error) });
8942
9116
  }
8943
9117
  } else {
8944
- otelSpan.setStatus({ code: import_api15.SpanStatusCode.OK });
9118
+ otelSpan.setStatus({ code: import_api17.SpanStatusCode.OK });
8945
9119
  }
8946
9120
  if (startTime) {
8947
9121
  otelSpan.setAttribute("neatlogs.llm.metrics.duration_ms", Date.now() - startTime);
@@ -8952,7 +9126,7 @@ var NeatlogsTraceProcessor = class {
8952
9126
  }
8953
9127
  shutdown() {
8954
9128
  for (const [, span2] of this._spans) {
8955
- span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: "Processor shutdown before span completed" });
9129
+ span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: "Processor shutdown before span completed" });
8956
9130
  span2.end();
8957
9131
  }
8958
9132
  this._spans.clear();
@@ -8970,7 +9144,7 @@ function safeStringify10(value) {
8970
9144
  }
8971
9145
 
8972
9146
  // src/mastra-wrap.ts
8973
- var import_api16 = require("@opentelemetry/api");
9147
+ var import_api18 = require("@opentelemetry/api");
8974
9148
  var TRACER_NAME10 = "neatlogs.mastra";
8975
9149
  var PATCH_FLAG2 = "_neatlogs_patched";
8976
9150
  function wrapMastra(entity) {
@@ -9037,11 +9211,11 @@ function patchAgentMethod(agent, method, streaming) {
9037
9211
  }
9038
9212
  if (streaming) attrs["neatlogs.llm.is_streaming"] = true;
9039
9213
  if (streaming) {
9040
- const tracer = import_api16.trace.getTracer(TRACER_NAME10);
9041
- const span2 = tracer.startSpan(`mastra.agent.${agentName}`, { attributes: attrs }, import_api16.context.active());
9042
- const ctx = import_api16.trace.setSpan(import_api16.context.active(), span2);
9214
+ const tracer = import_api18.trace.getTracer(TRACER_NAME10);
9215
+ const span2 = tracer.startSpan(`mastra.agent.${agentName}`, { attributes: attrs }, import_api18.context.active());
9216
+ const ctx = import_api18.trace.setSpan(import_api18.context.active(), span2);
9043
9217
  try {
9044
- const result = await import_api16.context.with(ctx, () => orig(input, opts));
9218
+ const result = await import_api18.context.with(ctx, () => orig(input, opts));
9045
9219
  return wrapStreamingOutput(result, span2, ctx);
9046
9220
  } catch (err) {
9047
9221
  recordError6(span2, err);
@@ -9245,7 +9419,7 @@ function wrapRootMastra(mastra) {
9245
9419
  }
9246
9420
  function wrapStreamingOutput(output, span2, ctx) {
9247
9421
  if (!output) {
9248
- span2.setStatus({ code: import_api16.SpanStatusCode.OK });
9422
+ span2.setStatus({ code: import_api18.SpanStatusCode.OK });
9249
9423
  span2.end();
9250
9424
  return output;
9251
9425
  }
@@ -9254,7 +9428,7 @@ function wrapStreamingOutput(output, span2, ctx) {
9254
9428
  if (ended) return;
9255
9429
  ended = true;
9256
9430
  if (err) recordError6(span2, err);
9257
- else span2.setStatus({ code: import_api16.SpanStatusCode.OK });
9431
+ else span2.setStatus({ code: import_api18.SpanStatusCode.OK });
9258
9432
  span2.end();
9259
9433
  };
9260
9434
  if (output.text && typeof output.text.then === "function") {
@@ -9345,7 +9519,7 @@ function rebindStreamContext(output, ctx) {
9345
9519
  const origIterator = value[Symbol.asyncIterator].bind(value);
9346
9520
  return {
9347
9521
  [Symbol.asyncIterator]() {
9348
- return import_api16.context.with(ctx, () => origIterator());
9522
+ return import_api18.context.with(ctx, () => origIterator());
9349
9523
  }
9350
9524
  };
9351
9525
  }
@@ -9455,13 +9629,13 @@ function recordUsage(span2, usage) {
9455
9629
  }
9456
9630
  }
9457
9631
  function withActiveSpan(name, attrs, fn) {
9458
- const tracer = import_api16.trace.getTracer(TRACER_NAME10);
9459
- const span2 = tracer.startSpan(name, { attributes: attrs }, import_api16.context.active());
9460
- const ctx = import_api16.trace.setSpan(import_api16.context.active(), span2);
9461
- return import_api16.context.with(ctx, async () => {
9632
+ const tracer = import_api18.trace.getTracer(TRACER_NAME10);
9633
+ const span2 = tracer.startSpan(name, { attributes: attrs }, import_api18.context.active());
9634
+ const ctx = import_api18.trace.setSpan(import_api18.context.active(), span2);
9635
+ return import_api18.context.with(ctx, async () => {
9462
9636
  try {
9463
9637
  const result = await fn(span2);
9464
- span2.setStatus({ code: import_api16.SpanStatusCode.OK });
9638
+ span2.setStatus({ code: import_api18.SpanStatusCode.OK });
9465
9639
  return result;
9466
9640
  } catch (err) {
9467
9641
  recordError6(span2, err);
@@ -9496,15 +9670,15 @@ function safeStringify11(value) {
9496
9670
  }
9497
9671
  function recordError6(span2, err) {
9498
9672
  if (err instanceof Error) {
9499
- span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: err.message });
9673
+ span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: err.message });
9500
9674
  span2.recordException(err);
9501
9675
  } else {
9502
- span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: String(err) });
9676
+ span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: String(err) });
9503
9677
  }
9504
9678
  }
9505
9679
 
9506
9680
  // src/pi-agent.ts
9507
- var import_api17 = require("@opentelemetry/api");
9681
+ var import_api19 = require("@opentelemetry/api");
9508
9682
  var TRACER_NAME11 = "neatlogs.pi-agent";
9509
9683
  var PATCH_FLAG3 = "_neatlogs_patched";
9510
9684
  function piAgentHooks(agent) {
@@ -9512,7 +9686,7 @@ function piAgentHooks(agent) {
9512
9686
  const a = agent;
9513
9687
  if (typeof a.subscribe !== "function") return agent;
9514
9688
  const state = { toolSpans: /* @__PURE__ */ new Map(), inputMessages: [] };
9515
- const tracer = import_api17.trace.getTracer(TRACER_NAME11);
9689
+ const tracer = import_api19.trace.getTracer(TRACER_NAME11);
9516
9690
  a.subscribe((event) => {
9517
9691
  try {
9518
9692
  handleEvent(tracer, state, event);
@@ -9528,10 +9702,10 @@ function handleEvent(tracer, state, event) {
9528
9702
  const span2 = tracer.startSpan(
9529
9703
  "pi_agent.run",
9530
9704
  { attributes: { "neatlogs.span.kind": "AGENT" } },
9531
- import_api17.context.active()
9705
+ import_api19.context.active()
9532
9706
  );
9533
9707
  state.agentSpan = span2;
9534
- state.agentCtx = import_api17.trace.setSpan(import_api17.context.active(), span2);
9708
+ state.agentCtx = import_api19.trace.setSpan(import_api19.context.active(), span2);
9535
9709
  state.inputMessages = [];
9536
9710
  break;
9537
9711
  }
@@ -9550,7 +9724,7 @@ function handleEvent(tracer, state, event) {
9550
9724
  break;
9551
9725
  }
9552
9726
  case "tool_execution_start": {
9553
- const parent = state.agentCtx ?? import_api17.context.active();
9727
+ const parent = state.agentCtx ?? import_api19.context.active();
9554
9728
  const span2 = tracer.startSpan(
9555
9729
  `pi_agent.tool.${event.toolName ?? "tool"}`,
9556
9730
  {
@@ -9572,10 +9746,10 @@ function handleEvent(tracer, state, event) {
9572
9746
  span2.setAttribute("output.value", safeStringify12(event.result));
9573
9747
  }
9574
9748
  if (event.isError) {
9575
- span2.setStatus({ code: import_api17.SpanStatusCode.ERROR });
9749
+ span2.setStatus({ code: import_api19.SpanStatusCode.ERROR });
9576
9750
  span2.setAttribute("neatlogs.tool.is_error", true);
9577
9751
  } else {
9578
- span2.setStatus({ code: import_api17.SpanStatusCode.OK });
9752
+ span2.setStatus({ code: import_api19.SpanStatusCode.OK });
9579
9753
  }
9580
9754
  span2.end();
9581
9755
  if (event.toolCallId) state.toolSpans.delete(event.toolCallId);
@@ -9594,7 +9768,7 @@ function handleEvent(tracer, state, event) {
9594
9768
  if (firstUser) state.agentSpan.setAttribute("input.value", firstUser.content);
9595
9769
  const finalText = lastAssistantText(event.messages);
9596
9770
  if (finalText) state.agentSpan.setAttribute("output.value", finalText);
9597
- state.agentSpan.setStatus({ code: import_api17.SpanStatusCode.OK });
9771
+ state.agentSpan.setStatus({ code: import_api19.SpanStatusCode.OK });
9598
9772
  state.agentSpan.end();
9599
9773
  state.agentSpan = void 0;
9600
9774
  state.agentCtx = void 0;
@@ -9646,13 +9820,13 @@ function emitLlmSpan(tracer, state, msg) {
9646
9820
  if (usage.cacheRead) attrs["neatlogs.llm.token_count.cache_read"] = usage.cacheRead;
9647
9821
  if (usage.cacheWrite) attrs["neatlogs.llm.token_count.cache_write"] = usage.cacheWrite;
9648
9822
  }
9649
- const parent = state.agentCtx ?? import_api17.context.active();
9823
+ const parent = state.agentCtx ?? import_api19.context.active();
9650
9824
  const span2 = tracer.startSpan(
9651
9825
  `pi_agent.llm.${msg.model || "model"}`,
9652
9826
  { attributes: attrs },
9653
9827
  parent
9654
9828
  );
9655
- span2.setStatus({ code: import_api17.SpanStatusCode.OK });
9829
+ span2.setStatus({ code: import_api19.SpanStatusCode.OK });
9656
9830
  span2.end();
9657
9831
  }
9658
9832
  function splitAssistantContent(content) {
@@ -9713,7 +9887,7 @@ function safeStringify12(value) {
9713
9887
  }
9714
9888
 
9715
9889
  // src/claude-agent-sdk.ts
9716
- var import_api18 = require("@opentelemetry/api");
9890
+ var import_api20 = require("@opentelemetry/api");
9717
9891
  var TRACER_NAME12 = "neatlogs.claude_agent_sdk";
9718
9892
  var ROOT_SCOPE = "__root__";
9719
9893
  function wrapClaudeAgentSDK(sdk, options = {}) {
@@ -9734,13 +9908,13 @@ function wrapClaudeAgentSDK(sdk, options = {}) {
9734
9908
  }
9735
9909
  function wrapQuery(original, options) {
9736
9910
  return function(params, ...rest) {
9737
- const tracer = import_api18.trace.getTracer(TRACER_NAME12);
9911
+ const tracer = import_api20.trace.getTracer(TRACER_NAME12);
9738
9912
  const workflowName = options.workflowName ?? "claude_agent.query";
9739
9913
  const promptRef = { text: "" };
9740
9914
  const agentSpan = tracer.startSpan(
9741
9915
  "claude_agent.query",
9742
9916
  { attributes: { "neatlogs.span.kind": "AGENT", "neatlogs.workflow.name": workflowName } },
9743
- import_api18.context.active()
9917
+ import_api20.context.active()
9744
9918
  );
9745
9919
  const promptText = extractPromptText(params?.prompt);
9746
9920
  if (promptText) {
@@ -9749,8 +9923,8 @@ function wrapQuery(original, options) {
9749
9923
  } else if (params && isAsyncIterable(params.prompt)) {
9750
9924
  params = { ...params, prompt: tapPromptStream(params.prompt, promptRef) };
9751
9925
  }
9752
- const agentCtx = import_api18.trace.setSpan(import_api18.context.active(), agentSpan);
9753
- const queryObj = import_api18.context.with(agentCtx, () => original(params, ...rest));
9926
+ const agentCtx = import_api20.trace.setSpan(import_api20.context.active(), agentSpan);
9927
+ const queryObj = import_api20.context.with(agentCtx, () => original(params, ...rest));
9754
9928
  return instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRef);
9755
9929
  };
9756
9930
  }
@@ -9769,7 +9943,7 @@ async function* tapPromptStream(prompt, ref) {
9769
9943
  function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRef) {
9770
9944
  const originalAsyncIterator = queryObj?.[Symbol.asyncIterator]?.bind(queryObj);
9771
9945
  if (!originalAsyncIterator) {
9772
- agentSpan.setStatus({ code: import_api18.SpanStatusCode.OK });
9946
+ agentSpan.setStatus({ code: import_api20.SpanStatusCode.OK });
9773
9947
  agentSpan.end();
9774
9948
  return queryObj;
9775
9949
  }
@@ -9806,7 +9980,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
9806
9980
  if (status === "error") {
9807
9981
  recordError7(agentSpan, err);
9808
9982
  } else {
9809
- agentSpan.setStatus({ code: import_api18.SpanStatusCode.OK });
9983
+ agentSpan.setStatus({ code: import_api20.SpanStatusCode.OK });
9810
9984
  agentSpan.end();
9811
9985
  }
9812
9986
  };
@@ -9817,7 +9991,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
9817
9991
  return {
9818
9992
  async next() {
9819
9993
  try {
9820
- const result = await import_api18.context.with(agentCtx, () => iterator.next());
9994
+ const result = await import_api20.context.with(agentCtx, () => iterator.next());
9821
9995
  if (result.done) {
9822
9996
  finalizeAgent("ok");
9823
9997
  return result;
@@ -9848,7 +10022,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
9848
10022
  function closeScope(scope, status) {
9849
10023
  try {
9850
10024
  if (scope.finalText) scope.span.setAttribute("output.value", scope.finalText);
9851
- scope.span.setStatus({ code: status === "ok" ? import_api18.SpanStatusCode.OK : import_api18.SpanStatusCode.ERROR });
10025
+ scope.span.setStatus({ code: status === "ok" ? import_api20.SpanStatusCode.OK : import_api20.SpanStatusCode.ERROR });
9852
10026
  scope.span.end();
9853
10027
  } catch {
9854
10028
  }
@@ -9863,7 +10037,7 @@ function getScope(tracer, state, msg) {
9863
10037
  flushAssistantTurn(tracer, root, state);
9864
10038
  }
9865
10039
  const parentToolSpan = state.toolSpans.get(parentId);
9866
- const parentCtx = parentToolSpan ? import_api18.trace.setSpan(import_api18.context.active(), parentToolSpan) : state.scopes.get(ROOT_SCOPE).ctx;
10040
+ const parentCtx = parentToolSpan ? import_api20.trace.setSpan(import_api20.context.active(), parentToolSpan) : state.scopes.get(ROOT_SCOPE).ctx;
9867
10041
  const subType = msg?.subagent_type ? String(msg.subagent_type) : "subagent";
9868
10042
  const attrs = {
9869
10043
  "neatlogs.span.kind": "AGENT",
@@ -9873,7 +10047,7 @@ function getScope(tracer, state, msg) {
9873
10047
  const span2 = tracer.startSpan(`claude_agent.subagent.${subType}`, { attributes: attrs }, parentCtx);
9874
10048
  const scope = {
9875
10049
  span: span2,
9876
- ctx: import_api18.trace.setSpan(import_api18.context.active(), span2),
10050
+ ctx: import_api20.trace.setSpan(import_api20.context.active(), span2),
9877
10051
  inputMessages: msg?.task_description ? [{ role: "user", content: String(msg.task_description) }] : [],
9878
10052
  assistantBuffer: null,
9879
10053
  finalText: "",
@@ -9997,7 +10171,7 @@ function flushAssistantTurn(tracer, scope, state) {
9997
10171
  if (buf.stopReason) attrs["neatlogs.llm.finish_reason"] = String(buf.stopReason);
9998
10172
  const span2 = tracer.startSpan(`claude_agent.llm.${model || "model"}`, { attributes: attrs }, scope.ctx);
9999
10173
  if (buf.usage) setUsage2(span2, buf.usage);
10000
- span2.setStatus({ code: import_api18.SpanStatusCode.OK });
10174
+ span2.setStatus({ code: import_api20.SpanStatusCode.OK });
10001
10175
  span2.end();
10002
10176
  if (outText) scope.finalText = outText;
10003
10177
  const turnParts = [];
@@ -10032,10 +10206,10 @@ function closeToolSpansFromUser(state, scope, msg) {
10032
10206
  if (!span2) continue;
10033
10207
  span2.setAttribute("output.value", outText);
10034
10208
  if (block.is_error) {
10035
- span2.setStatus({ code: import_api18.SpanStatusCode.ERROR });
10209
+ span2.setStatus({ code: import_api20.SpanStatusCode.ERROR });
10036
10210
  span2.setAttribute("neatlogs.tool.is_error", true);
10037
10211
  } else {
10038
- span2.setStatus({ code: import_api18.SpanStatusCode.OK });
10212
+ span2.setStatus({ code: import_api20.SpanStatusCode.OK });
10039
10213
  }
10040
10214
  span2.end();
10041
10215
  state.toolSpans.delete(id);
@@ -10082,16 +10256,16 @@ function safeStringify13(value) {
10082
10256
  }
10083
10257
  function recordError7(span2, err) {
10084
10258
  if (err instanceof Error) {
10085
- span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: err.message });
10259
+ span2.setStatus({ code: import_api20.SpanStatusCode.ERROR, message: err.message });
10086
10260
  span2.recordException(err);
10087
10261
  } else {
10088
- span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: String(err) });
10262
+ span2.setStatus({ code: import_api20.SpanStatusCode.ERROR, message: String(err) });
10089
10263
  }
10090
10264
  span2.end();
10091
10265
  }
10092
10266
 
10093
10267
  // src/openrouter-agent.ts
10094
- var import_api19 = require("@opentelemetry/api");
10268
+ var import_api21 = require("@opentelemetry/api");
10095
10269
  var TRACER_NAME13 = "neatlogs.openrouter_agent";
10096
10270
  var PROVIDER4 = "openrouter";
10097
10271
  function wrapOpenRouterAgent(client) {
@@ -10110,21 +10284,21 @@ function wrapOpenRouterAgent(client) {
10110
10284
  function wrapCallModel(callModel) {
10111
10285
  return function(clientArg, opts, ...rest) {
10112
10286
  const span2 = startLlmSpan(opts);
10113
- const ctx = import_api19.trace.setSpan(import_api19.context.active(), span2);
10114
- const result = import_api19.context.with(ctx, () => callModel.call(this, clientArg, opts, ...rest));
10287
+ const ctx = import_api21.trace.setSpan(import_api21.context.active(), span2);
10288
+ const result = import_api21.context.with(ctx, () => callModel.call(this, clientArg, opts, ...rest));
10115
10289
  return instrumentModelResult(result, span2);
10116
10290
  };
10117
10291
  }
10118
10292
  function tracedCallModel(original) {
10119
10293
  return function(opts, ...rest) {
10120
10294
  const span2 = startLlmSpan(opts);
10121
- const ctx = import_api19.trace.setSpan(import_api19.context.active(), span2);
10122
- const result = import_api19.context.with(ctx, () => original(opts, ...rest));
10295
+ const ctx = import_api21.trace.setSpan(import_api21.context.active(), span2);
10296
+ const result = import_api21.context.with(ctx, () => original(opts, ...rest));
10123
10297
  return instrumentModelResult(result, span2);
10124
10298
  };
10125
10299
  }
10126
10300
  function startLlmSpan(opts) {
10127
- const tracer = import_api19.trace.getTracer(TRACER_NAME13);
10301
+ const tracer = getProviderTracer(TRACER_NAME13);
10128
10302
  const model = opts?.model ?? "";
10129
10303
  const span2 = tracer.startSpan("openrouter.call_model", {
10130
10304
  attributes: {
@@ -10133,7 +10307,7 @@ function startLlmSpan(opts) {
10133
10307
  "neatlogs.llm.system": PROVIDER4,
10134
10308
  "neatlogs.llm.model_name": model
10135
10309
  }
10136
- }, import_api19.context.active());
10310
+ }, import_api21.context.active());
10137
10311
  const messages = Array.isArray(opts?.messages) ? opts.messages : Array.isArray(opts?.input) ? opts.input : [];
10138
10312
  if (messages.length) {
10139
10313
  messages.forEach((msg, i) => {
@@ -10185,7 +10359,7 @@ function startLlmSpan(opts) {
10185
10359
  }
10186
10360
  function instrumentModelResult(result, span2) {
10187
10361
  if (!result || typeof result !== "object" && typeof result !== "function") {
10188
- span2.setStatus({ code: import_api19.SpanStatusCode.OK });
10362
+ span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10189
10363
  span2.end();
10190
10364
  return result;
10191
10365
  }
@@ -10196,7 +10370,7 @@ function instrumentModelResult(result, span2) {
10196
10370
  try {
10197
10371
  finalizeLlm(span2, resolved);
10198
10372
  } catch {
10199
- span2.setStatus({ code: import_api19.SpanStatusCode.OK });
10373
+ span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10200
10374
  span2.end();
10201
10375
  }
10202
10376
  };
@@ -10299,7 +10473,7 @@ function finalizeLlm(span2, result) {
10299
10473
  const finishReason = result?.finishReason ?? result?.finish_reason ?? result?.choices?.[0]?.finish_reason;
10300
10474
  if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
10301
10475
  setOpenResponsesUsage(span2, result);
10302
- span2.setStatus({ code: import_api19.SpanStatusCode.OK });
10476
+ span2.setStatus({ code: import_api21.SpanStatusCode.OK });
10303
10477
  span2.end();
10304
10478
  }
10305
10479
  function extractOpenResponsesText(result) {
@@ -10325,10 +10499,10 @@ function safeStringify14(value) {
10325
10499
  }
10326
10500
  function recordError8(span2, err) {
10327
10501
  if (err instanceof Error) {
10328
- span2.setStatus({ code: import_api19.SpanStatusCode.ERROR, message: err.message });
10502
+ span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: err.message });
10329
10503
  span2.recordException(err);
10330
10504
  } else {
10331
- span2.setStatus({ code: import_api19.SpanStatusCode.ERROR, message: String(err) });
10505
+ span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: String(err) });
10332
10506
  }
10333
10507
  span2.end();
10334
10508
  }
@@ -10966,7 +11140,7 @@ function safeStringify15(value) {
10966
11140
  }
10967
11141
 
10968
11142
  // src/core/llm-binder.ts
10969
- var logger15 = getLogger();
11143
+ var logger16 = getLogger();
10970
11144
  function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
10971
11145
  const systemStr = String(systemTpl.template);
10972
11146
  const userStr = userTpl ? String(userTpl.template) : null;
@@ -10978,7 +11152,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
10978
11152
  llmCopy = structuredClone(llm);
10979
11153
  } catch {
10980
11154
  llmCopy = llm;
10981
- logger15.debug(
11155
+ logger16.debug(
10982
11156
  `LLM type ${llm?.constructor?.name ?? "unknown"} is not copyable \u2014 binding in place.`
10983
11157
  );
10984
11158
  }
@@ -10989,7 +11163,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
10989
11163
  } else if (typeof llmCopy.call === "function") {
10990
11164
  methodName = "call";
10991
11165
  } else {
10992
- logger15.warn(
11166
+ logger16.warn(
10993
11167
  `LLM type ${llm?.constructor?.name ?? "unknown"} has neither invoke() nor call() \u2014 prompt templates will not be captured on spans.`
10994
11168
  );
10995
11169
  return llmCopy;
@@ -11009,7 +11183,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
11009
11183
  }
11010
11184
  }
11011
11185
  };
11012
- logger15.debug(
11186
+ logger16.debug(
11013
11187
  `Wrapped ${llm?.constructor?.name ?? "unknown"}.${methodName}() with template injection.`
11014
11188
  );
11015
11189
  return llmCopy;