@probelabs/probe 0.6.0-rc299 → 0.6.0-rc301

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.
@@ -22,7 +22,8 @@ var simpleTelemetry_exports = {};
22
22
  __export(simpleTelemetry_exports, {
23
23
  SimpleAppTracer: () => SimpleAppTracer,
24
24
  SimpleTelemetry: () => SimpleTelemetry,
25
- initializeSimpleTelemetryFromOptions: () => initializeSimpleTelemetryFromOptions
25
+ initializeSimpleTelemetryFromOptions: () => initializeSimpleTelemetryFromOptions,
26
+ truncateForSpan: () => truncateForSpan
26
27
  });
27
28
  module.exports = __toCommonJS(simpleTelemetry_exports);
28
29
  var import_fs = require("fs");
@@ -138,6 +139,14 @@ function patchConsole() {
138
139
  }
139
140
 
140
141
  // src/agent/simpleTelemetry.js
142
+ function truncateForSpan(text, maxLen = 4096) {
143
+ if (!text || text.length <= maxLen) return text || "";
144
+ const half = Math.floor((maxLen - 40) / 2);
145
+ const omitted = text.length - half * 2;
146
+ return text.substring(0, half) + `
147
+ ... [${omitted} chars omitted] ...
148
+ ` + text.substring(text.length - half);
149
+ }
141
150
  var SimpleTelemetry = class {
142
151
  constructor(options = {}) {
143
152
  this.serviceName = options.serviceName || "probe-agent";
@@ -530,7 +539,7 @@ var SimpleAppTracer = class {
530
539
  "tokens.context_remaining": tokenData.maxContextTokens ? tokenData.maxContextTokens - (tokenData.contextTokens || 0) : null
531
540
  });
532
541
  }
533
- async withSpan(spanName, fn, attributes = {}) {
542
+ async withSpan(spanName, fn, attributes = {}, onResult = null) {
534
543
  if (!this.isEnabled()) {
535
544
  return fn();
536
545
  }
@@ -541,6 +550,12 @@ var SimpleAppTracer = class {
541
550
  try {
542
551
  const result = await fn();
543
552
  span.setStatus("OK");
553
+ if (onResult) {
554
+ try {
555
+ onResult(span, result);
556
+ } catch (_) {
557
+ }
558
+ }
544
559
  return result;
545
560
  } catch (error) {
546
561
  span.setStatus("ERROR");
@@ -578,5 +593,6 @@ function initializeSimpleTelemetryFromOptions(options) {
578
593
  0 && (module.exports = {
579
594
  SimpleAppTracer,
580
595
  SimpleTelemetry,
581
- initializeSimpleTelemetryFromOptions
596
+ initializeSimpleTelemetryFromOptions,
597
+ truncateForSpan
582
598
  });