raindrop-ai 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -720,11 +720,11 @@ var require_lodash = __commonJS({
720
720
  function unicodeWords(string) {
721
721
  return string.match(reUnicodeWord) || [];
722
722
  }
723
- var runInContext = (function runInContext2(context6) {
724
- context6 = context6 == null ? root : _.defaults(root.Object(), context6, _.pick(root, contextProps));
725
- var Array2 = context6.Array, Date2 = context6.Date, Error2 = context6.Error, Function2 = context6.Function, Math2 = context6.Math, Object2 = context6.Object, RegExp2 = context6.RegExp, String2 = context6.String, TypeError2 = context6.TypeError;
723
+ var runInContext = (function runInContext2(context7) {
724
+ context7 = context7 == null ? root : _.defaults(root.Object(), context7, _.pick(root, contextProps));
725
+ var Array2 = context7.Array, Date2 = context7.Date, Error2 = context7.Error, Function2 = context7.Function, Math2 = context7.Math, Object2 = context7.Object, RegExp2 = context7.RegExp, String2 = context7.String, TypeError2 = context7.TypeError;
726
726
  var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
727
- var coreJsData = context6["__core-js_shared__"];
727
+ var coreJsData = context7["__core-js_shared__"];
728
728
  var funcToString = funcProto.toString;
729
729
  var hasOwnProperty = objectProto.hasOwnProperty;
730
730
  var idCounter = 0;
@@ -738,7 +738,7 @@ var require_lodash = __commonJS({
738
738
  var reIsNative = RegExp2(
739
739
  "^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
740
740
  );
741
- var Buffer2 = moduleExports ? context6.Buffer : undefined2, Symbol2 = context6.Symbol, Uint8Array2 = context6.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined2, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined2, symIterator = Symbol2 ? Symbol2.iterator : undefined2, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined2;
741
+ var Buffer2 = moduleExports ? context7.Buffer : undefined2, Symbol2 = context7.Symbol, Uint8Array2 = context7.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined2, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined2, symIterator = Symbol2 ? Symbol2.iterator : undefined2, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined2;
742
742
  var defineProperty = (function() {
743
743
  try {
744
744
  var func = getNative(Object2, "defineProperty");
@@ -747,9 +747,9 @@ var require_lodash = __commonJS({
747
747
  } catch (e) {
748
748
  }
749
749
  })();
750
- var ctxClearTimeout = context6.clearTimeout !== root.clearTimeout && context6.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context6.setTimeout !== root.setTimeout && context6.setTimeout;
751
- var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context6.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context6.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
752
- var DataView = getNative(context6, "DataView"), Map2 = getNative(context6, "Map"), Promise2 = getNative(context6, "Promise"), Set2 = getNative(context6, "Set"), WeakMap = getNative(context6, "WeakMap"), nativeCreate = getNative(Object2, "create");
750
+ var ctxClearTimeout = context7.clearTimeout !== root.clearTimeout && context7.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context7.setTimeout !== root.setTimeout && context7.setTimeout;
751
+ var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context7.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context7.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
752
+ var DataView = getNative(context7, "DataView"), Map2 = getNative(context7, "Map"), Promise2 = getNative(context7, "Promise"), Set2 = getNative(context7, "Set"), WeakMap = getNative(context7, "WeakMap"), nativeCreate = getNative(Object2, "create");
753
753
  var metaMap = WeakMap && new WeakMap();
754
754
  var realNames = {};
755
755
  var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map2), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set2), weakMapCtorString = toSource(WeakMap);
@@ -10977,7 +10977,7 @@ var SignalEventSchema = external_exports.object({
10977
10977
  // package.json
10978
10978
  var package_default = {
10979
10979
  name: "raindrop-ai",
10980
- version: "0.3.1",
10980
+ version: "0.4.0",
10981
10981
  main: "dist/index.js",
10982
10982
  module: "dist/index.mjs",
10983
10983
  types: "dist/index.d.ts",
@@ -11031,7 +11031,6 @@ var package_default = {
11031
11031
  "@raindrop-ai/redact-pii": "workspace:*",
11032
11032
  "@raindrop-ai/schemas": "workspace:*",
11033
11033
  ai: "^6.0.0",
11034
- "@opentelemetry/resources": "^2.0.1",
11035
11034
  "@types/node": "^20.11.17",
11036
11035
  msw: "^2.12.8",
11037
11036
  tsup: "^8.4.0",
@@ -11042,9 +11041,25 @@ var package_default = {
11042
11041
  },
11043
11042
  dependencies: {
11044
11043
  "@opentelemetry/api": "^1.9.0",
11044
+ "@opentelemetry/core": "^1.30.1",
11045
11045
  "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
11046
11046
  "@opentelemetry/exporter-trace-otlp-proto": "^0.57.2",
11047
- "@traceloop/node-server-sdk": "0.19.0-otel-v1",
11047
+ "@opentelemetry/instrumentation": "^0.57.2",
11048
+ "@opentelemetry/resources": "^1.30.1",
11049
+ "@opentelemetry/sdk-trace-base": "^1.30.1",
11050
+ "@opentelemetry/sdk-trace-node": "^1.30.1",
11051
+ "@traceloop/ai-semantic-conventions": "0.19.0-otel-v1",
11052
+ "@traceloop/instrumentation-anthropic": "0.19.0-otel-v1",
11053
+ "@traceloop/instrumentation-openai": "0.19.0-otel-v1",
11054
+ "@traceloop/instrumentation-cohere": "0.19.0-otel-v1",
11055
+ "@traceloop/instrumentation-bedrock": "0.19.0-otel-v1",
11056
+ "@traceloop/instrumentation-vertexai": "0.19.0-otel-v1",
11057
+ "@traceloop/instrumentation-pinecone": "0.19.0-otel-v1",
11058
+ "@traceloop/instrumentation-chromadb": "0.19.0-otel-v1",
11059
+ "@traceloop/instrumentation-qdrant": "0.19.0-otel-v1",
11060
+ "@traceloop/instrumentation-together": "0.19.0-otel-v1",
11061
+ "@traceloop/instrumentation-langchain": "0.19.0-otel-v1",
11062
+ "@traceloop/instrumentation-llamaindex": "0.19.0-otel-v1",
11048
11063
  weakref: "^0.2.1",
11049
11064
  zod: "^3.23.8"
11050
11065
  },
@@ -11063,7 +11078,6 @@ var package_default = {
11063
11078
  "esm"
11064
11079
  ],
11065
11080
  external: [
11066
- "@traceloop/node-server-sdk",
11067
11081
  "@traceloop/instrumentation-anthropic",
11068
11082
  "@traceloop/instrumentation-openai",
11069
11083
  "@traceloop/instrumentation-cohere",
@@ -11073,10 +11087,17 @@ var package_default = {
11073
11087
  "@traceloop/instrumentation-chromadb",
11074
11088
  "@traceloop/instrumentation-qdrant",
11075
11089
  "@traceloop/instrumentation-together",
11090
+ "@traceloop/instrumentation-langchain",
11091
+ "@traceloop/instrumentation-llamaindex",
11092
+ "@traceloop/ai-semantic-conventions",
11093
+ "@opentelemetry/api",
11094
+ "@opentelemetry/core",
11076
11095
  "@opentelemetry/instrumentation",
11077
11096
  "@opentelemetry/exporter-trace-otlp-http",
11078
11097
  "@opentelemetry/exporter-trace-otlp-proto",
11079
- "@opentelemetry/sdk-trace-base"
11098
+ "@opentelemetry/resources",
11099
+ "@opentelemetry/sdk-trace-base",
11100
+ "@opentelemetry/sdk-trace-node"
11080
11101
  ],
11081
11102
  noExternal: [
11082
11103
  "@raindrop-ai/core",
@@ -11180,18 +11201,411 @@ function redactPII(event) {
11180
11201
  }
11181
11202
 
11182
11203
  // src/tracing/tracer-core.ts
11183
- var import_api5 = require("@opentelemetry/api");
11204
+ var import_api6 = require("@opentelemetry/api");
11184
11205
  var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
11185
11206
  var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
11186
11207
  var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
11187
11208
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
11188
11209
  var import_instrumentation_cohere = require("@traceloop/instrumentation-cohere");
11189
11210
  var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
11211
+ var import_instrumentation_langchain = require("@traceloop/instrumentation-langchain");
11212
+ var import_instrumentation_llamaindex = require("@traceloop/instrumentation-llamaindex");
11190
11213
  var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
11191
11214
  var import_instrumentation_qdrant = require("@traceloop/instrumentation-qdrant");
11192
11215
  var import_instrumentation_together = require("@traceloop/instrumentation-together");
11193
11216
  var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
11194
- var traceloop4 = __toESM(require("@traceloop/node-server-sdk"));
11217
+
11218
+ // src/tracing/otel-core/index.ts
11219
+ var import_api = require("@opentelemetry/api");
11220
+ var import_core = require("@opentelemetry/core");
11221
+ var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
11222
+ var import_instrumentation = require("@opentelemetry/instrumentation");
11223
+ var resourceModule = __toESM(require("@opentelemetry/resources"));
11224
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
11225
+ var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
11226
+ var import_ai_semantic_conventions = require("@traceloop/ai-semantic-conventions");
11227
+ var ALL_INSTRUMENTATION_LIBRARIES = "all";
11228
+ var TRACER_NAME = "@traceloop/node-server-sdk";
11229
+ var WORKFLOW_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.workflowName");
11230
+ var ENTITY_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.entityName");
11231
+ var ASSOCIATION_PROPERTIES_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.associationProperties");
11232
+ var INSTRUMENTATION_LIBRARIES = [
11233
+ "ai",
11234
+ "@traceloop/node-server-sdk",
11235
+ "@traceloop/instrumentation-openai",
11236
+ "@traceloop/instrumentation-langchain",
11237
+ "@traceloop/instrumentation-chroma",
11238
+ "@traceloop/instrumentation-chromadb",
11239
+ "@traceloop/instrumentation-anthropic",
11240
+ "@traceloop/instrumentation-llamaindex",
11241
+ "@traceloop/instrumentation-vertexai",
11242
+ "@traceloop/instrumentation-bedrock",
11243
+ "@traceloop/instrumentation-cohere",
11244
+ "@traceloop/instrumentation-pinecone",
11245
+ "@traceloop/instrumentation-qdrant",
11246
+ "@traceloop/instrumentation-together",
11247
+ TRACER_NAME,
11248
+ "traceloop.tracer"
11249
+ ];
11250
+ var AI_GENERATE_TEXT = "ai.generateText.doGenerate";
11251
+ var AI_STREAM_TEXT = "ai.streamText.doStream";
11252
+ var AI_RESPONSE_TEXT = "ai.response.text";
11253
+ var AI_PROMPT_MESSAGES = "ai.prompt.messages";
11254
+ var AI_PROMPT_TOKENS = "ai.usage.promptTokens";
11255
+ var AI_COMPLETION_TOKENS = "ai.usage.completionTokens";
11256
+ var AI_MODEL_PROVIDER = "ai.model.provider";
11257
+ var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.state");
11258
+ function getState() {
11259
+ var _a;
11260
+ const holder = globalThis;
11261
+ (_a = holder[STATE_KEY]) != null ? _a : holder[STATE_KEY] = {};
11262
+ return holder[STATE_KEY];
11263
+ }
11264
+ function parseHeaders(value) {
11265
+ const headers = {};
11266
+ if (!value) return headers;
11267
+ for (const pair of value.split(",")) {
11268
+ const separator = pair.indexOf("=");
11269
+ if (separator <= 0) continue;
11270
+ try {
11271
+ const key = decodeURIComponent(pair.slice(0, separator).trim());
11272
+ const val = decodeURIComponent(pair.slice(separator + 1).trim());
11273
+ if (key && val) headers[key] = val;
11274
+ } catch (e) {
11275
+ }
11276
+ }
11277
+ return headers;
11278
+ }
11279
+ function safeStringify(value) {
11280
+ try {
11281
+ const result = JSON.stringify(value);
11282
+ return result === void 0 ? String(value) : result;
11283
+ } catch (e) {
11284
+ return "[unserializable]";
11285
+ }
11286
+ }
11287
+ function createResource(attributes) {
11288
+ if ("resourceFromAttributes" in resourceModule) {
11289
+ const factory = resourceModule.resourceFromAttributes;
11290
+ if (typeof factory === "function") return factory(attributes);
11291
+ }
11292
+ return new resourceModule.Resource(attributes);
11293
+ }
11294
+ function detectRuntimeResource() {
11295
+ try {
11296
+ if ("detectResourcesSync" in resourceModule && typeof resourceModule.detectResourcesSync === "function" && "envDetectorSync" in resourceModule) {
11297
+ return resourceModule.detectResourcesSync({
11298
+ detectors: [
11299
+ resourceModule.envDetectorSync,
11300
+ resourceModule.processDetectorSync,
11301
+ resourceModule.hostDetectorSync
11302
+ ]
11303
+ });
11304
+ }
11305
+ if ("detectResources" in resourceModule && typeof resourceModule.detectResources === "function" && "envDetector" in resourceModule) {
11306
+ const detected = resourceModule.detectResources({
11307
+ detectors: [
11308
+ resourceModule.envDetector,
11309
+ resourceModule.processDetector,
11310
+ resourceModule.hostDetector
11311
+ ]
11312
+ });
11313
+ if (!(detected instanceof Promise)) {
11314
+ return detected;
11315
+ }
11316
+ }
11317
+ } catch (e) {
11318
+ }
11319
+ return void 0;
11320
+ }
11321
+ function logLevel(level) {
11322
+ switch (level) {
11323
+ case "debug":
11324
+ return import_api.DiagLogLevel.DEBUG;
11325
+ case "info":
11326
+ return import_api.DiagLogLevel.INFO;
11327
+ case "warn":
11328
+ return import_api.DiagLogLevel.WARN;
11329
+ default:
11330
+ return import_api.DiagLogLevel.ERROR;
11331
+ }
11332
+ }
11333
+ function transformAiSdkSpan(span) {
11334
+ const names = {
11335
+ [AI_GENERATE_TEXT]: "ai.generateText.generate",
11336
+ [AI_STREAM_TEXT]: "ai.streamText.stream"
11337
+ };
11338
+ if (!(span.name in names)) return span;
11339
+ const attributes = span.attributes;
11340
+ if (AI_RESPONSE_TEXT in attributes) {
11341
+ const response = attributes[AI_RESPONSE_TEXT];
11342
+ if (typeof response === "string") {
11343
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_COMPLETIONS}.0.content`] = response;
11344
+ }
11345
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_COMPLETIONS}.0.role`] = "assistant";
11346
+ delete attributes[AI_RESPONSE_TEXT];
11347
+ }
11348
+ if (AI_PROMPT_MESSAGES in attributes) {
11349
+ try {
11350
+ const parsed = JSON.parse(String(attributes[AI_PROMPT_MESSAGES]));
11351
+ if (Array.isArray(parsed)) {
11352
+ parsed.forEach((message, index) => {
11353
+ if (!message || typeof message !== "object") return;
11354
+ const content = "content" in message ? message.content : void 0;
11355
+ const role = "role" in message ? message.role : void 0;
11356
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.content`] = typeof content === "string" ? content : safeStringify(content);
11357
+ if (typeof role === "string") {
11358
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.role`] = role;
11359
+ }
11360
+ });
11361
+ }
11362
+ delete attributes[AI_PROMPT_MESSAGES];
11363
+ } catch (e) {
11364
+ }
11365
+ }
11366
+ if (AI_PROMPT_TOKENS in attributes) {
11367
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_PROMPT_TOKENS] = Number(attributes[AI_PROMPT_TOKENS]);
11368
+ delete attributes[AI_PROMPT_TOKENS];
11369
+ }
11370
+ if (AI_COMPLETION_TOKENS in attributes) {
11371
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_COMPLETION_TOKENS] = Number(attributes[AI_COMPLETION_TOKENS]);
11372
+ delete attributes[AI_COMPLETION_TOKENS];
11373
+ }
11374
+ const prompt = attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_PROMPT_TOKENS];
11375
+ const completion = attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_COMPLETION_TOKENS];
11376
+ if (prompt !== void 0 && completion !== void 0) {
11377
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_TOTAL_TOKENS] = Number(prompt) + Number(completion);
11378
+ }
11379
+ if (AI_MODEL_PROVIDER in attributes) {
11380
+ const vendor = String(attributes[AI_MODEL_PROVIDER]);
11381
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_SYSTEM] = vendor.startsWith("openai") ? "OpenAI" : vendor;
11382
+ delete attributes[AI_MODEL_PROVIDER];
11383
+ }
11384
+ Object.defineProperty(span, "name", {
11385
+ configurable: true,
11386
+ value: names[span.name],
11387
+ writable: true
11388
+ });
11389
+ return span;
11390
+ }
11391
+ function scopeName(span) {
11392
+ var _a;
11393
+ if ("instrumentationScope" in span) {
11394
+ const scope = span.instrumentationScope;
11395
+ if (scope && typeof scope === "object" && "name" in scope && typeof scope.name === "string") {
11396
+ return scope.name;
11397
+ }
11398
+ }
11399
+ return (_a = span.instrumentationLibrary) == null ? void 0 : _a.name;
11400
+ }
11401
+ function contentCaptureDisabled(options) {
11402
+ return options.traceContent === false || (process.env.TRACELOOP_TRACE_CONTENT || "true").toLowerCase() === "false";
11403
+ }
11404
+ function shouldSendTraceContent() {
11405
+ var _a;
11406
+ const contextual = import_api.context.active().getValue(import_ai_semantic_conventions.CONTEXT_KEY_ALLOW_TRACE_CONTENT);
11407
+ if (typeof contextual === "boolean") return contextual;
11408
+ if (((_a = getState().configuration) == null ? void 0 : _a.traceContent) === false) return false;
11409
+ return (process.env.TRACELOOP_TRACE_CONTENT || "true").toLowerCase() !== "false";
11410
+ }
11411
+ function enrichStart(span) {
11412
+ const active = import_api.context.active();
11413
+ const workflow = active.getValue(WORKFLOW_NAME_KEY);
11414
+ if (typeof workflow === "string") span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_WORKFLOW_NAME, workflow);
11415
+ const entity = active.getValue(ENTITY_NAME_KEY);
11416
+ if (typeof entity === "string") span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_PATH, entity);
11417
+ const properties = active.getValue(ASSOCIATION_PROPERTIES_KEY);
11418
+ if (properties && typeof properties === "object") {
11419
+ for (const [key, value] of Object.entries(properties)) {
11420
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
11421
+ span.setAttribute(`${import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.${key}`, value);
11422
+ }
11423
+ }
11424
+ }
11425
+ }
11426
+ function createSpanProcessor(options) {
11427
+ var _a, _b;
11428
+ const baseUrl = options.baseUrl || process.env.TRACELOOP_BASE_URL || "https://api.traceloop.com";
11429
+ const apiKey = options.apiKey || process.env.TRACELOOP_API_KEY;
11430
+ const resolvedHeaders = (_a = options.headers) != null ? _a : process.env.TRACELOOP_HEADERS ? parseHeaders(process.env.TRACELOOP_HEADERS) : { Authorization: `Bearer ${apiKey}` };
11431
+ const exporter = (_b = options.exporter) != null ? _b : new import_exporter_trace_otlp_proto.OTLPTraceExporter({ url: `${baseUrl}/v1/traces`, headers: resolvedHeaders });
11432
+ const processor = options.disableBatch ? new import_sdk_trace_base.SimpleSpanProcessor(exporter) : new import_sdk_trace_base.BatchSpanProcessor(exporter);
11433
+ const originalOnStart = processor.onStart.bind(processor);
11434
+ const originalOnEnd = processor.onEnd.bind(processor);
11435
+ processor.onStart = (span, parentContext) => {
11436
+ try {
11437
+ enrichStart(span);
11438
+ originalOnStart(span, parentContext);
11439
+ } catch (e) {
11440
+ }
11441
+ };
11442
+ processor.onEnd = (span) => {
11443
+ var _a2;
11444
+ let outgoing = span;
11445
+ try {
11446
+ const allowed = options.allowedInstrumentationLibraries;
11447
+ if (allowed !== ALL_INSTRUMENTATION_LIBRARIES && ![...INSTRUMENTATION_LIBRARIES, ...allowed != null ? allowed : []].includes((_a2 = scopeName(span)) != null ? _a2 : "")) {
11448
+ return;
11449
+ }
11450
+ outgoing = transformAiSdkSpan(span);
11451
+ } catch (e) {
11452
+ }
11453
+ try {
11454
+ originalOnEnd(outgoing);
11455
+ } catch (e) {
11456
+ }
11457
+ };
11458
+ return processor;
11459
+ }
11460
+ function initialize(options = {}) {
11461
+ var _a;
11462
+ const state = getState();
11463
+ if (state.configuration) return;
11464
+ state.configuration = Object.freeze({ ...options });
11465
+ if (options.logLevel) import_api.diag.setLogger(new import_api.DiagConsoleLogger(), logLevel(options.logLevel));
11466
+ if (options.tracingEnabled === false) return;
11467
+ const baseUrl = options.baseUrl || process.env.TRACELOOP_BASE_URL || "https://api.traceloop.com";
11468
+ state.defaultProcessor = createSpanProcessor({
11469
+ ...options,
11470
+ baseUrl,
11471
+ allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES
11472
+ });
11473
+ const serviceResource = createResource({
11474
+ "service.name": options.appName || process.env.npm_package_name || "unknown_service"
11475
+ });
11476
+ const detectedResource = detectRuntimeResource();
11477
+ state.provider = new import_sdk_trace_node.NodeTracerProvider({
11478
+ // Detected attributes win over the configured resource, matching
11479
+ // sdk-node's `this._resource.merge(detectResourcesSync(...))` so
11480
+ // OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES can still override appName.
11481
+ resource: detectedResource ? serviceResource.merge(detectedResource) : serviceResource,
11482
+ spanProcessors: [state.defaultProcessor, ...options.processor ? [options.processor] : []]
11483
+ });
11484
+ state.provider.register({
11485
+ contextManager: options.contextManager,
11486
+ propagator: options.propagator
11487
+ });
11488
+ const instrumentations = (_a = options.instrumentations) != null ? _a : [];
11489
+ if (contentCaptureDisabled(options)) {
11490
+ for (const instrumentation of instrumentations) {
11491
+ try {
11492
+ const config = {
11493
+ ...instrumentation.getConfig(),
11494
+ traceContent: false
11495
+ };
11496
+ instrumentation.setConfig(config);
11497
+ } catch (e) {
11498
+ }
11499
+ }
11500
+ }
11501
+ (0, import_instrumentation.registerInstrumentations)({ instrumentations });
11502
+ }
11503
+ async function forceFlush() {
11504
+ var _a, _b;
11505
+ const state = getState();
11506
+ try {
11507
+ await ((_a = state.provider) == null ? void 0 : _a.forceFlush());
11508
+ await ((_b = state.defaultProcessor) == null ? void 0 : _b.forceFlush());
11509
+ } catch (e) {
11510
+ }
11511
+ }
11512
+ function withEntity(type, config, fn, args) {
11513
+ let entityContext = import_api.context.active();
11514
+ if (type === import_ai_semantic_conventions.TraceloopSpanKindValues.WORKFLOW) {
11515
+ entityContext = entityContext.setValue(WORKFLOW_NAME_KEY, config.name);
11516
+ }
11517
+ const parentPath = entityContext.getValue(ENTITY_NAME_KEY);
11518
+ if (type === import_ai_semantic_conventions.TraceloopSpanKindValues.TASK || type === import_ai_semantic_conventions.TraceloopSpanKindValues.TOOL) {
11519
+ entityContext = entityContext.setValue(
11520
+ ENTITY_NAME_KEY,
11521
+ `${typeof parentPath === "string" ? `${parentPath}.` : ""}${config.name}`
11522
+ );
11523
+ }
11524
+ if (config.traceContent !== void 0) {
11525
+ entityContext = entityContext.setValue(import_ai_semantic_conventions.CONTEXT_KEY_ALLOW_TRACE_CONTENT, config.traceContent);
11526
+ }
11527
+ if (config.associationProperties) {
11528
+ entityContext = entityContext.setValue(ASSOCIATION_PROPERTIES_KEY, config.associationProperties);
11529
+ }
11530
+ if (config.suppressTracing) {
11531
+ entityContext = (0, import_core.suppressTracing)(entityContext);
11532
+ }
11533
+ let callbackStarted = false;
11534
+ const run = (span) => {
11535
+ var _a;
11536
+ try {
11537
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_NAME, config.name);
11538
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_PATH, typeof parentPath === "string" ? parentPath : "");
11539
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_SPAN_KIND, type);
11540
+ if (type === import_ai_semantic_conventions.TraceloopSpanKindValues.WORKFLOW) {
11541
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_WORKFLOW_NAME, config.name);
11542
+ }
11543
+ if (config.version !== void 0) span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_VERSION, config.version);
11544
+ const input = (_a = config.inputParameters) != null ? _a : args;
11545
+ if (shouldSendTraceContent()) {
11546
+ span.setAttribute(
11547
+ import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_INPUT,
11548
+ safeStringify(input.length === 1 && input[0] !== null && typeof input[0] === "object" && !(input[0] instanceof Map) ? { args: [], kwargs: input[0] } : { args: input, kwargs: {} })
11549
+ );
11550
+ }
11551
+ } catch (e) {
11552
+ }
11553
+ let result;
11554
+ try {
11555
+ callbackStarted = true;
11556
+ result = fn(...args);
11557
+ } catch (error) {
11558
+ try {
11559
+ span.end();
11560
+ } catch (e) {
11561
+ }
11562
+ throw error;
11563
+ }
11564
+ if (result instanceof Promise) {
11565
+ return result.then(
11566
+ (value) => {
11567
+ try {
11568
+ if (shouldSendTraceContent()) span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_OUTPUT, safeStringify(value));
11569
+ span.end();
11570
+ } catch (e) {
11571
+ }
11572
+ return value;
11573
+ },
11574
+ (error) => {
11575
+ try {
11576
+ span.end();
11577
+ } catch (e) {
11578
+ }
11579
+ throw error;
11580
+ }
11581
+ );
11582
+ }
11583
+ try {
11584
+ if (shouldSendTraceContent()) span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_OUTPUT, safeStringify(result));
11585
+ span.end();
11586
+ } catch (e) {
11587
+ }
11588
+ return result;
11589
+ };
11590
+ try {
11591
+ const tracer = import_api.trace.getTracer(TRACER_NAME);
11592
+ return import_api.context.with(
11593
+ entityContext,
11594
+ () => tracer.startActiveSpan(`${config.name}.${type}`, {}, entityContext, run)
11595
+ );
11596
+ } catch (error) {
11597
+ if (callbackStarted) throw error;
11598
+ return fn(...args);
11599
+ }
11600
+ }
11601
+ function withTask(config, fn, ...args) {
11602
+ return withEntity(import_ai_semantic_conventions.TraceloopSpanKindValues.TASK, config, fn, args);
11603
+ }
11604
+ function withTool(config, fn, ...args) {
11605
+ return withEntity(import_ai_semantic_conventions.TraceloopSpanKindValues.TOOL, config, fn, args);
11606
+ }
11607
+
11608
+ // src/tracing/tracer-core.ts
11195
11609
  var import_weakref = require("weakref");
