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.
@@ -36,7 +36,7 @@ __export(tracing_exports, {
36
36
  module.exports = __toCommonJS(tracing_exports);
37
37
 
38
38
  // src/tracing/tracer-core.ts
39
- var import_api5 = require("@opentelemetry/api");
39
+ var import_api6 = require("@opentelemetry/api");
40
40
  var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
41
41
 
42
42
  // ../core/dist/chunk-3V4MIA75.js
@@ -1097,11 +1097,404 @@ var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock
1097
1097
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
1098
1098
  var import_instrumentation_cohere = require("@traceloop/instrumentation-cohere");
1099
1099
  var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
1100
+ var import_instrumentation_langchain = require("@traceloop/instrumentation-langchain");
1101
+ var import_instrumentation_llamaindex = require("@traceloop/instrumentation-llamaindex");
1100
1102
  var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
1101
1103
  var import_instrumentation_qdrant = require("@traceloop/instrumentation-qdrant");
1102
1104
  var import_instrumentation_together = require("@traceloop/instrumentation-together");
1103
1105
  var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
1104
- var traceloop4 = __toESM(require("@traceloop/node-server-sdk"));
1106
+
1107
+ // src/tracing/otel-core/index.ts
1108
+ var import_api = require("@opentelemetry/api");
1109
+ var import_core = require("@opentelemetry/core");
1110
+ var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
1111
+ var import_instrumentation = require("@opentelemetry/instrumentation");
1112
+ var resourceModule = __toESM(require("@opentelemetry/resources"));
1113
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
1114
+ var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
1115
+ var import_ai_semantic_conventions = require("@traceloop/ai-semantic-conventions");
1116
+ var ALL_INSTRUMENTATION_LIBRARIES = "all";
1117
+ var TRACER_NAME = "@traceloop/node-server-sdk";
1118
+ var WORKFLOW_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.workflowName");
1119
+ var ENTITY_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.entityName");
1120
+ var ASSOCIATION_PROPERTIES_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.associationProperties");
1121
+ var INSTRUMENTATION_LIBRARIES = [
1122
+ "ai",
1123
+ "@traceloop/node-server-sdk",
1124
+ "@traceloop/instrumentation-openai",
1125
+ "@traceloop/instrumentation-langchain",
1126
+ "@traceloop/instrumentation-chroma",
1127
+ "@traceloop/instrumentation-chromadb",
1128
+ "@traceloop/instrumentation-anthropic",
1129
+ "@traceloop/instrumentation-llamaindex",
1130
+ "@traceloop/instrumentation-vertexai",
1131
+ "@traceloop/instrumentation-bedrock",
1132
+ "@traceloop/instrumentation-cohere",
1133
+ "@traceloop/instrumentation-pinecone",
1134
+ "@traceloop/instrumentation-qdrant",
1135
+ "@traceloop/instrumentation-together",
1136
+ TRACER_NAME,
1137
+ "traceloop.tracer"
1138
+ ];
1139
+ var AI_GENERATE_TEXT = "ai.generateText.doGenerate";
1140
+ var AI_STREAM_TEXT = "ai.streamText.doStream";
1141
+ var AI_RESPONSE_TEXT = "ai.response.text";
1142
+ var AI_PROMPT_MESSAGES = "ai.prompt.messages";
1143
+ var AI_PROMPT_TOKENS = "ai.usage.promptTokens";
1144
+ var AI_COMPLETION_TOKENS = "ai.usage.completionTokens";
1145
+ var AI_MODEL_PROVIDER = "ai.model.provider";
1146
+ var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.state");
1147
+ function getState() {
1148
+ var _a;
1149
+ const holder = globalThis;
1150
+ (_a = holder[STATE_KEY]) != null ? _a : holder[STATE_KEY] = {};
1151
+ return holder[STATE_KEY];
1152
+ }
1153
+ function parseHeaders(value) {
1154
+ const headers = {};
1155
+ if (!value) return headers;
1156
+ for (const pair of value.split(",")) {
1157
+ const separator = pair.indexOf("=");
1158
+ if (separator <= 0) continue;
1159
+ try {
1160
+ const key = decodeURIComponent(pair.slice(0, separator).trim());
1161
+ const val = decodeURIComponent(pair.slice(separator + 1).trim());
1162
+ if (key && val) headers[key] = val;
1163
+ } catch (e) {
1164
+ }
1165
+ }
1166
+ return headers;
1167
+ }
1168
+ function safeStringify(value) {
1169
+ try {
1170
+ const result = JSON.stringify(value);
1171
+ return result === void 0 ? String(value) : result;
1172
+ } catch (e) {
1173
+ return "[unserializable]";
1174
+ }
1175
+ }
1176
+ function createResource(attributes) {
1177
+ if ("resourceFromAttributes" in resourceModule) {
1178
+ const factory = resourceModule.resourceFromAttributes;
1179
+ if (typeof factory === "function") return factory(attributes);
1180
+ }
1181
+ return new resourceModule.Resource(attributes);
1182
+ }
1183
+ function detectRuntimeResource() {
1184
+ try {
1185
+ if ("detectResourcesSync" in resourceModule && typeof resourceModule.detectResourcesSync === "function" && "envDetectorSync" in resourceModule) {
1186
+ return resourceModule.detectResourcesSync({
1187
+ detectors: [
1188
+ resourceModule.envDetectorSync,
1189
+ resourceModule.processDetectorSync,
1190
+ resourceModule.hostDetectorSync
1191
+ ]
1192
+ });
1193
+ }
1194
+ if ("detectResources" in resourceModule && typeof resourceModule.detectResources === "function" && "envDetector" in resourceModule) {
1195
+ const detected = resourceModule.detectResources({
1196
+ detectors: [
1197
+ resourceModule.envDetector,
1198
+ resourceModule.processDetector,
1199
+ resourceModule.hostDetector
1200
+ ]
1201
+ });
1202
+ if (!(detected instanceof Promise)) {
1203
+ return detected;
1204
+ }
1205
+ }
1206
+ } catch (e) {
1207
+ }
1208
+ return void 0;
1209
+ }
1210
+ function logLevel(level) {
1211
+ switch (level) {
1212
+ case "debug":
1213
+ return import_api.DiagLogLevel.DEBUG;
1214
+ case "info":
1215
+ return import_api.DiagLogLevel.INFO;
1216
+ case "warn":
1217
+ return import_api.DiagLogLevel.WARN;
1218
+ default:
1219
+ return import_api.DiagLogLevel.ERROR;
1220
+ }
1221
+ }
1222
+ function transformAiSdkSpan(span) {
1223
+ const names = {
1224
+ [AI_GENERATE_TEXT]: "ai.generateText.generate",
1225
+ [AI_STREAM_TEXT]: "ai.streamText.stream"
1226
+ };
1227
+ if (!(span.name in names)) return span;
1228
+ const attributes = span.attributes;
1229
+ if (AI_RESPONSE_TEXT in attributes) {
1230
+ const response = attributes[AI_RESPONSE_TEXT];
1231
+ if (typeof response === "string") {
1232
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_COMPLETIONS}.0.content`] = response;
1233
+ }
1234
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_COMPLETIONS}.0.role`] = "assistant";
1235
+ delete attributes[AI_RESPONSE_TEXT];
1236
+ }
1237
+ if (AI_PROMPT_MESSAGES in attributes) {
1238
+ try {
1239
+ const parsed = JSON.parse(String(attributes[AI_PROMPT_MESSAGES]));
1240
+ if (Array.isArray(parsed)) {
1241
+ parsed.forEach((message, index) => {
1242
+ if (!message || typeof message !== "object") return;
1243
+ const content = "content" in message ? message.content : void 0;
1244
+ const role = "role" in message ? message.role : void 0;
1245
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.content`] = typeof content === "string" ? content : safeStringify(content);
1246
+ if (typeof role === "string") {
1247
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.role`] = role;
1248
+ }
1249
+ });
1250
+ }
1251
+ delete attributes[AI_PROMPT_MESSAGES];
1252
+ } catch (e) {
1253
+ }
1254
+ }
1255
+ if (AI_PROMPT_TOKENS in attributes) {
1256
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_PROMPT_TOKENS] = Number(attributes[AI_PROMPT_TOKENS]);
1257
+ delete attributes[AI_PROMPT_TOKENS];
1258
+ }
1259
+ if (AI_COMPLETION_TOKENS in attributes) {
1260
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_COMPLETION_TOKENS] = Number(attributes[AI_COMPLETION_TOKENS]);
1261
+ delete attributes[AI_COMPLETION_TOKENS];
1262
+ }
1263
+ const prompt = attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_PROMPT_TOKENS];
1264
+ const completion = attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_COMPLETION_TOKENS];
1265
+ if (prompt !== void 0 && completion !== void 0) {
1266
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_USAGE_TOTAL_TOKENS] = Number(prompt) + Number(completion);
1267
+ }
1268
+ if (AI_MODEL_PROVIDER in attributes) {
1269
+ const vendor = String(attributes[AI_MODEL_PROVIDER]);
1270
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_SYSTEM] = vendor.startsWith("openai") ? "OpenAI" : vendor;
1271
+ delete attributes[AI_MODEL_PROVIDER];
1272
+ }
1273
+ Object.defineProperty(span, "name", {
1274
+ configurable: true,
1275
+ value: names[span.name],
1276
+ writable: true
1277
+ });
1278
+ return span;
1279
+ }
1280
+ function scopeName(span) {
1281
+ var _a;
1282
+ if ("instrumentationScope" in span) {
1283
+ const scope = span.instrumentationScope;
1284
+ if (scope && typeof scope === "object" && "name" in scope && typeof scope.name === "string") {
1285
+ return scope.name;
1286
+ }
1287
+ }
1288
+ return (_a = span.instrumentationLibrary) == null ? void 0 : _a.name;
1289
+ }
1290
+ function contentCaptureDisabled(options) {
1291
+ return options.traceContent === false || (process.env.TRACELOOP_TRACE_CONTENT || "true").toLowerCase() === "false";
1292
+ }
1293
+ function shouldSendTraceContent() {
1294
+ var _a;
1295
+ const contextual = import_api.context.active().getValue(import_ai_semantic_conventions.CONTEXT_KEY_ALLOW_TRACE_CONTENT);
1296
+ if (typeof contextual === "boolean") return contextual;
1297
+ if (((_a = getState().configuration) == null ? void 0 : _a.traceContent) === false) return false;
1298
+ return (process.env.TRACELOOP_TRACE_CONTENT || "true").toLowerCase() !== "false";
1299
+ }
1300
+ function enrichStart(span) {
1301
+ const active = import_api.context.active();
1302
+ const workflow = active.getValue(WORKFLOW_NAME_KEY);
1303
+ if (typeof workflow === "string") span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_WORKFLOW_NAME, workflow);
1304
+ const entity = active.getValue(ENTITY_NAME_KEY);
1305
+ if (typeof entity === "string") span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_PATH, entity);
1306
+ const properties = active.getValue(ASSOCIATION_PROPERTIES_KEY);
1307
+ if (properties && typeof properties === "object") {
1308
+ for (const [key, value] of Object.entries(properties)) {
1309
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1310
+ span.setAttribute(`${import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.${key}`, value);
1311
+ }
1312
+ }
1313
+ }
1314
+ }
1315
+ function createSpanProcessor(options) {
1316
+ var _a, _b;
1317
+ const baseUrl = options.baseUrl || process.env.TRACELOOP_BASE_URL || "https://api.traceloop.com";
1318
+ const apiKey = options.apiKey || process.env.TRACELOOP_API_KEY;
1319
+ const resolvedHeaders = (_a = options.headers) != null ? _a : process.env.TRACELOOP_HEADERS ? parseHeaders(process.env.TRACELOOP_HEADERS) : { Authorization: `Bearer ${apiKey}` };
1320
+ const exporter = (_b = options.exporter) != null ? _b : new import_exporter_trace_otlp_proto.OTLPTraceExporter({ url: `${baseUrl}/v1/traces`, headers: resolvedHeaders });
1321
+ const processor = options.disableBatch ? new import_sdk_trace_base.SimpleSpanProcessor(exporter) : new import_sdk_trace_base.BatchSpanProcessor(exporter);
1322
+ const originalOnStart = processor.onStart.bind(processor);
1323
+ const originalOnEnd = processor.onEnd.bind(processor);
1324
+ processor.onStart = (span, parentContext) => {
1325
+ try {
1326
+ enrichStart(span);
1327
+ originalOnStart(span, parentContext);
1328
+ } catch (e) {
1329
+ }
1330
+ };
1331
+ processor.onEnd = (span) => {
1332
+ var _a2;
1333
+ let outgoing = span;
1334
+ try {
1335
+ const allowed = options.allowedInstrumentationLibraries;
1336
+ if (allowed !== ALL_INSTRUMENTATION_LIBRARIES && ![...INSTRUMENTATION_LIBRARIES, ...allowed != null ? allowed : []].includes((_a2 = scopeName(span)) != null ? _a2 : "")) {
1337
+ return;
1338
+ }
1339
+ outgoing = transformAiSdkSpan(span);
1340
+ } catch (e) {
1341
+ }
1342
+ try {
1343
+ originalOnEnd(outgoing);
1344
+ } catch (e) {
1345
+ }
1346
+ };
1347
+ return processor;
1348
+ }
1349
+ function initialize(options = {}) {
1350
+ var _a;
1351
+ const state = getState();
1352
+ if (state.configuration) return;
1353
+ state.configuration = Object.freeze({ ...options });
1354
+ if (options.logLevel) import_api.diag.setLogger(new import_api.DiagConsoleLogger(), logLevel(options.logLevel));
1355
+ if (options.tracingEnabled === false) return;
1356
+ const baseUrl = options.baseUrl || process.env.TRACELOOP_BASE_URL || "https://api.traceloop.com";
1357
+ state.defaultProcessor = createSpanProcessor({
1358
+ ...options,
1359
+ baseUrl,
1360
+ allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES
1361
+ });
1362
+ const serviceResource = createResource({
1363
+ "service.name": options.appName || process.env.npm_package_name || "unknown_service"
1364
+ });
1365
+ const detectedResource = detectRuntimeResource();
1366
+ state.provider = new import_sdk_trace_node.NodeTracerProvider({
1367
+ // Detected attributes win over the configured resource, matching
1368
+ // sdk-node's `this._resource.merge(detectResourcesSync(...))` so
1369
+ // OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES can still override appName.
1370
+ resource: detectedResource ? serviceResource.merge(detectedResource) : serviceResource,
1371
+ spanProcessors: [state.defaultProcessor, ...options.processor ? [options.processor] : []]
1372
+ });
1373
+ state.provider.register({
1374
+ contextManager: options.contextManager,
1375
+ propagator: options.propagator
1376
+ });
1377
+ const instrumentations = (_a = options.instrumentations) != null ? _a : [];
1378
+ if (contentCaptureDisabled(options)) {
1379
+ for (const instrumentation of instrumentations) {
1380
+ try {
1381
+ const config = {
1382
+ ...instrumentation.getConfig(),
1383
+ traceContent: false
1384
+ };
1385
+ instrumentation.setConfig(config);
1386
+ } catch (e) {
1387
+ }
1388
+ }
1389
+ }
1390
+ (0, import_instrumentation.registerInstrumentations)({ instrumentations });
1391
+ }
1392
+ async function forceFlush() {
1393
+ var _a, _b;
1394
+ const state = getState();
1395
+ try {
1396
+ await ((_a = state.provider) == null ? void 0 : _a.forceFlush());
1397
+ await ((_b = state.defaultProcessor) == null ? void 0 : _b.forceFlush());
1398
+ } catch (e) {
1399
+ }
1400
+ }
1401
+ function withEntity(type, config, fn, args) {
1402
+ let entityContext = import_api.context.active();
1403
+ if (type === import_ai_semantic_conventions.TraceloopSpanKindValues.WORKFLOW) {
1404
+ entityContext = entityContext.setValue(WORKFLOW_NAME_KEY, config.name);
1405
+ }
1406
+ const parentPath = entityContext.getValue(ENTITY_NAME_KEY);
1407
+ if (type === import_ai_semantic_conventions.TraceloopSpanKindValues.TASK || type === import_ai_semantic_conventions.TraceloopSpanKindValues.TOOL) {
1408
+ entityContext = entityContext.setValue(
1409
+ ENTITY_NAME_KEY,
1410
+ `${typeof parentPath === "string" ? `${parentPath}.` : ""}${config.name}`
1411
+ );
1412
+ }
1413
+ if (config.traceContent !== void 0) {
1414
+ entityContext = entityContext.setValue(import_ai_semantic_conventions.CONTEXT_KEY_ALLOW_TRACE_CONTENT, config.traceContent);
1415
+ }
1416
+ if (config.associationProperties) {
1417
+ entityContext = entityContext.setValue(ASSOCIATION_PROPERTIES_KEY, config.associationProperties);
1418
+ }
1419
+ if (config.suppressTracing) {
1420
+ entityContext = (0, import_core.suppressTracing)(entityContext);
1421
+ }
1422
+ let callbackStarted = false;
1423
+ const run = (span) => {
1424
+ var _a;
1425
+ try {
1426
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_NAME, config.name);
1427
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_PATH, typeof parentPath === "string" ? parentPath : "");
1428
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_SPAN_KIND, type);
1429
+ if (type === import_ai_semantic_conventions.TraceloopSpanKindValues.WORKFLOW) {
1430
+ span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_WORKFLOW_NAME, config.name);
1431
+ }
1432
+ if (config.version !== void 0) span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_VERSION, config.version);
1433
+ const input = (_a = config.inputParameters) != null ? _a : args;
1434
+ if (shouldSendTraceContent()) {
1435
+ span.setAttribute(
1436
+ import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_INPUT,
1437
+ safeStringify(input.length === 1 && input[0] !== null && typeof input[0] === "object" && !(input[0] instanceof Map) ? { args: [], kwargs: input[0] } : { args: input, kwargs: {} })
1438
+ );
1439
+ }
1440
+ } catch (e) {
1441
+ }
1442
+ let result;
1443
+ try {
1444
+ callbackStarted = true;
1445
+ result = fn(...args);
1446
+ } catch (error) {
1447
+ try {
1448
+ span.end();
1449
+ } catch (e) {
1450
+ }
1451
+ throw error;
1452
+ }
1453
+ if (result instanceof Promise) {
1454
+ return result.then(
1455
+ (value) => {
1456
+ try {
1457
+ if (shouldSendTraceContent()) span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_OUTPUT, safeStringify(value));
1458
+ span.end();
1459
+ } catch (e) {
1460
+ }
1461
+ return value;
1462
+ },
1463
+ (error) => {
1464
+ try {
1465
+ span.end();
1466
+ } catch (e) {
1467
+ }
1468
+ throw error;
1469
+ }
1470
+ );
1471
+ }
1472
+ try {
1473
+ if (shouldSendTraceContent()) span.setAttribute(import_ai_semantic_conventions.SpanAttributes.TRACELOOP_ENTITY_OUTPUT, safeStringify(result));
1474
+ span.end();
1475
+ } catch (e) {
1476
+ }
1477
+ return result;
1478
+ };
1479
+ try {
1480
+ const tracer = import_api.trace.getTracer(TRACER_NAME);
1481
+ return import_api.context.with(
1482
+ entityContext,
1483
+ () => tracer.startActiveSpan(`${config.name}.${type}`, {}, entityContext, run)
1484
+ );
1485
+ } catch (error) {
1486
+ if (callbackStarted) throw error;
1487
+ return fn(...args);
1488
+ }
1489
+ }
1490
+ function withTask(config, fn, ...args) {
1491
+ return withEntity(import_ai_semantic_conventions.TraceloopSpanKindValues.TASK, config, fn, args);
1492
+ }
1493
+ function withTool(config, fn, ...args) {
1494
+ return withEntity(import_ai_semantic_conventions.TraceloopSpanKindValues.TOOL, config, fn, args);
1495
+ }
1496
+
1497
+ // src/tracing/tracer-core.ts
1105
1498
  var import_weakref = require("weakref");