11196
11610
 
11197
11611
  // src/tracing/direct/http.ts
@@ -11392,7 +11806,7 @@ function buildExportTraceServiceRequest2(spans) {
11392
11806
  }
11393
11807
 
11394
11808
  // src/tracing/direct/context.ts
11395
- var import_api = require("@opentelemetry/api");
11809
+ var import_api2 = require("@opentelemetry/api");
11396
11810
  var INVALID_TRACE_ID = "00000000000000000000000000000000";
11397
11811
  var INVALID_SPAN_ID = "0000000000000000";
11398
11812
  function hexToBase64(hex) {
@@ -11403,7 +11817,7 @@ function hexToBase64(hex) {
11403
11817
  return base64Encode2(bytes);
11404
11818
  }
11405
11819
  function getExplicitTraceContext(traceId, parentSpanId) {
11406
- if (!traceId || !parentSpanId || !(0, import_api.isValidTraceId)(traceId) || !(0, import_api.isValidSpanId)(parentSpanId)) {
11820
+ if (!traceId || !parentSpanId || !(0, import_api2.isValidTraceId)(traceId) || !(0, import_api2.isValidSpanId)(parentSpanId)) {
11407
11821
  return void 0;
11408
11822
  }
11409
11823
  return {
@@ -11412,7 +11826,7 @@ function getExplicitTraceContext(traceId, parentSpanId) {
11412
11826
  };
11413
11827
  }
11414
11828
  function getActiveTraceContext() {
11415
- const activeSpan = import_api.trace.getSpan(import_api.context.active());
11829
+ const activeSpan = import_api2.trace.getSpan(import_api2.context.active());
11416
11830
  if (!activeSpan) return {};
11417
11831
  const spanContext = activeSpan.spanContext();
11418
11832
  const traceIdHex = spanContext.traceId;
@@ -11426,7 +11840,7 @@ function getActiveTraceContext() {
11426
11840
 
11427
11841
  // src/tracing/multi-project.ts
11428
11842
  var import_node_crypto = require("crypto");
11429
- var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
11843
+ var import_exporter_trace_otlp_proto2 = require("@opentelemetry/exporter-trace-otlp-proto");
11430
11844
  var PROJECT_ID_SPAN_ATTRIBUTE = "raindrop.project_id";
11431
11845
  var AUTH_HINT_SPAN_ATTRIBUTE = "raindrop.auth_hint";
11432
11846
  var EXPORT_SUCCESS = 0;
@@ -11436,10 +11850,10 @@ function authHintForKey(writeKey) {
11436
11850
  if (!writeKey) return void 0;
11437
11851
  return (0, import_node_crypto.createHash)("sha256").update(writeKey, "utf8").digest("hex").slice(0, 8);
11438
11852
  }
11439
- var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.multiProjectState");
11440
- function getState() {
11853
+ var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.multiProjectState");
11854
+ function getState2() {
11441
11855
  const holder = globalThis;
11442
- let state = holder[STATE_KEY];
11856
+ let state = holder[STATE_KEY2];
11443
11857
  if (!state) {
11444
11858
  state = {
11445
11859
  foreignClientSeen: false,
@@ -11451,12 +11865,12 @@ function getState() {
11451
11865
  multiKeyWarned: false,
11452
11866
  pendingMultiKeyWarning: false
11453
11867
  };
11454
- holder[STATE_KEY] = state;
11868
+ holder[STATE_KEY2] = state;
11455
11869
  }
11456
11870
  return state;
11457
11871
  }
11458
11872
  function emitMultiKeyWarningOnce() {
11459
- const state = getState();
11873
+ const state = getState2();
11460
11874
  if (state.multiKeyWarned) return;
11461
11875
  state.multiKeyWarned = true;
11462
11876
  state.pendingMultiKeyWarning = false;
@@ -11466,7 +11880,7 @@ function emitMultiKeyWarningOnce() {
11466
11880
  }
11467
11881
  function registerClientKey(authHint, tracingEnabled = false) {
11468
11882
  if (!authHint) return;
11469
- const state = getState();
11883
+ const state = getState2();
11470
11884
  state.seenClientHints.add(authHint);
11471
11885
  if (state.seenClientHints.size > 1) {
11472
11886
  state.foreignClientSeen = true;
@@ -11478,10 +11892,10 @@ function registerClientKey(authHint, tracingEnabled = false) {
11478
11892
  }
11479
11893
  }
11480
11894
  function markForeignClient() {
11481
- getState().foreignClientSeen = true;
11895
+ getState2().foreignClientSeen = true;
11482
11896
  }
11483
11897
  function foreignClientSeen() {
11484
- return getState().foreignClientSeen;
11898
+ return getState2().foreignClientSeen;
11485
11899
  }
11486
11900
  function stampSpan(span, projectId, authHint) {
11487
11901
  try {
@@ -11587,17 +12001,17 @@ var GuardedSpanExporter = class {
11587
12001
  }
11588
12002
  };
11589
12003
  function buildGuardedExporter(baseUrl, headers, ownerAuthHint) {
11590
- const inner = new import_exporter_trace_otlp_proto.OTLPTraceExporter({
12004
+ const inner = new import_exporter_trace_otlp_proto2.OTLPTraceExporter({
11591
12005
  url: `${baseUrl}/v1/traces`,
11592
12006
  headers
11593
12007
  });
11594
12008
  return new GuardedSpanExporter(inner, ownerAuthHint);
11595
12009
  }
11596
12010
  function pipelineOwnerHint() {
11597
- return getState().ownerAuthHint;
12011
+ return getState2().ownerAuthHint;
11598
12012
  }
11599
12013
  function claimPipeline(authHint, projectId) {
11600
- const state = getState();
12014
+ const state = getState2();
11601
12015
  if (state.pipelineClaimed) {
11602
12016
  return false;
11603
12017
  }
@@ -11610,16 +12024,16 @@ function claimPipeline(authHint, projectId) {
11610
12024
  return true;
11611
12025
  }
11612
12026
  function releasePipelineClaim() {
11613
- const state = getState();
12027
+ const state = getState2();
11614
12028
  state.pipelineClaimed = false;
11615
12029
  state.ownerAuthHint = void 0;
11616
12030
  state.ownerProjectId = void 0;
11617
12031
  }
11618
12032
  function markTraceloopConfiguredWithoutClaim() {
11619
- getState().traceloopConfiguredWithoutClaim = true;
12033
+ getState2().traceloopConfiguredWithoutClaim = true;
11620
12034
  }
11621
12035
  function traceloopConfiguredWithoutClaim() {
11622
- return getState().traceloopConfiguredWithoutClaim;
12036
+ return getState2().traceloopConfiguredWithoutClaim;
11623
12037
  }
11624
12038
 
11625
12039
  // src/tracing/direct/shipper.ts
@@ -11856,18 +12270,17 @@ var DirectTraceShipper = class {
11856
12270
  };
11857
12271
 
11858
12272
  // src/tracing/exit-flush.ts
11859
- var traceloop = __toESM(require("@traceloop/node-server-sdk"));
11860
- var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
11861
- function getState2() {
12273
+ var STATE_KEY3 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
12274
+ function getState3() {
11862
12275
  const holder = globalThis;
11863
- let state = holder[STATE_KEY2];
12276
+ let state = holder[STATE_KEY3];
11864
12277
  if (!state) {
11865
12278
  state = {
11866
12279
  clientFlushers: /* @__PURE__ */ new Set(),
11867
12280
  pipelineFlushNeeded: false,
11868
12281
  handlerRegistered: false
11869
12282
  };
11870
- holder[STATE_KEY2] = state;
12283
+ holder[STATE_KEY3] = state;
11871
12284
  }
11872
12285
  return state;
11873
12286
  }
@@ -11880,7 +12293,7 @@ function ensureExitHandler(state) {
11880
12293
  });
11881
12294
  }
11882
12295
  function registerClientFlusher(flush) {
11883
- const state = getState2();
12296
+ const state = getState3();
11884
12297
  state.clientFlushers.add(flush);
11885
12298
  ensureExitHandler(state);
11886
12299
  return () => {
@@ -11888,12 +12301,12 @@ function registerClientFlusher(flush) {
11888
12301
  };
11889
12302
  }
11890
12303
  function markPipelineForExitFlush() {
11891
- const state = getState2();
12304
+ const state = getState3();
11892
12305
  state.pipelineFlushNeeded = true;
11893
12306
  ensureExitHandler(state);
11894
12307
  }
11895
12308
  async function flushAll() {
11896
- const state = getState2();
12309
+ const state = getState3();
11897
12310
  const tasks = [];
11898
12311
  for (const flush of state.clientFlushers) {
11899
12312
  tasks.push(Promise.resolve().then(flush).catch(() => {
@@ -11901,7 +12314,7 @@ async function flushAll() {
11901
12314
  }
11902
12315
  if (state.pipelineFlushNeeded) {
11903
12316
  tasks.push(
11904
- Promise.resolve().then(() => traceloop.forceFlush()).catch(() => {
12317
+ Promise.resolve().then(() => forceFlush()).catch(() => {
11905
12318
  })
11906
12319
  );
11907
12320
  }
@@ -11909,11 +12322,10 @@ async function flushAll() {
11909
12322
  }
11910
12323
 
11911
12324
  // src/tracing/liveInteraction.ts
11912
- var import_api3 = require("@opentelemetry/api");
11913
- var traceloop2 = __toESM(require("@traceloop/node-server-sdk"));
12325
+ var import_api4 = require("@opentelemetry/api");
11914
12326
 
11915
12327
  // src/tracing/subagents.ts
11916
- var import_api2 = require("@opentelemetry/api");
12328
+ var import_api3 = require("@opentelemetry/api");
11917
12329
  var DEFAULT_SUBAGENT_NAME = "subagent";
11918
12330
  var DISPATCH_ACCEPTED = "accepted";
11919
12331
  function reasonText(reason) {
@@ -11929,7 +12341,7 @@ function reasonText(reason) {
11929
12341
  }
11930
12342
  function stampCurrentSpan(attributes) {
11931
12343
  try {
11932
- const span = import_api2.trace.getSpan(import_api2.context.active());
12344
+ const span = import_api3.trace.getSpan(import_api3.context.active());
11933
12345
  if (!(span == null ? void 0 : span.isRecording())) return;
11934
12346
  for (const [key, value] of Object.entries(attributes)) {
11935
12347
  span.setAttribute(key, value);
@@ -11940,7 +12352,7 @@ function stampCurrentSpan(attributes) {
11940
12352
  function stampOwnSpan(attributes, frame) {
11941
12353
  if (!frame) return;
11942
12354
  try {
11943
- const span = import_api2.trace.getSpan(import_api2.context.active());
12355
+ const span = import_api3.trace.getSpan(import_api3.context.active());
11944
12356
  if (!(span == null ? void 0 : span.isRecording()) || !frame.ownsSpan(span)) return;
11945
12357
  for (const [key, value] of Object.entries(attributes)) {
11946
12358
  span.setAttribute(key, value);
@@ -11950,11 +12362,11 @@ function stampOwnSpan(attributes, frame) {
11950
12362
  }
11951
12363
  function failOwnSpan(reason, frame) {
11952
12364
  try {
11953
- const span = import_api2.trace.getSpan(import_api2.context.active());
12365
+ const span = import_api3.trace.getSpan(import_api3.context.active());
11954
12366
  if (!(span == null ? void 0 : span.isRecording())) return false;
11955
12367
  if (!(frame == null ? void 0 : frame.ownsSpan(span))) return false;
11956
12368
  const message = reasonText(reason);
11957
- span.setStatus({ code: import_api2.SpanStatusCode.ERROR, message });
12369
+ span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message });
11958
12370
  span.recordException(reason instanceof Error ? reason : new Error(message));
11959
12371
  return true;
11960
12372
  } catch (e) {
@@ -12198,16 +12610,16 @@ var LiveSubagentRun = class {
12198
12610
  };
12199
12611
 
12200
12612
  // src/tracing/liveInteraction.ts
12201
- function getPropertiesFromContext(context6) {
12613
+ function getPropertiesFromContext(context7) {
12202
12614
  const properties = {
12203
- ...context6.userId && { user_id: context6.userId },
12204
- ...context6.convoId && { convo_id: context6.convoId },
12205
- ...context6.eventId && { event_id: context6.eventId },
12206
- ...context6.event && { event_name: context6.event },
12207
- ...context6.properties || {}
12615
+ ...context7.userId && { user_id: context7.userId },
12616
+ ...context7.convoId && { convo_id: context7.convoId },
12617
+ ...context7.eventId && { event_id: context7.eventId },
12618
+ ...context7.event && { event_name: context7.event },
12619
+ ...context7.properties || {}
12208
12620
  };
12209
- if (context6.attachments && context6.attachments.length > 0) {
12210
- properties.attachments = stringifyBounded(context6.attachments);
12621
+ if (context7.attachments && context7.attachments.length > 0) {
12622
+ properties.attachments = stringifyBounded(context7.attachments);
12211
12623
  }
12212
12624
  return properties;
12213
12625
  }
@@ -12227,12 +12639,12 @@ function serializeAssociationProperties(properties) {
12227
12639
  function serializeSpanValue(value) {
12228
12640
  return stringifyBounded(value);
12229
12641
  }
12230
- function getLocalDebuggerMetadata(context6) {
12642
+ function getLocalDebuggerMetadata(context7) {
12231
12643
  return {
12232
- ...context6.eventId ? { eventId: context6.eventId } : {},
12233
- ...context6.event ? { eventName: context6.event } : {},
12234
- ...context6.userId ? { userId: context6.userId } : {},
12235
- ...context6.convoId ? { convoId: context6.convoId } : {}
12644
+ ...context7.eventId ? { eventId: context7.eventId } : {},
12645
+ ...context7.event ? { eventName: context7.event } : {},
12646
+ ...context7.userId ? { userId: context7.userId } : {},
12647
+ ...context7.convoId ? { convoId: context7.convoId } : {}
12236
12648
  };
12237
12649
  }
12238
12650
  var LiveToolSpan = class {
@@ -12244,7 +12656,7 @@ var LiveToolSpan = class {
12244
12656
  }
12245
12657
  spanIdHex() {
12246
12658
  const ctx = this.span.spanContext();
12247
- return (0, import_api3.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
12659
+ return (0, import_api4.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
12248
12660
  }
12249
12661
  setInput(input) {
12250
12662
  this.span.setAttribute("traceloop.entity.input", serializeSpanValue(input));
@@ -12256,13 +12668,13 @@ var LiveToolSpan = class {
12256
12668
  setError(error) {
12257
12669
  this.hasError = true;
12258
12670
  this.errorMessage = error instanceof Error ? error.message : String(error);
12259
- this.span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message: this.errorMessage });
12671
+ this.span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message: this.errorMessage });
12260
12672
  this.span.recordException(error instanceof Error ? error : new Error(this.errorMessage));
12261
12673
  }
12262
12674
  end() {
12263
12675
  var _a;
12264
12676
  if (!this.hasError) {
12265
- this.span.setStatus({ code: import_api3.SpanStatusCode.OK });
12677
+ this.span.setStatus({ code: import_api4.SpanStatusCode.OK });
12266
12678
  }
12267
12679
  this.span.end();
12268
12680
  (_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
@@ -12333,11 +12745,11 @@ var DirectToolSpan = class {
12333
12745
  }
12334
12746
  };
12335
12747
  var LiveInteraction = class {
12336
- constructor(context6, traceId, analytics, directShipper, routing) {
12748
+ constructor(context7, traceId, analytics, directShipper, routing) {
12337
12749
  this.usageEmitted = false;
12338
- this.context = context6;
12750
+ this.context = context7;
12339
12751
  this.analytics = analytics;
12340
- this.tracer = import_api3.trace.getTracer("traceloop.tracer");
12752
+ this.tracer = import_api4.trace.getTracer("traceloop.tracer");
12341
12753
  this.traceId = traceId;
12342
12754
  this.directShipper = directShipper;
12343
12755
  this.routing = routing;
@@ -12372,7 +12784,7 @@ var LiveInteraction = class {
12372
12784
  this.traceId = explicitTraceId;
12373
12785
  return explicitTraceId;
12374
12786
  }
12375
- const activeSpan = import_api3.trace.getSpan(import_api3.context.active());
12787
+ const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
12376
12788
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
12377
12789
  if (activeTraceId) {
12378
12790
  this.traceId = activeTraceId;
@@ -12417,12 +12829,12 @@ var LiveInteraction = class {
12417
12829
  const spanContext = {
12418
12830
  traceId: base64ToHex2(traceIdB64),
12419
12831
  spanId: base64ToHex2(spanIdB64),
12420
- traceFlags: import_api3.TraceFlags.SAMPLED
12832
+ traceFlags: import_api4.TraceFlags.SAMPLED
12421
12833
  };
12422
- const wrappedContext = import_api3.trace.setSpan(import_api3.context.active(), import_api3.trace.wrapSpanContext(spanContext));
12834
+ const wrappedContext = import_api4.trace.setSpan(import_api4.context.active(), import_api4.trace.wrapSpanContext(spanContext));
12423
12835
  const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
12424
12836
  try {
12425
- const result = await import_api3.context.with(wrappedContext, invoke);
12837
+ const result = await import_api4.context.with(wrappedContext, invoke);
12426
12838
  const endTimeMs = Date.now();
12427
12839
  this.directShipper.sendSpan({
12428
12840
  name: taskName,
@@ -12457,7 +12869,7 @@ var LiveInteraction = class {
12457
12869
  }
12458
12870
  }
12459
12871
  const wrappedFn = (...fnArgs) => {
12460
- const activeSpan = import_api3.trace.getSpan(import_api3.context.active());
12872
+ const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
12461
12873
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
12462
12874
  if (activeTraceId) {
12463
12875
  this.traceId = activeTraceId;
@@ -12470,7 +12882,7 @@ var LiveInteraction = class {
12470
12882
  }
12471
12883
  return fn.apply(thisArg, fnArgs);
12472
12884
  };
12473
- return traceloop2.withTask(
12885
+ return withTask(
12474
12886
  {
12475
12887
  name: taskName,
12476
12888
  associationProperties: serializeAssociationProperties(properties),
@@ -12509,14 +12921,14 @@ var LiveInteraction = class {
12509
12921
  const spanContext = {
12510
12922
  traceId: base64ToHex2(traceIdB64),
12511
12923
  spanId: base64ToHex2(spanIdB64),
12512
- traceFlags: import_api3.TraceFlags.SAMPLED
12924
+ traceFlags: import_api4.TraceFlags.SAMPLED
12513
12925
  };
12514
- const wrappedContext = import_api3.trace.setSpan(import_api3.context.active(), import_api3.trace.wrapSpanContext(spanContext));
12926
+ const wrappedContext = import_api4.trace.setSpan(import_api4.context.active(), import_api4.trace.wrapSpanContext(spanContext));
12515
12927
  const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
12516
12928
  let result;
12517
12929
  let error;
12518
12930
  try {
12519
- result = await import_api3.context.with(wrappedContext, invoke);
12931
+ result = await import_api4.context.with(wrappedContext, invoke);
12520
12932
  } catch (err) {
12521
12933
  error = err instanceof Error ? err.message : String(err);
12522
12934
  const endTimeMs2 = Date.now();
@@ -12581,9 +12993,9 @@ var LiveInteraction = class {
12581
12993
  const inputParams = params.inputParameters ? [params.inputParameters] : void 0;
12582
12994
  const emitLive = (event) => this.emitLiveEvent(event);
12583
12995
  const wrapped = async (...wrappedArgs) => {
12584
- const activeSpan = import_api3.trace.getSpan(import_api3.context.active());
12996
+ const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
12585
12997
  const ctx = activeSpan == null ? void 0 : activeSpan.spanContext();
12586
- const liveSpanId = ctx && (0, import_api3.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
12998
+ const liveSpanId = ctx && (0, import_api4.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
12587
12999
  if (activeSpan) {
12588
13000
  this.stampRouting(activeSpan);
12589
13001
  }
@@ -12621,7 +13033,7 @@ var LiveInteraction = class {
12621
13033
  throw error;
12622
13034
  }
12623
13035
  };
12624
- return traceloop2.withTool(
13036
+ return withTool(
12625
13037
  {
12626
13038
  name: toolName,
12627
13039
  associationProperties: serializeAssociationProperties(properties),
@@ -12691,7 +13103,7 @@ var LiveInteraction = class {
12691
13103
  console.log(`[raindrop] startToolSpan: started tool span "${name}"`);
12692
13104
  }
12693
13105
  const startSpanCtx = span.spanContext();
12694
- const startSpanIdHex = (0, import_api3.isValidSpanId)(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
13106
+ const startSpanIdHex = (0, import_api4.isValidSpanId)(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
12695
13107
  this.emitLiveEvent({
12696
13108
  type: "tool_start",
12697
13109
  spanId: startSpanIdHex,
@@ -12862,19 +13274,19 @@ var LiveInteraction = class {
12862
13274
  span.setAttribute("traceloop.entity.input", input);
12863
13275
  }
12864
13276
  span.setAttribute("traceloop.entity.output", output);
12865
- span.setStatus({ code: import_api3.SpanStatusCode.OK });
13277
+ span.setStatus({ code: import_api4.SpanStatusCode.OK });
12866
13278
  const spanContext = span.spanContext();
12867
13279
  span.end();
12868
13280
  this.emitLiveEvent({
12869
- spanId: (0, import_api3.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0,
13281
+ spanId: (0, import_api4.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0,
12870
13282
  type: "tool_result",
12871
13283
  content: params.name,
12872
13284
  timestamp: Date.now(),
12873
13285
  metadata: { result: params.output }
12874
13286
  });
12875
13287
  return {
12876
- traceIdHex: (0, import_api3.isValidTraceId)(spanContext.traceId) ? spanContext.traceId : void 0,
12877
- spanIdHex: (0, import_api3.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0
13288
+ traceIdHex: (0, import_api4.isValidTraceId)(spanContext.traceId) ? spanContext.traceId : void 0,
13289
+ spanIdHex: (0, import_api4.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0
12878
13290
  };
12879
13291
  }
12880
13292
  /**
@@ -12919,7 +13331,7 @@ var LiveInteraction = class {
12919
13331
  for (const [key, value] of Object.entries(attributes)) {
12920
13332
  span.setAttribute(key, value);
12921
13333
  }
12922
- span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message });
13334
+ span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message });
12923
13335
  span.recordException(reason instanceof Error ? reason : new Error(message));
12924
13336
  span.end();
12925
13337
  }
@@ -13046,10 +13458,10 @@ var LiveInteraction = class {
13046
13458
  }
13047
13459
  if (error) {
13048
13460
  const errorMessage = error instanceof Error ? error.message : String(error);
13049
- span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message: errorMessage });
13461
+ span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message: errorMessage });
13050
13462
  span.recordException(error instanceof Error ? error : new Error(errorMessage));
13051
13463
  } else {
13052
- span.setStatus({ code: import_api3.SpanStatusCode.OK });
13464
+ span.setStatus({ code: import_api4.SpanStatusCode.OK });
13053
13465
  }
13054
13466
  span.end(endTimeMs);
13055
13467
  if ((_c = this.analytics) == null ? void 0 : _c.debugLogs) {
@@ -13061,7 +13473,7 @@ var LiveInteraction = class {
13061
13473
  });
13062
13474
  }
13063
13475
  const trackToolCtx = span.spanContext();
13064
- const trackToolSpanIdHex = (0, import_api3.isValidSpanId)(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
13476
+ const trackToolSpanIdHex = (0, import_api4.isValidSpanId)(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
13065
13477
  this.emitLiveEvent({
13066
13478
  type: "tool_result",
13067
13479
  spanId: trackToolSpanIdHex,
@@ -13077,11 +13489,10 @@ var LiveInteraction = class {
13077
13489
  };
13078
13490
 
13079
13491
  // src/tracing/liveTracer.ts
13080
- var import_api4 = require("@opentelemetry/api");
13081
- var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
13492
+ var import_api5 = require("@opentelemetry/api");
13082
13493
  var LiveTracer = class {
13083
13494
  constructor(globalProperties, directShipper, routing) {
13084
- this.tracer = import_api4.trace.getTracer("traceloop.tracer");
13495
+ this.tracer = import_api5.trace.getTracer("traceloop.tracer");
13085
13496
  this.globalProperties = globalProperties || {};
13086
13497
  this.directShipper = directShipper;
13087
13498
  this.routing = routing;
@@ -13093,7 +13504,7 @@ var LiveTracer = class {
13093
13504
  }
13094
13505
  emitLiveEvent(event) {
13095
13506
  var _a, _b;
13096
- const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
13507
+ const activeSpan = import_api5.trace.getSpan(import_api5.context.active());
13097
13508
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
13098
13509
  const active = getActiveTraceContext();
13099
13510
  const traceId = (_b = (_a = event.traceId) != null ? _a : activeTraceId) != null ? _b : active.traceIdB64;
@@ -13113,7 +13524,7 @@ var LiveTracer = class {
13113
13524
  };
13114
13525
  const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
13115
13526
  const wrappedFn = (...fnArgs) => {
13116
- const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
13527
+ const activeSpan = import_api5.trace.getSpan(import_api5.context.active());
13117
13528
  if (activeSpan) {
13118
13529
  this.stampRouting(activeSpan);
13119
13530
  }
@@ -13122,7 +13533,7 @@ var LiveTracer = class {
13122
13533
  }
13123
13534
  return fn.apply(thisArg, fnArgs);
13124
13535
  };
13125
- return traceloop3.withTask(
13536
+ return withTask(
13126
13537
  {
13127
13538
  name: taskName,
13128
13539
  associationProperties: properties,
@@ -13208,15 +13619,15 @@ var LiveTracer = class {
13208
13619
  }
13209
13620
  if (error) {
13210
13621
  const errorMessage = error instanceof Error ? error.message : String(error);
13211
- span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message: errorMessage });
13622
+ span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message: errorMessage });
13212
13623
  span.recordException(error instanceof Error ? error : new Error(errorMessage));
13213
13624
  } else {
13214
- span.setStatus({ code: import_api4.SpanStatusCode.OK });
13625
+ span.setStatus({ code: import_api5.SpanStatusCode.OK });
13215
13626
  }
13216
13627
  span.end(endTimeMs);
13217
13628
  const ctx = span.spanContext();
13218
- const traceId = ctx.traceId || ((_b = import_api4.trace.getSpan(import_api4.context.active())) == null ? void 0 : _b.spanContext().traceId);
13219
- const spanIdHex = (0, import_api4.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
13629
+ const traceId = ctx.traceId || ((_b = import_api5.trace.getSpan(import_api5.context.active())) == null ? void 0 : _b.spanContext().traceId);
13630
+ const spanIdHex = (0, import_api5.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
13220
13631
  if (traceId) {
13221
13632
  this.emitLiveEvent({
13222
13633
  traceId,
@@ -13375,7 +13786,7 @@ function createLocalDebuggerSpanProcessor(options) {
13375
13786
  headers: {}
13376
13787
  });
13377
13788
  try {
13378
- return traceloop4.createSpanProcessor({
13789
+ return createSpanProcessor({
13379
13790
  apiKey: options.writeKey,
13380
13791
  baseUrl: localDebuggerUrl,
13381
13792
  disableBatch: options.disableBatching,
@@ -13455,7 +13866,7 @@ try {
13455
13866
  e instanceof Error ? e.message : e
13456
13867
  );
13457
13868
  span.setStatus({
13458
- code: import_api5.SpanStatusCode.ERROR,
13869
+ code: import_api6.SpanStatusCode.ERROR,
13459
13870
  message: e instanceof Error ? e.message : String(e)
13460
13871
  });
13461
13872
  span.end();
@@ -13487,7 +13898,7 @@ try {
13487
13898
  );
13488
13899
  if (!spanEnded) {
13489
13900
  span.setStatus({
13490
- code: import_api5.SpanStatusCode.ERROR,
13901
+ code: import_api6.SpanStatusCode.ERROR,
13491
13902
  message: e instanceof Error ? e.message : String(e)
13492
13903
  });
13493
13904
  span.end();
@@ -13501,7 +13912,7 @@ try {
13501
13912
  } catch (error) {
13502
13913
  if (!spanEnded) {
13503
13914
  const msg = error instanceof Error ? error.message : String(error);
13504
- span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message: msg });
13915
+ span.setStatus({ code: import_api6.SpanStatusCode.ERROR, message: msg });
13505
13916
  span.recordException(error);
13506
13917
  span.end();
13507
13918
  spanEnded = true;
@@ -13524,7 +13935,7 @@ try {
13524
13935
  return result;
13525
13936
  }).catch((error) => {
13526
13937
  span.setStatus({
13527
- code: import_api5.SpanStatusCode.ERROR,
13938
+ code: import_api6.SpanStatusCode.ERROR,
13528
13939
  message: error.message
13529
13940
  });
13530
13941
  span.recordException(error);
@@ -13587,7 +13998,7 @@ function patchBedrockStreamingBug(inst) {
13587
13998
  } catch (error) {
13588
13999
  if (!spanEnded) {
13589
14000
  const msg = error instanceof Error ? error.message : String(error);
13590
- span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message: msg });
14001
+ span.setStatus({ code: import_api6.SpanStatusCode.ERROR, message: msg });
13591
14002
  span.recordException(error);
13592
14003
  span.end();
13593
14004
  spanEnded = true;
@@ -13610,7 +14021,7 @@ function patchBedrockStreamingBug(inst) {
13610
14021
  return result;
13611
14022
  }).catch((error) => {
13612
14023
  span.setStatus({
13613
- code: import_api5.SpanStatusCode.ERROR,
14024
+ code: import_api6.SpanStatusCode.ERROR,
13614
14025
  message: error.message
13615
14026
  });
13616
14027
  span.recordException(error);
@@ -13623,7 +14034,9 @@ function createDefaultInstrumentations() {
13623
14034
  const bedrockInst = new import_instrumentation_bedrock.BedrockInstrumentation();
13624
14035
  patchBedrockStreamingBug(bedrockInst);
13625
14036
  return [
13626
- new import_instrumentation_openai.OpenAIInstrumentation(),
14037
+ new import_instrumentation_openai.OpenAIInstrumentation({
14038
+ enrichTokens: (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true"
14039
+ }),
13627
14040
  new import_instrumentation_anthropic.AnthropicInstrumentation(),
13628
14041
  new import_instrumentation_cohere.CohereInstrumentation(),
13629
14042
  bedrockInst,
@@ -13632,7 +14045,9 @@ function createDefaultInstrumentations() {
13632
14045
  new import_instrumentation_pinecone.PineconeInstrumentation(),
13633
14046
  new import_instrumentation_together.TogetherInstrumentation(),
13634
14047
  new import_instrumentation_chromadb.ChromaDBInstrumentation(),
13635
- new import_instrumentation_qdrant.QdrantInstrumentation()
14048
+ new import_instrumentation_qdrant.QdrantInstrumentation(),
14049
+ new import_instrumentation_langchain.LangChainInstrumentation(),
14050
+ new import_instrumentation_llamaindex.LlamaIndexInstrumentation()
13636
14051
  ];
13637
14052
  }
13638
14053
  function createManualInstrumentations(instrumentModules) {
@@ -13688,17 +14103,29 @@ function createManualInstrumentations(instrumentModules) {
13688
14103
  inst.manuallyInstrument(instrumentModules.qdrant);
13689
14104
  instrumentations.push(inst);
13690
14105
  }
14106
+ instrumentations.push(new import_instrumentation_langchain.LangChainInstrumentation());
14107
+ if (instrumentModules.llamaIndex) {
14108
+ const inst = new import_instrumentation_llamaindex.LlamaIndexInstrumentation();
14109
+ inst.manuallyInstrument(instrumentModules.llamaIndex);
14110
+ instrumentations.push(inst);
14111
+ }
13691
14112
  return instrumentations;
13692
14113
  }
14114
+ function createConfiguredInstrumentations(options) {
14115
+ if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
14116
+ return createManualInstrumentations(options.instrumentModules);
14117
+ }
14118
+ return createDefaultInstrumentations();
14119
+ }
13693
14120
  function getCurrentTraceId() {
13694
14121
  var _a;
13695
- return (_a = import_api5.trace.getSpan(import_api5.context.active())) == null ? void 0 : _a.spanContext().traceId;
14122
+ return (_a = import_api6.trace.getSpan(import_api6.context.active())) == null ? void 0 : _a.spanContext().traceId;
13696
14123
  }
13697
14124
  var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
13698
14125
  var _a;
13699
14126
  process.env.TRACELOOP_TELEMETRY = "false";
13700
14127
  const {
13701
- logLevel,
14128
+ logLevel: logLevel2,
13702
14129
  useExternalOtel,
13703
14130
  tracingEnabled,
13704
14131
  disableBatching,
@@ -13745,10 +14172,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
13745
14172
  const activeInteractionsByEventId = new import_weakref.WeakValueMap();
13746
14173
  try {
13747
14174
  if (useExternalOtel) {
13748
- traceloop4.initialize({
14175
+ initialize({
13749
14176
  baseUrl: apiUrl,
13750
14177
  apiKey: writeKey,
13751
- logLevel,
14178
+ logLevel: logLevel2,
13752
14179
  // Traceloop's init banner ("Traceloop exporting traces to <baseUrl>") is
13753
14180
  // misleading inside our wrapper: in external-OTEL mode we create no
13754
14181
  // exporter at all (tracingEnabled: false). Suppress it.
@@ -13774,28 +14201,29 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
13774
14201
  const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
13775
14202
  writeKey,
13776
14203
  disableBatching,
13777
- allowedInstrumentationLibraries: traceloop4.ALL_INSTRUMENTATION_LIBRARIES,
14204
+ allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES,
13778
14205
  localDebuggerUrlOpt: localDebuggerUrl
13779
14206
  });
13780
14207
  if (!cloudEnabledResolved) {
13781
14208
  if (localDebuggerProcessor) {
13782
- traceloop4.initialize({
14209
+ initialize({
13783
14210
  baseUrl: apiUrl,
13784
14211
  apiKey: writeKey,
13785
14212
  ...otherOptions,
13786
- logLevel,
14213
+ logLevel: logLevel2,
13787
14214
  silenceInitializationMessage: true,
13788
14215
  tracingEnabled: tracingEnabled !== false,
13789
14216
  disableBatch: disableBatching,
13790
- processor: localDebuggerProcessor
14217
+ processor: localDebuggerProcessor,
14218
+ instrumentations: createConfiguredInstrumentations(otherOptions)
13791
14219
  });
13792
14220
  traceloopInitialized = true;
13793
14221
  markTraceloopConfiguredWithoutClaim();
13794
14222
  } else {
13795
- traceloop4.initialize({
14223
+ initialize({
13796
14224
  baseUrl: apiUrl,
13797
14225
  apiKey: writeKey,
13798
- logLevel,
14226
+ logLevel: logLevel2,
13799
14227
  silenceInitializationMessage: true,
13800
14228
  tracingEnabled: false
13801
14229
  });
@@ -13841,18 +14269,19 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
13841
14269
  localDebuggerProcessor ? [localDebuggerProcessor] : []
13842
14270
  );
13843
14271
  try {
13844
- traceloop4.initialize({
14272
+ initialize({
13845
14273
  baseUrl: apiUrl,
13846
14274
  apiKey: writeKey,
13847
14275
  ...otherOptions,
13848
- logLevel,
14276
+ logLevel: logLevel2,
13849
14277
  silenceInitializationMessage: true,
13850
14278
  // This branch only runs when tracing is enabled (the disabled
13851
14279
  // case is handled above), so tracing is always on here.
13852
14280
  tracingEnabled: true,
13853
14281
  disableBatch: disableBatching,
13854
14282
  processor,
13855
- exporter: guardedExporter
14283
+ exporter: guardedExporter,
14284
+ instrumentations: createConfiguredInstrumentations(otherOptions)
13856
14285
  });
13857
14286
  traceloopInitialized = true;
13858
14287
  } catch (initError) {
@@ -13983,7 +14412,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
13983
14412
  });
13984
14413
  return;
13985
14414
  }
13986
- const span = import_api5.trace.getTracer("traceloop.tracer").startSpan("ai.model.usage");
14415
+ const span = import_api6.trace.getTracer("traceloop.tracer").startSpan("ai.model.usage");
13987
14416
  span.setAttribute("traceloop.span.kind", "llm");
13988
14417
  span.setAttribute("traceloop.association.properties.event_id", params.eventId);
13989
14418
  stampSpan(span, projectId, authHint);
@@ -14091,7 +14520,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
14091
14520
  );
14092
14521
  }
14093
14522
  const headers = withProjectIdHeaders(processorOptions == null ? void 0 : processorOptions.headers);
14094
- const productionProcessor = traceloop4.createSpanProcessor({
14523
+ const productionProcessor = createSpanProcessor({
14095
14524
  baseUrl: apiUrl,
14096
14525
  apiKey: writeKey,
14097
14526
  disableBatch: disableBatching,
@@ -14157,7 +14586,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
14157
14586
  }
14158
14587
  if (traceloopInitialized) {
14159
14588
  try {
14160
- await traceloop4.forceFlush();
14589
+ await forceFlush();
14161
14590
  } catch (e) {
14162
14591
  }
14163
14592
  }
@@ -14169,7 +14598,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
14169
14598
  await (directShipper == null ? void 0 : directShipper.shutdown());
14170
14599
  if (traceloopInitialized) {
14171
14600
  try {
14172
- await traceloop4.forceFlush();
14601
+ await forceFlush();
14173
14602
  } catch (e) {
14174
14603
  }
14175
14604
  }
@@ -14611,14 +15040,14 @@ var Raindrop = class {
14611
15040
  const description = buildSelfDiagnosticsDescription(signals, options.guidance);
14612
15041
  const inputSchema = buildSelfDiagnosticsInputSchema(signalKeys);
14613
15042
  const onMissingEventId = (_b = options.onMissingEventId) != null ? _b : "warn";
14614
- const execute = async (rawInput, context6) => {
15043
+ const execute = async (rawInput, context7) => {
14615
15044
  var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
14616
15045
  const input = isRecord(rawInput) ? rawInput : void 0;
14617
15046
  const fallbackCategory = (_a2 = signalKeys[0]) != null ? _a2 : "unknown";
14618
15047
  const categoryCandidate = normalizeEventId(input == null ? void 0 : input["category"]);
14619
15048
  const category = categoryCandidate && signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
14620
15049
  const detail = (_b2 = normalizeEventId(input == null ? void 0 : input["detail"])) != null ? _b2 : "";
14621
- const eventId = (_l = (_k = (_i = (_g = (_f = (_e = (_d = normalizeEventId(context6 == null ? void 0 : context6.eventId)) != null ? _d : (_c = context6 == null ? void 0 : context6.interaction) == null ? void 0 : _c.getEventId()) != null ? _e : resolveEventIdFromMetadata(context6 == null ? void 0 : context6.metadata)) != null ? _f : normalizeEventId(input == null ? void 0 : input["event_id"])) != null ? _g : normalizeEventId(input == null ? void 0 : input["eventId"])) != null ? _i : (_h = options.interaction) == null ? void 0 : _h.getEventId()) != null ? _k : (_j = options.getEventId) == null ? void 0 : _j.call(options)) != null ? _l : normalizeEventId(options.eventId);
15050
+ const eventId = (_l = (_k = (_i = (_g = (_f = (_e = (_d = normalizeEventId(context7 == null ? void 0 : context7.eventId)) != null ? _d : (_c = context7 == null ? void 0 : context7.interaction) == null ? void 0 : _c.getEventId()) != null ? _e : resolveEventIdFromMetadata(context7 == null ? void 0 : context7.metadata)) != null ? _f : normalizeEventId(input == null ? void 0 : input["event_id"])) != null ? _g : normalizeEventId(input == null ? void 0 : input["eventId"])) != null ? _i : (_h = options.interaction) == null ? void 0 : _h.getEventId()) != null ? _k : (_j = options.getEventId) == null ? void 0 : _j.call(options)) != null ? _l : normalizeEventId(options.eventId);
14622
15051
  if (!eventId) {
14623
15052
  const message = "self diagnostics signal skipped: missing eventId. Pass eventId, interaction, or getEventId when creating or executing the tool.";
14624
15053
  if (onMissingEventId === "throw") {
@@ -14636,11 +15065,11 @@ var Raindrop = class {
14636
15065
  type: "agent",
14637
15066
  sentiment: signalDefinition == null ? void 0 : signalDefinition.sentiment,
14638
15067
  properties: {
14639
- source: (context6 == null ? void 0 : context6.source) || options.source || SELF_DIAGNOSTICS_SOURCE_DEFAULT,
15068
+ source: (context7 == null ? void 0 : context7.source) || options.source || SELF_DIAGNOSTICS_SOURCE_DEFAULT,
14640
15069
  category,
14641
15070
  signal_description: signalDefinition == null ? void 0 : signalDefinition.description,
14642
15071
  ...detail ? { detail } : {},
14643
- ...(_m = context6 == null ? void 0 : context6.properties) != null ? _m : {}
15072
+ ...(_m = context7 == null ? void 0 : context7.properties) != null ? _m : {}
14644
15073
  }
14645
15074
  });
14646
15075
  return { acknowledged: true, category, eventId };
@@ -15030,7 +15459,7 @@ var Raindrop = class {
15030
15459
  }
15031
15460
  getContext() {
15032
15461
  const runtime = detectRuntime();
15033
- const context6 = {
15462
+ const context7 = {
15034
15463
  library: {
15035
15464
  name: package_default.name,
15036
15465
  version: package_default.version
@@ -15040,9 +15469,9 @@ var Raindrop = class {
15040
15469
  }
15041
15470
  };
15042
15471
  if (runtime === "node") {
15043
- context6.metadata.nodeVersion = process.version;
15472
+ context7.metadata.nodeVersion = process.version;
15044
15473
  }
15045
- return context6;
15474
+ return context7;
15046
15475
  }
15047
15476
  formatZodError(error) {
15048
15477
  return error.issues.map((issue) => `(path: ${issue.path.join(".")}): ${issue.message}`).join(", ");