1106
1499
 
1107
1500
  // src/lib/inject-als.ts
@@ -1266,7 +1659,7 @@ function base64ToHex2(base64) {
1266
1659
  // package.json
1267
1660
  var package_default = {
1268
1661
  name: "raindrop-ai",
1269
- version: "0.3.1",
1662
+ version: "0.4.0",
1270
1663
  main: "dist/index.js",
1271
1664
  module: "dist/index.mjs",
1272
1665
  types: "dist/index.d.ts",
@@ -1320,7 +1713,6 @@ var package_default = {
1320
1713
  "@raindrop-ai/redact-pii": "workspace:*",
1321
1714
  "@raindrop-ai/schemas": "workspace:*",
1322
1715
  ai: "^6.0.0",
1323
- "@opentelemetry/resources": "^2.0.1",
1324
1716
  "@types/node": "^20.11.17",
1325
1717
  msw: "^2.12.8",
1326
1718
  tsup: "^8.4.0",
@@ -1331,9 +1723,25 @@ var package_default = {
1331
1723
  },
1332
1724
  dependencies: {
1333
1725
  "@opentelemetry/api": "^1.9.0",
1726
+ "@opentelemetry/core": "^1.30.1",
1334
1727
  "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
1335
1728
  "@opentelemetry/exporter-trace-otlp-proto": "^0.57.2",
1336
- "@traceloop/node-server-sdk": "0.19.0-otel-v1",
1729
+ "@opentelemetry/instrumentation": "^0.57.2",
1730
+ "@opentelemetry/resources": "^1.30.1",
1731
+ "@opentelemetry/sdk-trace-base": "^1.30.1",
1732
+ "@opentelemetry/sdk-trace-node": "^1.30.1",
1733
+ "@traceloop/ai-semantic-conventions": "0.19.0-otel-v1",
1734
+ "@traceloop/instrumentation-anthropic": "0.19.0-otel-v1",
1735
+ "@traceloop/instrumentation-openai": "0.19.0-otel-v1",
1736
+ "@traceloop/instrumentation-cohere": "0.19.0-otel-v1",
1737
+ "@traceloop/instrumentation-bedrock": "0.19.0-otel-v1",
1738
+ "@traceloop/instrumentation-vertexai": "0.19.0-otel-v1",
1739
+ "@traceloop/instrumentation-pinecone": "0.19.0-otel-v1",
1740
+ "@traceloop/instrumentation-chromadb": "0.19.0-otel-v1",
1741
+ "@traceloop/instrumentation-qdrant": "0.19.0-otel-v1",
1742
+ "@traceloop/instrumentation-together": "0.19.0-otel-v1",
1743
+ "@traceloop/instrumentation-langchain": "0.19.0-otel-v1",
1744
+ "@traceloop/instrumentation-llamaindex": "0.19.0-otel-v1",
1337
1745
  weakref: "^0.2.1",
1338
1746
  zod: "^3.23.8"
1339
1747
  },
@@ -1352,7 +1760,6 @@ var package_default = {
1352
1760
  "esm"
1353
1761
  ],
1354
1762
  external: [
1355
- "@traceloop/node-server-sdk",
1356
1763
  "@traceloop/instrumentation-anthropic",
1357
1764
  "@traceloop/instrumentation-openai",
1358
1765
  "@traceloop/instrumentation-cohere",
@@ -1362,10 +1769,17 @@ var package_default = {
1362
1769
  "@traceloop/instrumentation-chromadb",
1363
1770
  "@traceloop/instrumentation-qdrant",
1364
1771
  "@traceloop/instrumentation-together",
1772
+ "@traceloop/instrumentation-langchain",
1773
+ "@traceloop/instrumentation-llamaindex",
1774
+ "@traceloop/ai-semantic-conventions",
1775
+ "@opentelemetry/api",
1776
+ "@opentelemetry/core",
1365
1777
  "@opentelemetry/instrumentation",
1366
1778
  "@opentelemetry/exporter-trace-otlp-http",
1367
1779
  "@opentelemetry/exporter-trace-otlp-proto",
1368
- "@opentelemetry/sdk-trace-base"
1780
+ "@opentelemetry/resources",
1781
+ "@opentelemetry/sdk-trace-base",
1782
+ "@opentelemetry/sdk-trace-node"
1369
1783
  ],
1370
1784
  noExternal: [
1371
1785
  "@raindrop-ai/core",
@@ -1424,7 +1838,7 @@ function buildExportTraceServiceRequest2(spans) {
1424
1838
  }
1425
1839
 
1426
1840
  // src/tracing/direct/context.ts
1427
- var import_api = require("@opentelemetry/api");
1841
+ var import_api2 = require("@opentelemetry/api");
1428
1842
  var INVALID_TRACE_ID = "00000000000000000000000000000000";
1429
1843
  var INVALID_SPAN_ID = "0000000000000000";
1430
1844
  function hexToBase64(hex) {
@@ -1435,7 +1849,7 @@ function hexToBase64(hex) {
1435
1849
  return base64Encode2(bytes);
1436
1850
  }
1437
1851
  function getExplicitTraceContext(traceId, parentSpanId) {
1438
- if (!traceId || !parentSpanId || !(0, import_api.isValidTraceId)(traceId) || !(0, import_api.isValidSpanId)(parentSpanId)) {
1852
+ if (!traceId || !parentSpanId || !(0, import_api2.isValidTraceId)(traceId) || !(0, import_api2.isValidSpanId)(parentSpanId)) {
1439
1853
  return void 0;
1440
1854
  }
1441
1855
  return {
@@ -1444,7 +1858,7 @@ function getExplicitTraceContext(traceId, parentSpanId) {
1444
1858
  };
1445
1859
  }
1446
1860
  function getActiveTraceContext() {
1447
- const activeSpan = import_api.trace.getSpan(import_api.context.active());
1861
+ const activeSpan = import_api2.trace.getSpan(import_api2.context.active());
1448
1862
  if (!activeSpan) return {};
1449
1863
  const spanContext = activeSpan.spanContext();
1450
1864
  const traceIdHex = spanContext.traceId;
@@ -1458,7 +1872,7 @@ function getActiveTraceContext() {
1458
1872
 
1459
1873
  // src/tracing/multi-project.ts
1460
1874
  var import_node_crypto = require("crypto");
1461
- var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
1875
+ var import_exporter_trace_otlp_proto2 = require("@opentelemetry/exporter-trace-otlp-proto");
1462
1876
  var PROJECT_ID_SPAN_ATTRIBUTE = "raindrop.project_id";
1463
1877
  var AUTH_HINT_SPAN_ATTRIBUTE = "raindrop.auth_hint";
1464
1878
  var EXPORT_SUCCESS = 0;
@@ -1468,10 +1882,10 @@ function authHintForKey(writeKey) {
1468
1882
  if (!writeKey) return void 0;
1469
1883
  return (0, import_node_crypto.createHash)("sha256").update(writeKey, "utf8").digest("hex").slice(0, 8);
1470
1884
  }
1471
- var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.multiProjectState");
1472
- function getState() {
1885
+ var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.multiProjectState");
1886
+ function getState2() {
1473
1887
  const holder = globalThis;
1474
- let state = holder[STATE_KEY];
1888
+ let state = holder[STATE_KEY2];
1475
1889
  if (!state) {
1476
1890
  state = {
1477
1891
  foreignClientSeen: false,
@@ -1483,12 +1897,12 @@ function getState() {
1483
1897
  multiKeyWarned: false,
1484
1898
  pendingMultiKeyWarning: false
1485
1899
  };
1486
- holder[STATE_KEY] = state;
1900
+ holder[STATE_KEY2] = state;
1487
1901
  }
1488
1902
  return state;
1489
1903
  }
1490
1904
  function emitMultiKeyWarningOnce() {
1491
- const state = getState();
1905
+ const state = getState2();
1492
1906
  if (state.multiKeyWarned) return;
1493
1907
  state.multiKeyWarned = true;
1494
1908
  state.pendingMultiKeyWarning = false;
@@ -1498,7 +1912,7 @@ function emitMultiKeyWarningOnce() {
1498
1912
  }
1499
1913
  function registerClientKey(authHint, tracingEnabled = false) {
1500
1914
  if (!authHint) return;
1501
- const state = getState();
1915
+ const state = getState2();
1502
1916
  state.seenClientHints.add(authHint);
1503
1917
  if (state.seenClientHints.size > 1) {
1504
1918
  state.foreignClientSeen = true;
@@ -1510,10 +1924,10 @@ function registerClientKey(authHint, tracingEnabled = false) {
1510
1924
  }
1511
1925
  }
1512
1926
  function markForeignClient() {
1513
- getState().foreignClientSeen = true;
1927
+ getState2().foreignClientSeen = true;
1514
1928
  }
1515
1929
  function foreignClientSeen() {
1516
- return getState().foreignClientSeen;
1930
+ return getState2().foreignClientSeen;
1517
1931
  }
1518
1932
  function stampSpan(span, projectId, authHint) {
1519
1933
  try {
@@ -1619,17 +2033,17 @@ var GuardedSpanExporter = class {
1619
2033
  }
1620
2034
  };
1621
2035
  function buildGuardedExporter(baseUrl, headers, ownerAuthHint) {
1622
- const inner = new import_exporter_trace_otlp_proto.OTLPTraceExporter({
2036
+ const inner = new import_exporter_trace_otlp_proto2.OTLPTraceExporter({
1623
2037
  url: `${baseUrl}/v1/traces`,
1624
2038
  headers
1625
2039
  });
1626
2040
  return new GuardedSpanExporter(inner, ownerAuthHint);
1627
2041
  }
1628
2042
  function pipelineOwnerHint() {
1629
- return getState().ownerAuthHint;
2043
+ return getState2().ownerAuthHint;
1630
2044
  }
1631
2045
  function claimPipeline(authHint, projectId) {
1632
- const state = getState();
2046
+ const state = getState2();
1633
2047
  if (state.pipelineClaimed) {
1634
2048
  return false;
1635
2049
  }
@@ -1642,16 +2056,16 @@ function claimPipeline(authHint, projectId) {
1642
2056
  return true;
1643
2057
  }
1644
2058
  function releasePipelineClaim() {
1645
- const state = getState();
2059
+ const state = getState2();
1646
2060
  state.pipelineClaimed = false;
1647
2061
  state.ownerAuthHint = void 0;
1648
2062
  state.ownerProjectId = void 0;
1649
2063
  }
1650
2064
  function markTraceloopConfiguredWithoutClaim() {
1651
- getState().traceloopConfiguredWithoutClaim = true;
2065
+ getState2().traceloopConfiguredWithoutClaim = true;
1652
2066
  }
1653
2067
  function traceloopConfiguredWithoutClaim() {
1654
- return getState().traceloopConfiguredWithoutClaim;
2068
+ return getState2().traceloopConfiguredWithoutClaim;
1655
2069
  }
1656
2070
 
1657
2071
  // src/tracing/direct/shipper.ts
@@ -1888,18 +2302,17 @@ var DirectTraceShipper = class {
1888
2302
  };
1889
2303
 
1890
2304
  // src/tracing/exit-flush.ts
1891
- var traceloop = __toESM(require("@traceloop/node-server-sdk"));
1892
- var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
1893
- function getState2() {
2305
+ var STATE_KEY3 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
2306
+ function getState3() {
1894
2307
  const holder = globalThis;
1895
- let state = holder[STATE_KEY2];
2308
+ let state = holder[STATE_KEY3];
1896
2309
  if (!state) {
1897
2310
  state = {
1898
2311
  clientFlushers: /* @__PURE__ */ new Set(),
1899
2312
  pipelineFlushNeeded: false,
1900
2313
  handlerRegistered: false
1901
2314
  };
1902
- holder[STATE_KEY2] = state;
2315
+ holder[STATE_KEY3] = state;
1903
2316
  }
1904
2317
  return state;
1905
2318
  }
@@ -1912,7 +2325,7 @@ function ensureExitHandler(state) {
1912
2325
  });
1913
2326
  }
1914
2327
  function registerClientFlusher(flush) {
1915
- const state = getState2();
2328
+ const state = getState3();
1916
2329
  state.clientFlushers.add(flush);
1917
2330
  ensureExitHandler(state);
1918
2331
  return () => {
@@ -1920,12 +2333,12 @@ function registerClientFlusher(flush) {
1920
2333
  };
1921
2334
  }
1922
2335
  function markPipelineForExitFlush() {
1923
- const state = getState2();
2336
+ const state = getState3();
1924
2337
  state.pipelineFlushNeeded = true;
1925
2338
  ensureExitHandler(state);
1926
2339
  }
1927
2340
  async function flushAll() {
1928
- const state = getState2();
2341
+ const state = getState3();
1929
2342
  const tasks = [];
1930
2343
  for (const flush of state.clientFlushers) {
1931
2344
  tasks.push(Promise.resolve().then(flush).catch(() => {
@@ -1933,7 +2346,7 @@ async function flushAll() {
1933
2346
  }
1934
2347
  if (state.pipelineFlushNeeded) {
1935
2348
  tasks.push(
1936
- Promise.resolve().then(() => traceloop.forceFlush()).catch(() => {
2349
+ Promise.resolve().then(() => forceFlush()).catch(() => {
1937
2350
  })
1938
2351
  );
1939
2352
  }
@@ -1941,11 +2354,10 @@ async function flushAll() {
1941
2354
  }
1942
2355
 
1943
2356
  // src/tracing/liveInteraction.ts
1944
- var import_api3 = require("@opentelemetry/api");
1945
- var traceloop2 = __toESM(require("@traceloop/node-server-sdk"));
2357
+ var import_api4 = require("@opentelemetry/api");
1946
2358
 
1947
2359
  // src/tracing/subagents.ts
1948
- var import_api2 = require("@opentelemetry/api");
2360
+ var import_api3 = require("@opentelemetry/api");
1949
2361
  var DEFAULT_SUBAGENT_NAME = "subagent";
1950
2362
  var DISPATCH_ACCEPTED = "accepted";
1951
2363
  function reasonText(reason) {
@@ -1961,7 +2373,7 @@ function reasonText(reason) {
1961
2373
  }
1962
2374
  function stampCurrentSpan(attributes) {
1963
2375
  try {
1964
- const span = import_api2.trace.getSpan(import_api2.context.active());
2376
+ const span = import_api3.trace.getSpan(import_api3.context.active());
1965
2377
  if (!(span == null ? void 0 : span.isRecording())) return;
1966
2378
  for (const [key, value] of Object.entries(attributes)) {
1967
2379
  span.setAttribute(key, value);
@@ -1972,7 +2384,7 @@ function stampCurrentSpan(attributes) {
1972
2384
  function stampOwnSpan(attributes, frame) {
1973
2385
  if (!frame) return;
1974
2386
  try {
1975
- const span = import_api2.trace.getSpan(import_api2.context.active());
2387
+ const span = import_api3.trace.getSpan(import_api3.context.active());
1976
2388
  if (!(span == null ? void 0 : span.isRecording()) || !frame.ownsSpan(span)) return;
1977
2389
  for (const [key, value] of Object.entries(attributes)) {
1978
2390
  span.setAttribute(key, value);
@@ -1982,11 +2394,11 @@ function stampOwnSpan(attributes, frame) {
1982
2394
  }
1983
2395
  function failOwnSpan(reason, frame) {
1984
2396
  try {
1985
- const span = import_api2.trace.getSpan(import_api2.context.active());
2397
+ const span = import_api3.trace.getSpan(import_api3.context.active());
1986
2398
  if (!(span == null ? void 0 : span.isRecording())) return false;
1987
2399
  if (!(frame == null ? void 0 : frame.ownsSpan(span))) return false;
1988
2400
  const message = reasonText(reason);
1989
- span.setStatus({ code: import_api2.SpanStatusCode.ERROR, message });
2401
+ span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message });
1990
2402
  span.recordException(reason instanceof Error ? reason : new Error(message));
1991
2403
  return true;
1992
2404
  } catch (e) {
@@ -2230,16 +2642,16 @@ var LiveSubagentRun = class {
2230
2642
  };
2231
2643
 
2232
2644
  // src/tracing/liveInteraction.ts
2233
- function getPropertiesFromContext(context6) {
2645
+ function getPropertiesFromContext(context7) {
2234
2646
  const properties = {
2235
- ...context6.userId && { user_id: context6.userId },
2236
- ...context6.convoId && { convo_id: context6.convoId },
2237
- ...context6.eventId && { event_id: context6.eventId },
2238
- ...context6.event && { event_name: context6.event },
2239
- ...context6.properties || {}
2647
+ ...context7.userId && { user_id: context7.userId },
2648
+ ...context7.convoId && { convo_id: context7.convoId },
2649
+ ...context7.eventId && { event_id: context7.eventId },
2650
+ ...context7.event && { event_name: context7.event },
2651
+ ...context7.properties || {}
2240
2652
  };
2241
- if (context6.attachments && context6.attachments.length > 0) {
2242
- properties.attachments = stringifyBounded(context6.attachments);
2653
+ if (context7.attachments && context7.attachments.length > 0) {
2654
+ properties.attachments = stringifyBounded(context7.attachments);
2243
2655
  }
2244
2656
  return properties;
2245
2657
  }
@@ -2259,12 +2671,12 @@ function serializeAssociationProperties(properties) {
2259
2671
  function serializeSpanValue(value) {
2260
2672
  return stringifyBounded(value);
2261
2673
  }
2262
- function getLocalDebuggerMetadata(context6) {
2674
+ function getLocalDebuggerMetadata(context7) {
2263
2675
  return {
2264
- ...context6.eventId ? { eventId: context6.eventId } : {},
2265
- ...context6.event ? { eventName: context6.event } : {},
2266
- ...context6.userId ? { userId: context6.userId } : {},
2267
- ...context6.convoId ? { convoId: context6.convoId } : {}
2676
+ ...context7.eventId ? { eventId: context7.eventId } : {},
2677
+ ...context7.event ? { eventName: context7.event } : {},
2678
+ ...context7.userId ? { userId: context7.userId } : {},
2679
+ ...context7.convoId ? { convoId: context7.convoId } : {}
2268
2680
  };
2269
2681
  }
2270
2682
  var LiveToolSpan = class {
@@ -2276,7 +2688,7 @@ var LiveToolSpan = class {
2276
2688
  }
2277
2689
  spanIdHex() {
2278
2690
  const ctx = this.span.spanContext();
2279
- return (0, import_api3.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
2691
+ return (0, import_api4.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
2280
2692
  }
2281
2693
  setInput(input) {
2282
2694
  this.span.setAttribute("traceloop.entity.input", serializeSpanValue(input));
@@ -2288,13 +2700,13 @@ var LiveToolSpan = class {
2288
2700
  setError(error) {
2289
2701
  this.hasError = true;
2290
2702
  this.errorMessage = error instanceof Error ? error.message : String(error);
2291
- this.span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message: this.errorMessage });
2703
+ this.span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message: this.errorMessage });
2292
2704
  this.span.recordException(error instanceof Error ? error : new Error(this.errorMessage));
2293
2705
  }
2294
2706
  end() {
2295
2707
  var _a;
2296
2708
  if (!this.hasError) {
2297
- this.span.setStatus({ code: import_api3.SpanStatusCode.OK });
2709
+ this.span.setStatus({ code: import_api4.SpanStatusCode.OK });
2298
2710
  }
2299
2711
  this.span.end();
2300
2712
  (_a = this.emitLiveEvent) == null ? void 0 : _a.call(this, {
@@ -2365,11 +2777,11 @@ var DirectToolSpan = class {
2365
2777
  }
2366
2778
  };
2367
2779
  var LiveInteraction = class {
2368
- constructor(context6, traceId, analytics, directShipper, routing) {
2780
+ constructor(context7, traceId, analytics, directShipper, routing) {
2369
2781
  this.usageEmitted = false;
2370
- this.context = context6;
2782
+ this.context = context7;
2371
2783
  this.analytics = analytics;
2372
- this.tracer = import_api3.trace.getTracer("traceloop.tracer");
2784
+ this.tracer = import_api4.trace.getTracer("traceloop.tracer");
2373
2785
  this.traceId = traceId;
2374
2786
  this.directShipper = directShipper;
2375
2787
  this.routing = routing;
@@ -2404,7 +2816,7 @@ var LiveInteraction = class {
2404
2816
  this.traceId = explicitTraceId;
2405
2817
  return explicitTraceId;
2406
2818
  }
2407
- const activeSpan = import_api3.trace.getSpan(import_api3.context.active());
2819
+ const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
2408
2820
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
2409
2821
  if (activeTraceId) {
2410
2822
  this.traceId = activeTraceId;
@@ -2449,12 +2861,12 @@ var LiveInteraction = class {
2449
2861
  const spanContext = {
2450
2862
  traceId: base64ToHex2(traceIdB64),
2451
2863
  spanId: base64ToHex2(spanIdB64),
2452
- traceFlags: import_api3.TraceFlags.SAMPLED
2864
+ traceFlags: import_api4.TraceFlags.SAMPLED
2453
2865
  };
2454
- const wrappedContext = import_api3.trace.setSpan(import_api3.context.active(), import_api3.trace.wrapSpanContext(spanContext));
2866
+ const wrappedContext = import_api4.trace.setSpan(import_api4.context.active(), import_api4.trace.wrapSpanContext(spanContext));
2455
2867
  const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
2456
2868
  try {
2457
- const result = await import_api3.context.with(wrappedContext, invoke);
2869
+ const result = await import_api4.context.with(wrappedContext, invoke);
2458
2870
  const endTimeMs = Date.now();
2459
2871
  this.directShipper.sendSpan({
2460
2872
  name: taskName,
@@ -2489,7 +2901,7 @@ var LiveInteraction = class {
2489
2901
  }
2490
2902
  }
2491
2903
  const wrappedFn = (...fnArgs) => {
2492
- const activeSpan = import_api3.trace.getSpan(import_api3.context.active());
2904
+ const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
2493
2905
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
2494
2906
  if (activeTraceId) {
2495
2907
  this.traceId = activeTraceId;
@@ -2502,7 +2914,7 @@ var LiveInteraction = class {
2502
2914
  }
2503
2915
  return fn.apply(thisArg, fnArgs);
2504
2916
  };
2505
- return traceloop2.withTask(
2917
+ return withTask(
2506
2918
  {
2507
2919
  name: taskName,
2508
2920
  associationProperties: serializeAssociationProperties(properties),
@@ -2541,14 +2953,14 @@ var LiveInteraction = class {
2541
2953
  const spanContext = {
2542
2954
  traceId: base64ToHex2(traceIdB64),
2543
2955
  spanId: base64ToHex2(spanIdB64),
2544
- traceFlags: import_api3.TraceFlags.SAMPLED
2956
+ traceFlags: import_api4.TraceFlags.SAMPLED
2545
2957
  };
2546
- const wrappedContext = import_api3.trace.setSpan(import_api3.context.active(), import_api3.trace.wrapSpanContext(spanContext));
2958
+ const wrappedContext = import_api4.trace.setSpan(import_api4.context.active(), import_api4.trace.wrapSpanContext(spanContext));
2547
2959
  const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
2548
2960
  let result;
2549
2961
  let error;
2550
2962
  try {
2551
- result = await import_api3.context.with(wrappedContext, invoke);
2963
+ result = await import_api4.context.with(wrappedContext, invoke);
2552
2964
  } catch (err) {
2553
2965
  error = err instanceof Error ? err.message : String(err);
2554
2966
  const endTimeMs2 = Date.now();
@@ -2613,9 +3025,9 @@ var LiveInteraction = class {
2613
3025
  const inputParams = params.inputParameters ? [params.inputParameters] : void 0;
2614
3026
  const emitLive = (event) => this.emitLiveEvent(event);
2615
3027
  const wrapped = async (...wrappedArgs) => {
2616
- const activeSpan = import_api3.trace.getSpan(import_api3.context.active());
3028
+ const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
2617
3029
  const ctx = activeSpan == null ? void 0 : activeSpan.spanContext();
2618
- const liveSpanId = ctx && (0, import_api3.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
3030
+ const liveSpanId = ctx && (0, import_api4.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
2619
3031
  if (activeSpan) {
2620
3032
  this.stampRouting(activeSpan);
2621
3033
  }
@@ -2653,7 +3065,7 @@ var LiveInteraction = class {
2653
3065
  throw error;
2654
3066
  }
2655
3067
  };
2656
- return traceloop2.withTool(
3068
+ return withTool(
2657
3069
  {
2658
3070
  name: toolName,
2659
3071
  associationProperties: serializeAssociationProperties(properties),
@@ -2723,7 +3135,7 @@ var LiveInteraction = class {
2723
3135
  console.log(`[raindrop] startToolSpan: started tool span "${name}"`);
2724
3136
  }
2725
3137
  const startSpanCtx = span.spanContext();
2726
- const startSpanIdHex = (0, import_api3.isValidSpanId)(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
3138
+ const startSpanIdHex = (0, import_api4.isValidSpanId)(startSpanCtx.spanId) ? startSpanCtx.spanId : void 0;
2727
3139
  this.emitLiveEvent({
2728
3140
  type: "tool_start",
2729
3141
  spanId: startSpanIdHex,
@@ -2894,19 +3306,19 @@ var LiveInteraction = class {
2894
3306
  span.setAttribute("traceloop.entity.input", input);
2895
3307
  }
2896
3308
  span.setAttribute("traceloop.entity.output", output);
2897
- span.setStatus({ code: import_api3.SpanStatusCode.OK });
3309
+ span.setStatus({ code: import_api4.SpanStatusCode.OK });
2898
3310
  const spanContext = span.spanContext();
2899
3311
  span.end();
2900
3312
  this.emitLiveEvent({
2901
- spanId: (0, import_api3.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0,
3313
+ spanId: (0, import_api4.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0,
2902
3314
  type: "tool_result",
2903
3315
  content: params.name,
2904
3316
  timestamp: Date.now(),
2905
3317
  metadata: { result: params.output }
2906
3318
  });
2907
3319
  return {
2908
- traceIdHex: (0, import_api3.isValidTraceId)(spanContext.traceId) ? spanContext.traceId : void 0,
2909
- spanIdHex: (0, import_api3.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0
3320
+ traceIdHex: (0, import_api4.isValidTraceId)(spanContext.traceId) ? spanContext.traceId : void 0,
3321
+ spanIdHex: (0, import_api4.isValidSpanId)(spanContext.spanId) ? spanContext.spanId : void 0
2910
3322
  };
2911
3323
  }
2912
3324
  /**
@@ -2951,7 +3363,7 @@ var LiveInteraction = class {
2951
3363
  for (const [key, value] of Object.entries(attributes)) {
2952
3364
  span.setAttribute(key, value);
2953
3365
  }
2954
- span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message });
3366
+ span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message });
2955
3367
  span.recordException(reason instanceof Error ? reason : new Error(message));
2956
3368
  span.end();
2957
3369
  }
@@ -3078,10 +3490,10 @@ var LiveInteraction = class {
3078
3490
  }
3079
3491
  if (error) {
3080
3492
  const errorMessage = error instanceof Error ? error.message : String(error);
3081
- span.setStatus({ code: import_api3.SpanStatusCode.ERROR, message: errorMessage });
3493
+ span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message: errorMessage });
3082
3494
  span.recordException(error instanceof Error ? error : new Error(errorMessage));
3083
3495
  } else {
3084
- span.setStatus({ code: import_api3.SpanStatusCode.OK });
3496
+ span.setStatus({ code: import_api4.SpanStatusCode.OK });
3085
3497
  }
3086
3498
  span.end(endTimeMs);
3087
3499
  if ((_c = this.analytics) == null ? void 0 : _c.debugLogs) {
@@ -3093,7 +3505,7 @@ var LiveInteraction = class {
3093
3505
  });
3094
3506
  }
3095
3507
  const trackToolCtx = span.spanContext();
3096
- const trackToolSpanIdHex = (0, import_api3.isValidSpanId)(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
3508
+ const trackToolSpanIdHex = (0, import_api4.isValidSpanId)(trackToolCtx.spanId) ? trackToolCtx.spanId : void 0;
3097
3509
  this.emitLiveEvent({
3098
3510
  type: "tool_result",
3099
3511
  spanId: trackToolSpanIdHex,
@@ -3109,11 +3521,10 @@ var LiveInteraction = class {
3109
3521
  };
3110
3522
 
3111
3523
  // src/tracing/liveTracer.ts
3112
- var import_api4 = require("@opentelemetry/api");
3113
- var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
3524
+ var import_api5 = require("@opentelemetry/api");
3114
3525
  var LiveTracer = class {
3115
3526
  constructor(globalProperties, directShipper, routing) {
3116
- this.tracer = import_api4.trace.getTracer("traceloop.tracer");
3527
+ this.tracer = import_api5.trace.getTracer("traceloop.tracer");
3117
3528
  this.globalProperties = globalProperties || {};
3118
3529
  this.directShipper = directShipper;
3119
3530
  this.routing = routing;
@@ -3125,7 +3536,7 @@ var LiveTracer = class {
3125
3536
  }
3126
3537
  emitLiveEvent(event) {
3127
3538
  var _a, _b;
3128
- const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
3539
+ const activeSpan = import_api5.trace.getSpan(import_api5.context.active());
3129
3540
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
3130
3541
  const active = getActiveTraceContext();
3131
3542
  const traceId = (_b = (_a = event.traceId) != null ? _a : activeTraceId) != null ? _b : active.traceIdB64;
@@ -3145,7 +3556,7 @@ var LiveTracer = class {
3145
3556
  };
3146
3557
  const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
3147
3558
  const wrappedFn = (...fnArgs) => {
3148
- const activeSpan = import_api4.trace.getSpan(import_api4.context.active());
3559
+ const activeSpan = import_api5.trace.getSpan(import_api5.context.active());
3149
3560
  if (activeSpan) {
3150
3561
  this.stampRouting(activeSpan);
3151
3562
  }
@@ -3154,7 +3565,7 @@ var LiveTracer = class {
3154
3565
  }
3155
3566
  return fn.apply(thisArg, fnArgs);
3156
3567
  };
3157
- return traceloop3.withTask(
3568
+ return withTask(
3158
3569
  {
3159
3570
  name: taskName,
3160
3571
  associationProperties: properties,
@@ -3240,15 +3651,15 @@ var LiveTracer = class {
3240
3651
  }
3241
3652
  if (error) {
3242
3653
  const errorMessage = error instanceof Error ? error.message : String(error);
3243
- span.setStatus({ code: import_api4.SpanStatusCode.ERROR, message: errorMessage });
3654
+ span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message: errorMessage });
3244
3655
  span.recordException(error instanceof Error ? error : new Error(errorMessage));
3245
3656
  } else {
3246
- span.setStatus({ code: import_api4.SpanStatusCode.OK });
3657
+ span.setStatus({ code: import_api5.SpanStatusCode.OK });
3247
3658
  }
3248
3659
  span.end(endTimeMs);
3249
3660
  const ctx = span.spanContext();
3250
- const traceId = ctx.traceId || ((_b = import_api4.trace.getSpan(import_api4.context.active())) == null ? void 0 : _b.spanContext().traceId);
3251
- const spanIdHex = (0, import_api4.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
3661
+ const traceId = ctx.traceId || ((_b = import_api5.trace.getSpan(import_api5.context.active())) == null ? void 0 : _b.spanContext().traceId);
3662
+ const spanIdHex = (0, import_api5.isValidSpanId)(ctx.spanId) ? ctx.spanId : void 0;
3252
3663
  if (traceId) {
3253
3664
  this.emitLiveEvent({
3254
3665
  traceId,
@@ -3407,7 +3818,7 @@ function createLocalDebuggerSpanProcessor(options) {
3407
3818
  headers: {}
3408
3819
  });
3409
3820
  try {
3410
- return traceloop4.createSpanProcessor({
3821
+ return createSpanProcessor({
3411
3822
  apiKey: options.writeKey,
3412
3823
  baseUrl: localDebuggerUrl,
3413
3824
  disableBatch: options.disableBatching,
@@ -3487,7 +3898,7 @@ try {
3487
3898
  e instanceof Error ? e.message : e
3488
3899
  );
3489
3900
  span.setStatus({
3490
- code: import_api5.SpanStatusCode.ERROR,
3901
+ code: import_api6.SpanStatusCode.ERROR,
3491
3902
  message: e instanceof Error ? e.message : String(e)
3492
3903
  });
3493
3904
  span.end();
@@ -3519,7 +3930,7 @@ try {
3519
3930
  );
3520
3931
  if (!spanEnded) {
3521
3932
  span.setStatus({
3522
- code: import_api5.SpanStatusCode.ERROR,
3933
+ code: import_api6.SpanStatusCode.ERROR,
3523
3934
  message: e instanceof Error ? e.message : String(e)
3524
3935
  });
3525
3936
  span.end();
@@ -3533,7 +3944,7 @@ try {
3533
3944
  } catch (error) {
3534
3945
  if (!spanEnded) {
3535
3946
  const msg = error instanceof Error ? error.message : String(error);
3536
- span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message: msg });
3947
+ span.setStatus({ code: import_api6.SpanStatusCode.ERROR, message: msg });
3537
3948
  span.recordException(error);
3538
3949
  span.end();
3539
3950
  spanEnded = true;
@@ -3556,7 +3967,7 @@ try {
3556
3967
  return result;
3557
3968
  }).catch((error) => {
3558
3969
  span.setStatus({
3559
- code: import_api5.SpanStatusCode.ERROR,
3970
+ code: import_api6.SpanStatusCode.ERROR,
3560
3971
  message: error.message
3561
3972
  });
3562
3973
  span.recordException(error);
@@ -3619,7 +4030,7 @@ function patchBedrockStreamingBug(inst) {
3619
4030
  } catch (error) {
3620
4031
  if (!spanEnded) {
3621
4032
  const msg = error instanceof Error ? error.message : String(error);
3622
- span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message: msg });
4033
+ span.setStatus({ code: import_api6.SpanStatusCode.ERROR, message: msg });
3623
4034
  span.recordException(error);
3624
4035
  span.end();
3625
4036
  spanEnded = true;
@@ -3642,7 +4053,7 @@ function patchBedrockStreamingBug(inst) {
3642
4053
  return result;
3643
4054
  }).catch((error) => {
3644
4055
  span.setStatus({
3645
- code: import_api5.SpanStatusCode.ERROR,
4056
+ code: import_api6.SpanStatusCode.ERROR,
3646
4057
  message: error.message
3647
4058
  });
3648
4059
  span.recordException(error);
@@ -3655,7 +4066,9 @@ function createDefaultInstrumentations() {
3655
4066
  const bedrockInst = new import_instrumentation_bedrock.BedrockInstrumentation();
3656
4067
  patchBedrockStreamingBug(bedrockInst);
3657
4068
  return [
3658
- new import_instrumentation_openai.OpenAIInstrumentation(),
4069
+ new import_instrumentation_openai.OpenAIInstrumentation({
4070
+ enrichTokens: (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true"
4071
+ }),
3659
4072
  new import_instrumentation_anthropic.AnthropicInstrumentation(),
3660
4073
  new import_instrumentation_cohere.CohereInstrumentation(),
3661
4074
  bedrockInst,
@@ -3664,7 +4077,9 @@ function createDefaultInstrumentations() {
3664
4077
  new import_instrumentation_pinecone.PineconeInstrumentation(),
3665
4078
  new import_instrumentation_together.TogetherInstrumentation(),
3666
4079
  new import_instrumentation_chromadb.ChromaDBInstrumentation(),
3667
- new import_instrumentation_qdrant.QdrantInstrumentation()
4080
+ new import_instrumentation_qdrant.QdrantInstrumentation(),
4081
+ new import_instrumentation_langchain.LangChainInstrumentation(),
4082
+ new import_instrumentation_llamaindex.LlamaIndexInstrumentation()
3668
4083
  ];
3669
4084
  }
3670
4085
  function createManualInstrumentations(instrumentModules) {
@@ -3720,17 +4135,29 @@ function createManualInstrumentations(instrumentModules) {
3720
4135
  inst.manuallyInstrument(instrumentModules.qdrant);
3721
4136
  instrumentations.push(inst);
3722
4137
  }
4138
+ instrumentations.push(new import_instrumentation_langchain.LangChainInstrumentation());
4139
+ if (instrumentModules.llamaIndex) {
4140
+ const inst = new import_instrumentation_llamaindex.LlamaIndexInstrumentation();
4141
+ inst.manuallyInstrument(instrumentModules.llamaIndex);
4142
+ instrumentations.push(inst);
4143
+ }
3723
4144
  return instrumentations;
3724
4145
  }
4146
+ function createConfiguredInstrumentations(options) {
4147
+ if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
4148
+ return createManualInstrumentations(options.instrumentModules);
4149
+ }
4150
+ return createDefaultInstrumentations();
4151
+ }
3725
4152
  function getCurrentTraceId() {
3726
4153
  var _a;
3727
- return (_a = import_api5.trace.getSpan(import_api5.context.active())) == null ? void 0 : _a.spanContext().traceId;
4154
+ return (_a = import_api6.trace.getSpan(import_api6.context.active())) == null ? void 0 : _a.spanContext().traceId;
3728
4155
  }
3729
4156
  var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3730
4157
  var _a;
3731
4158
  process.env.TRACELOOP_TELEMETRY = "false";
3732
4159
  const {
3733
- logLevel,
4160
+ logLevel: logLevel2,
3734
4161
  useExternalOtel,
3735
4162
  tracingEnabled,
3736
4163
  disableBatching,
@@ -3777,10 +4204,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3777
4204
  const activeInteractionsByEventId = new import_weakref.WeakValueMap();
3778
4205
  try {
3779
4206
  if (useExternalOtel) {
3780
- traceloop4.initialize({
4207
+ initialize({
3781
4208
  baseUrl: apiUrl,
3782
4209
  apiKey: writeKey,
3783
- logLevel,
4210
+ logLevel: logLevel2,
3784
4211
  // Traceloop's init banner ("Traceloop exporting traces to <baseUrl>") is
3785
4212
  // misleading inside our wrapper: in external-OTEL mode we create no
3786
4213
  // exporter at all (tracingEnabled: false). Suppress it.
@@ -3806,28 +4233,29 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3806
4233
  const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
3807
4234
  writeKey,
3808
4235
  disableBatching,
3809
- allowedInstrumentationLibraries: traceloop4.ALL_INSTRUMENTATION_LIBRARIES,
4236
+ allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES,
3810
4237
  localDebuggerUrlOpt: localDebuggerUrl
3811
4238
  });
3812
4239
  if (!cloudEnabledResolved) {
3813
4240
  if (localDebuggerProcessor) {
3814
- traceloop4.initialize({
4241
+ initialize({
3815
4242
  baseUrl: apiUrl,
3816
4243
  apiKey: writeKey,
3817
4244
  ...otherOptions,
3818
- logLevel,
4245
+ logLevel: logLevel2,
3819
4246
  silenceInitializationMessage: true,
3820
4247
  tracingEnabled: tracingEnabled !== false,
3821
4248
  disableBatch: disableBatching,
3822
- processor: localDebuggerProcessor
4249
+ processor: localDebuggerProcessor,
4250
+ instrumentations: createConfiguredInstrumentations(otherOptions)
3823
4251
  });
3824
4252
  traceloopInitialized = true;
3825
4253
  markTraceloopConfiguredWithoutClaim();
3826
4254
  } else {
3827
- traceloop4.initialize({
4255
+ initialize({
3828
4256
  baseUrl: apiUrl,
3829
4257
  apiKey: writeKey,
3830
- logLevel,
4258
+ logLevel: logLevel2,
3831
4259
  silenceInitializationMessage: true,
3832
4260
  tracingEnabled: false
3833
4261
  });
@@ -3873,18 +4301,19 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3873
4301
  localDebuggerProcessor ? [localDebuggerProcessor] : []
3874
4302
  );
3875
4303
  try {
3876
- traceloop4.initialize({
4304
+ initialize({
3877
4305
  baseUrl: apiUrl,
3878
4306
  apiKey: writeKey,
3879
4307
  ...otherOptions,
3880
- logLevel,
4308
+ logLevel: logLevel2,
3881
4309
  silenceInitializationMessage: true,
3882
4310
  // This branch only runs when tracing is enabled (the disabled
3883
4311
  // case is handled above), so tracing is always on here.
3884
4312
  tracingEnabled: true,
3885
4313
  disableBatch: disableBatching,
3886
4314
  processor,
3887
- exporter: guardedExporter
4315
+ exporter: guardedExporter,
4316
+ instrumentations: createConfiguredInstrumentations(otherOptions)
3888
4317
  });
3889
4318
  traceloopInitialized = true;
3890
4319
  } catch (initError) {
@@ -4015,7 +4444,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4015
4444
  });
4016
4445
  return;
4017
4446
  }
4018
- const span = import_api5.trace.getTracer("traceloop.tracer").startSpan("ai.model.usage");
4447
+ const span = import_api6.trace.getTracer("traceloop.tracer").startSpan("ai.model.usage");
4019
4448
  span.setAttribute("traceloop.span.kind", "llm");
4020
4449
  span.setAttribute("traceloop.association.properties.event_id", params.eventId);
4021
4450
  stampSpan(span, projectId, authHint);
@@ -4123,7 +4552,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4123
4552
  );
4124
4553
  }
4125
4554
  const headers = withProjectIdHeaders(processorOptions == null ? void 0 : processorOptions.headers);
4126
- const productionProcessor = traceloop4.createSpanProcessor({
4555
+ const productionProcessor = createSpanProcessor({
4127
4556
  baseUrl: apiUrl,
4128
4557
  apiKey: writeKey,
4129
4558
  disableBatch: disableBatching,
@@ -4189,7 +4618,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4189
4618
  }
4190
4619
  if (traceloopInitialized) {
4191
4620
  try {
4192
- await traceloop4.forceFlush();
4621
+ await forceFlush();
4193
4622
  } catch (e) {
4194
4623
  }
4195
4624
  }
@@ -4201,7 +4630,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4201
4630
  await (directShipper == null ? void 0 : directShipper.shutdown());
4202
4631
  if (traceloopInitialized) {
4203
4632
  try {
4204
- await traceloop4.forceFlush();
4633
+ await forceFlush();
4205
4634
  } catch (e) {
4206
4635
  }
4207
4636
  }