raindrop-ai 0.3.1 → 0.4.0-otelv2

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.
@@ -1097,7 +1097,7 @@ installTracingSuppressionHook();
1097
1097
  // package.json
1098
1098
  var package_default = {
1099
1099
  name: "raindrop-ai",
1100
- version: "0.3.1",
1100
+ version: "0.4.0",
1101
1101
  main: "dist/index.js",
1102
1102
  module: "dist/index.mjs",
1103
1103
  types: "dist/index.d.ts",
@@ -1151,7 +1151,6 @@ var package_default = {
1151
1151
  "@raindrop-ai/redact-pii": "workspace:*",
1152
1152
  "@raindrop-ai/schemas": "workspace:*",
1153
1153
  ai: "^6.0.0",
1154
- "@opentelemetry/resources": "^2.0.1",
1155
1154
  "@types/node": "^20.11.17",
1156
1155
  msw: "^2.12.8",
1157
1156
  tsup: "^8.4.0",
@@ -1162,9 +1161,25 @@ var package_default = {
1162
1161
  },
1163
1162
  dependencies: {
1164
1163
  "@opentelemetry/api": "^1.9.0",
1164
+ "@opentelemetry/core": "^1.30.1",
1165
1165
  "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
1166
1166
  "@opentelemetry/exporter-trace-otlp-proto": "^0.57.2",
1167
- "@traceloop/node-server-sdk": "0.19.0-otel-v1",
1167
+ "@opentelemetry/instrumentation": "^0.57.2",
1168
+ "@opentelemetry/resources": "^1.30.1",
1169
+ "@opentelemetry/sdk-trace-base": "^1.30.1",
1170
+ "@opentelemetry/sdk-trace-node": "^1.30.1",
1171
+ "@traceloop/ai-semantic-conventions": "0.19.0-otel-v1",
1172
+ "@traceloop/instrumentation-anthropic": "0.19.0-otel-v1",
1173
+ "@traceloop/instrumentation-openai": "0.19.0-otel-v1",
1174
+ "@traceloop/instrumentation-cohere": "0.19.0-otel-v1",
1175
+ "@traceloop/instrumentation-bedrock": "0.19.0-otel-v1",
1176
+ "@traceloop/instrumentation-vertexai": "0.19.0-otel-v1",
1177
+ "@traceloop/instrumentation-pinecone": "0.19.0-otel-v1",
1178
+ "@traceloop/instrumentation-chromadb": "0.19.0-otel-v1",
1179
+ "@traceloop/instrumentation-qdrant": "0.19.0-otel-v1",
1180
+ "@traceloop/instrumentation-together": "0.19.0-otel-v1",
1181
+ "@traceloop/instrumentation-langchain": "0.19.0-otel-v1",
1182
+ "@traceloop/instrumentation-llamaindex": "0.19.0-otel-v1",
1168
1183
  weakref: "^0.2.1",
1169
1184
  zod: "^3.23.8"
1170
1185
  },
@@ -1183,7 +1198,6 @@ var package_default = {
1183
1198
  "esm"
1184
1199
  ],
1185
1200
  external: [
1186
- "@traceloop/node-server-sdk",
1187
1201
  "@traceloop/instrumentation-anthropic",
1188
1202
  "@traceloop/instrumentation-openai",
1189
1203
  "@traceloop/instrumentation-cohere",
@@ -1193,10 +1207,17 @@ var package_default = {
1193
1207
  "@traceloop/instrumentation-chromadb",
1194
1208
  "@traceloop/instrumentation-qdrant",
1195
1209
  "@traceloop/instrumentation-together",
1210
+ "@traceloop/instrumentation-langchain",
1211
+ "@traceloop/instrumentation-llamaindex",
1212
+ "@traceloop/ai-semantic-conventions",
1213
+ "@opentelemetry/api",
1214
+ "@opentelemetry/core",
1196
1215
  "@opentelemetry/instrumentation",
1197
1216
  "@opentelemetry/exporter-trace-otlp-http",
1198
1217
  "@opentelemetry/exporter-trace-otlp-proto",
1199
- "@opentelemetry/sdk-trace-base"
1218
+ "@opentelemetry/resources",
1219
+ "@opentelemetry/sdk-trace-base",
1220
+ "@opentelemetry/sdk-trace-node"
1200
1221
  ],
1201
1222
  noExternal: [
1202
1223
  "@raindrop-ai/core",
@@ -1409,13 +1430,15 @@ function traceloopConfiguredWithoutClaim() {
1409
1430
  }
1410
1431
 
1411
1432
  // src/tracing/tracer-core.ts
1412
- import { SpanStatusCode as SpanStatusCode5, context as context5, trace as trace5 } from "@opentelemetry/api";
1433
+ import { SpanStatusCode as SpanStatusCode5, context as context6, trace as trace6 } from "@opentelemetry/api";
1413
1434
  import { OTLPTraceExporter as OTLPHttpTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
1414
1435
  import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
1415
1436
  import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
1416
1437
  import { ChromaDBInstrumentation } from "@traceloop/instrumentation-chromadb";
1417
1438
  import { CohereInstrumentation } from "@traceloop/instrumentation-cohere";
1418
1439
  import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai";
1440
+ import { LangChainInstrumentation } from "@traceloop/instrumentation-langchain";
1441
+ import { LlamaIndexInstrumentation } from "@traceloop/instrumentation-llamaindex";
1419
1442
  import { PineconeInstrumentation } from "@traceloop/instrumentation-pinecone";
1420
1443
  import { QdrantInstrumentation } from "@traceloop/instrumentation-qdrant";
1421
1444
  import { TogetherInstrumentation } from "@traceloop/instrumentation-together";
@@ -1423,7 +1446,411 @@ import {
1423
1446
  AIPlatformInstrumentation,
1424
1447
  VertexAIInstrumentation
1425
1448
  } from "@traceloop/instrumentation-vertexai";
1426
- import * as traceloop4 from "@traceloop/node-server-sdk";
1449
+
1450
+ // src/tracing/otel-core/index.ts
1451
+ import {
1452
+ DiagConsoleLogger,
1453
+ DiagLogLevel,
1454
+ context,
1455
+ diag,
1456
+ trace
1457
+ } from "@opentelemetry/api";
1458
+ import { suppressTracing } from "@opentelemetry/core";
1459
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
1460
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
1461
+ import * as resourceModule from "@opentelemetry/resources";
1462
+ import {
1463
+ BatchSpanProcessor,
1464
+ SimpleSpanProcessor
1465
+ } from "@opentelemetry/sdk-trace-base";
1466
+ import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
1467
+ import {
1468
+ CONTEXT_KEY_ALLOW_TRACE_CONTENT,
1469
+ SpanAttributes,
1470
+ TraceloopSpanKindValues
1471
+ } from "@traceloop/ai-semantic-conventions";
1472
+ var ALL_INSTRUMENTATION_LIBRARIES = "all";
1473
+ var TRACER_NAME = "@traceloop/node-server-sdk";
1474
+ var WORKFLOW_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.workflowName");
1475
+ var ENTITY_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.entityName");
1476
+ var ASSOCIATION_PROPERTIES_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.associationProperties");
1477
+ var INSTRUMENTATION_LIBRARIES = [
1478
+ "ai",
1479
+ "@traceloop/node-server-sdk",
1480
+ "@traceloop/instrumentation-openai",
1481
+ "@traceloop/instrumentation-langchain",
1482
+ "@traceloop/instrumentation-chroma",
1483
+ "@traceloop/instrumentation-chromadb",
1484
+ "@traceloop/instrumentation-anthropic",
1485
+ "@traceloop/instrumentation-llamaindex",
1486
+ "@traceloop/instrumentation-vertexai",
1487
+ "@traceloop/instrumentation-bedrock",
1488
+ "@traceloop/instrumentation-cohere",
1489
+ "@traceloop/instrumentation-pinecone",
1490
+ "@traceloop/instrumentation-qdrant",
1491
+ "@traceloop/instrumentation-together",
1492
+ TRACER_NAME,
1493
+ "traceloop.tracer"
1494
+ ];
1495
+ var AI_GENERATE_TEXT = "ai.generateText.doGenerate";
1496
+ var AI_STREAM_TEXT = "ai.streamText.doStream";
1497
+ var AI_RESPONSE_TEXT = "ai.response.text";
1498
+ var AI_PROMPT_MESSAGES = "ai.prompt.messages";
1499
+ var AI_PROMPT_TOKENS = "ai.usage.promptTokens";
1500
+ var AI_COMPLETION_TOKENS = "ai.usage.completionTokens";
1501
+ var AI_MODEL_PROVIDER = "ai.model.provider";
1502
+ var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.otelCore.state");
1503
+ function getState2() {
1504
+ var _a;
1505
+ const holder = globalThis;
1506
+ (_a = holder[STATE_KEY2]) != null ? _a : holder[STATE_KEY2] = {};
1507
+ return holder[STATE_KEY2];
1508
+ }
1509
+ function parseHeaders(value) {
1510
+ const headers = {};
1511
+ if (!value) return headers;
1512
+ for (const pair of value.split(",")) {
1513
+ const separator = pair.indexOf("=");
1514
+ if (separator <= 0) continue;
1515
+ try {
1516
+ const key = decodeURIComponent(pair.slice(0, separator).trim());
1517
+ const val = decodeURIComponent(pair.slice(separator + 1).trim());
1518
+ if (key && val) headers[key] = val;
1519
+ } catch (e) {
1520
+ }
1521
+ }
1522
+ return headers;
1523
+ }
1524
+ function safeStringify(value) {
1525
+ try {
1526
+ const result = JSON.stringify(value);
1527
+ return result === void 0 ? String(value) : result;
1528
+ } catch (e) {
1529
+ return "[unserializable]";
1530
+ }
1531
+ }
1532
+ function createResource(attributes) {
1533
+ if ("resourceFromAttributes" in resourceModule) {
1534
+ const factory = resourceModule.resourceFromAttributes;
1535
+ if (typeof factory === "function") return factory(attributes);
1536
+ }
1537
+ return new resourceModule.Resource(attributes);
1538
+ }
1539
+ function detectRuntimeResource() {
1540
+ try {
1541
+ if ("detectResourcesSync" in resourceModule && typeof resourceModule.detectResourcesSync === "function" && "envDetectorSync" in resourceModule) {
1542
+ return resourceModule.detectResourcesSync({
1543
+ detectors: [
1544
+ resourceModule.envDetectorSync,
1545
+ resourceModule.processDetectorSync,
1546
+ resourceModule.hostDetectorSync
1547
+ ]
1548
+ });
1549
+ }
1550
+ if ("detectResources" in resourceModule && typeof resourceModule.detectResources === "function" && "envDetector" in resourceModule) {
1551
+ const detected = resourceModule.detectResources({
1552
+ detectors: [
1553
+ resourceModule.envDetector,
1554
+ resourceModule.processDetector,
1555
+ resourceModule.hostDetector
1556
+ ]
1557
+ });
1558
+ if (!(detected instanceof Promise)) {
1559
+ return detected;
1560
+ }
1561
+ }
1562
+ } catch (e) {
1563
+ }
1564
+ return void 0;
1565
+ }
1566
+ function logLevel(level) {
1567
+ switch (level) {
1568
+ case "debug":
1569
+ return DiagLogLevel.DEBUG;
1570
+ case "info":
1571
+ return DiagLogLevel.INFO;
1572
+ case "warn":
1573
+ return DiagLogLevel.WARN;
1574
+ default:
1575
+ return DiagLogLevel.ERROR;
1576
+ }
1577
+ }
1578
+ function transformAiSdkSpan(span) {
1579
+ const names = {
1580
+ [AI_GENERATE_TEXT]: "ai.generateText.generate",
1581
+ [AI_STREAM_TEXT]: "ai.streamText.stream"
1582
+ };
1583
+ if (!(span.name in names)) return span;
1584
+ const attributes = span.attributes;
1585
+ if (AI_RESPONSE_TEXT in attributes) {
1586
+ const response = attributes[AI_RESPONSE_TEXT];
1587
+ if (typeof response === "string") {
1588
+ attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.content`] = response;
1589
+ }
1590
+ attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.role`] = "assistant";
1591
+ delete attributes[AI_RESPONSE_TEXT];
1592
+ }
1593
+ if (AI_PROMPT_MESSAGES in attributes) {
1594
+ try {
1595
+ const parsed = JSON.parse(String(attributes[AI_PROMPT_MESSAGES]));
1596
+ if (Array.isArray(parsed)) {
1597
+ parsed.forEach((message, index) => {
1598
+ if (!message || typeof message !== "object") return;
1599
+ const content = "content" in message ? message.content : void 0;
1600
+ const role = "role" in message ? message.role : void 0;
1601
+ attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = typeof content === "string" ? content : safeStringify(content);
1602
+ if (typeof role === "string") {
1603
+ attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = role;
1604
+ }
1605
+ });
1606
+ }
1607
+ delete attributes[AI_PROMPT_MESSAGES];
1608
+ } catch (e) {
1609
+ }
1610
+ }
1611
+ if (AI_PROMPT_TOKENS in attributes) {
1612
+ attributes[SpanAttributes.LLM_USAGE_PROMPT_TOKENS] = Number(attributes[AI_PROMPT_TOKENS]);
1613
+ delete attributes[AI_PROMPT_TOKENS];
1614
+ }
1615
+ if (AI_COMPLETION_TOKENS in attributes) {
1616
+ attributes[SpanAttributes.LLM_USAGE_COMPLETION_TOKENS] = Number(attributes[AI_COMPLETION_TOKENS]);
1617
+ delete attributes[AI_COMPLETION_TOKENS];
1618
+ }
1619
+ const prompt = attributes[SpanAttributes.LLM_USAGE_PROMPT_TOKENS];
1620
+ const completion = attributes[SpanAttributes.LLM_USAGE_COMPLETION_TOKENS];
1621
+ if (prompt !== void 0 && completion !== void 0) {
1622
+ attributes[SpanAttributes.LLM_USAGE_TOTAL_TOKENS] = Number(prompt) + Number(completion);
1623
+ }
1624
+ if (AI_MODEL_PROVIDER in attributes) {
1625
+ const vendor = String(attributes[AI_MODEL_PROVIDER]);
1626
+ attributes[SpanAttributes.LLM_SYSTEM] = vendor.startsWith("openai") ? "OpenAI" : vendor;
1627
+ delete attributes[AI_MODEL_PROVIDER];
1628
+ }
1629
+ Object.defineProperty(span, "name", {
1630
+ configurable: true,
1631
+ value: names[span.name],
1632
+ writable: true
1633
+ });
1634
+ return span;
1635
+ }
1636
+ function scopeName(span) {
1637
+ var _a;
1638
+ if ("instrumentationScope" in span) {
1639
+ const scope = span.instrumentationScope;
1640
+ if (scope && typeof scope === "object" && "name" in scope && typeof scope.name === "string") {
1641
+ return scope.name;
1642
+ }
1643
+ }
1644
+ return (_a = span.instrumentationLibrary) == null ? void 0 : _a.name;
1645
+ }
1646
+ function contentCaptureDisabled(options) {
1647
+ return options.traceContent === false || (process.env.TRACELOOP_TRACE_CONTENT || "true").toLowerCase() === "false";
1648
+ }
1649
+ function shouldSendTraceContent() {
1650
+ var _a;
1651
+ const contextual = context.active().getValue(CONTEXT_KEY_ALLOW_TRACE_CONTENT);
1652
+ if (typeof contextual === "boolean") return contextual;
1653
+ if (((_a = getState2().configuration) == null ? void 0 : _a.traceContent) === false) return false;
1654
+ return (process.env.TRACELOOP_TRACE_CONTENT || "true").toLowerCase() !== "false";
1655
+ }
1656
+ function enrichStart(span) {
1657
+ const active = context.active();
1658
+ const workflow = active.getValue(WORKFLOW_NAME_KEY);
1659
+ if (typeof workflow === "string") span.setAttribute(SpanAttributes.TRACELOOP_WORKFLOW_NAME, workflow);
1660
+ const entity = active.getValue(ENTITY_NAME_KEY);
1661
+ if (typeof entity === "string") span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_PATH, entity);
1662
+ const properties = active.getValue(ASSOCIATION_PROPERTIES_KEY);
1663
+ if (properties && typeof properties === "object") {
1664
+ for (const [key, value] of Object.entries(properties)) {
1665
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1666
+ span.setAttribute(`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.${key}`, value);
1667
+ }
1668
+ }
1669
+ }
1670
+ }
1671
+ function createSpanProcessor(options) {
1672
+ var _a, _b;
1673
+ const baseUrl = options.baseUrl || process.env.TRACELOOP_BASE_URL || "https://api.traceloop.com";
1674
+ const apiKey = options.apiKey || process.env.TRACELOOP_API_KEY;
1675
+ const resolvedHeaders = (_a = options.headers) != null ? _a : process.env.TRACELOOP_HEADERS ? parseHeaders(process.env.TRACELOOP_HEADERS) : { Authorization: `Bearer ${apiKey}` };
1676
+ const exporter = (_b = options.exporter) != null ? _b : new OTLPTraceExporter({ url: `${baseUrl}/v1/traces`, headers: resolvedHeaders });
1677
+ const processor = options.disableBatch ? new SimpleSpanProcessor(exporter) : new BatchSpanProcessor(exporter);
1678
+ const originalOnStart = processor.onStart.bind(processor);
1679
+ const originalOnEnd = processor.onEnd.bind(processor);
1680
+ processor.onStart = (span, parentContext) => {
1681
+ try {
1682
+ enrichStart(span);
1683
+ originalOnStart(span, parentContext);
1684
+ } catch (e) {
1685
+ }
1686
+ };
1687
+ processor.onEnd = (span) => {
1688
+ var _a2;
1689
+ let outgoing = span;
1690
+ try {
1691
+ const allowed = options.allowedInstrumentationLibraries;
1692
+ if (allowed !== ALL_INSTRUMENTATION_LIBRARIES && ![...INSTRUMENTATION_LIBRARIES, ...allowed != null ? allowed : []].includes((_a2 = scopeName(span)) != null ? _a2 : "")) {
1693
+ return;
1694
+ }
1695
+ outgoing = transformAiSdkSpan(span);
1696
+ } catch (e) {
1697
+ }
1698
+ try {
1699
+ originalOnEnd(outgoing);
1700
+ } catch (e) {
1701
+ }
1702
+ };
1703
+ return processor;
1704
+ }
1705
+ function initialize(options = {}) {
1706
+ var _a;
1707
+ const state = getState2();
1708
+ if (state.configuration) return;
1709
+ state.configuration = Object.freeze({ ...options });
1710
+ if (options.logLevel) diag.setLogger(new DiagConsoleLogger(), logLevel(options.logLevel));
1711
+ if (options.tracingEnabled === false) return;
1712
+ const baseUrl = options.baseUrl || process.env.TRACELOOP_BASE_URL || "https://api.traceloop.com";
1713
+ state.defaultProcessor = createSpanProcessor({
1714
+ ...options,
1715
+ baseUrl,
1716
+ allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES
1717
+ });
1718
+ const serviceResource = createResource({
1719
+ "service.name": options.appName || process.env.npm_package_name || "unknown_service"
1720
+ });
1721
+ const detectedResource = detectRuntimeResource();
1722
+ state.provider = new NodeTracerProvider({
1723
+ // Detected attributes win over the configured resource, matching
1724
+ // sdk-node's `this._resource.merge(detectResourcesSync(...))` so
1725
+ // OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES can still override appName.
1726
+ resource: detectedResource ? serviceResource.merge(detectedResource) : serviceResource,
1727
+ spanProcessors: [state.defaultProcessor, ...options.processor ? [options.processor] : []]
1728
+ });
1729
+ state.provider.register({
1730
+ contextManager: options.contextManager,
1731
+ propagator: options.propagator
1732
+ });
1733
+ const instrumentations = (_a = options.instrumentations) != null ? _a : [];
1734
+ if (contentCaptureDisabled(options)) {
1735
+ for (const instrumentation of instrumentations) {
1736
+ try {
1737
+ const config = {
1738
+ ...instrumentation.getConfig(),
1739
+ traceContent: false
1740
+ };
1741
+ instrumentation.setConfig(config);
1742
+ } catch (e) {
1743
+ }
1744
+ }
1745
+ }
1746
+ registerInstrumentations({ instrumentations });
1747
+ }
1748
+ async function forceFlush() {
1749
+ var _a, _b;
1750
+ const state = getState2();
1751
+ try {
1752
+ await ((_a = state.provider) == null ? void 0 : _a.forceFlush());
1753
+ await ((_b = state.defaultProcessor) == null ? void 0 : _b.forceFlush());
1754
+ } catch (e) {
1755
+ }
1756
+ }
1757
+ function withEntity(type, config, fn, args) {
1758
+ let entityContext = context.active();
1759
+ if (type === TraceloopSpanKindValues.WORKFLOW) {
1760
+ entityContext = entityContext.setValue(WORKFLOW_NAME_KEY, config.name);
1761
+ }
1762
+ const parentPath = entityContext.getValue(ENTITY_NAME_KEY);
1763
+ if (type === TraceloopSpanKindValues.TASK || type === TraceloopSpanKindValues.TOOL) {
1764
+ entityContext = entityContext.setValue(
1765
+ ENTITY_NAME_KEY,
1766
+ `${typeof parentPath === "string" ? `${parentPath}.` : ""}${config.name}`
1767
+ );
1768
+ }
1769
+ if (config.traceContent !== void 0) {
1770
+ entityContext = entityContext.setValue(CONTEXT_KEY_ALLOW_TRACE_CONTENT, config.traceContent);
1771
+ }
1772
+ if (config.associationProperties) {
1773
+ entityContext = entityContext.setValue(ASSOCIATION_PROPERTIES_KEY, config.associationProperties);
1774
+ }
1775
+ if (config.suppressTracing) {
1776
+ entityContext = suppressTracing(entityContext);
1777
+ }
1778
+ let callbackStarted = false;
1779
+ const run = (span) => {
1780
+ var _a;
1781
+ try {
1782
+ span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_NAME, config.name);
1783
+ span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_PATH, typeof parentPath === "string" ? parentPath : "");
1784
+ span.setAttribute(SpanAttributes.TRACELOOP_SPAN_KIND, type);
1785
+ if (type === TraceloopSpanKindValues.WORKFLOW) {
1786
+ span.setAttribute(SpanAttributes.TRACELOOP_WORKFLOW_NAME, config.name);
1787
+ }
1788
+ if (config.version !== void 0) span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_VERSION, config.version);
1789
+ const input = (_a = config.inputParameters) != null ? _a : args;
1790
+ if (shouldSendTraceContent()) {
1791
+ span.setAttribute(
1792
+ SpanAttributes.TRACELOOP_ENTITY_INPUT,
1793
+ safeStringify(input.length === 1 && input[0] !== null && typeof input[0] === "object" && !(input[0] instanceof Map) ? { args: [], kwargs: input[0] } : { args: input, kwargs: {} })
1794
+ );
1795
+ }
1796
+ } catch (e) {
1797
+ }
1798
+ let result;
1799
+ try {
1800
+ callbackStarted = true;
1801
+ result = fn(...args);
1802
+ } catch (error) {
1803
+ try {
1804
+ span.end();
1805
+ } catch (e) {
1806
+ }
1807
+ throw error;
1808
+ }
1809
+ if (result instanceof Promise) {
1810
+ return result.then(
1811
+ (value) => {
1812
+ try {
1813
+ if (shouldSendTraceContent()) span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, safeStringify(value));
1814
+ span.end();
1815
+ } catch (e) {
1816
+ }
1817
+ return value;
1818
+ },
1819
+ (error) => {
1820
+ try {
1821
+ span.end();
1822
+ } catch (e) {
1823
+ }
1824
+ throw error;
1825
+ }
1826
+ );
1827
+ }
1828
+ try {
1829
+ if (shouldSendTraceContent()) span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, safeStringify(result));
1830
+ span.end();
1831
+ } catch (e) {
1832
+ }
1833
+ return result;
1834
+ };
1835
+ try {
1836
+ const tracer = trace.getTracer(TRACER_NAME);
1837
+ return context.with(
1838
+ entityContext,
1839
+ () => tracer.startActiveSpan(`${config.name}.${type}`, {}, entityContext, run)
1840
+ );
1841
+ } catch (error) {
1842
+ if (callbackStarted) throw error;
1843
+ return fn(...args);
1844
+ }
1845
+ }
1846
+ function withTask(config, fn, ...args) {
1847
+ return withEntity(TraceloopSpanKindValues.TASK, config, fn, args);
1848
+ }
1849
+ function withTool(config, fn, ...args) {
1850
+ return withEntity(TraceloopSpanKindValues.TOOL, config, fn, args);
1851
+ }
1852
+
1853
+ // src/tracing/tracer-core.ts
1427
1854
  import { WeakValueMap } from "weakref";
1428
1855
 
1429
1856
  // src/tracing/direct/http.ts
@@ -1624,7 +2051,7 @@ function buildExportTraceServiceRequest2(spans) {
1624
2051
  }
1625
2052
 
1626
2053
  // src/tracing/direct/context.ts
1627
- import { context, isValidSpanId, isValidTraceId, trace } from "@opentelemetry/api";
2054
+ import { context as context2, isValidSpanId, isValidTraceId, trace as trace2 } from "@opentelemetry/api";
1628
2055
  var INVALID_TRACE_ID = "00000000000000000000000000000000";
1629
2056
  var INVALID_SPAN_ID = "0000000000000000";
1630
2057
  function hexToBase64(hex) {
@@ -1644,7 +2071,7 @@ function getExplicitTraceContext(traceId, parentSpanId) {
1644
2071
  };
1645
2072
  }
1646
2073
  function getActiveTraceContext() {
1647
- const activeSpan = trace.getSpan(context.active());
2074
+ const activeSpan = trace2.getSpan(context2.active());
1648
2075
  if (!activeSpan) return {};
1649
2076
  const spanContext = activeSpan.spanContext();
1650
2077
  const traceIdHex = spanContext.traceId;
@@ -1890,18 +2317,17 @@ var DirectTraceShipper = class {
1890
2317
  };
1891
2318
 
1892
2319
  // src/tracing/exit-flush.ts
1893
- import * as traceloop from "@traceloop/node-server-sdk";
1894
- var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
1895
- function getState2() {
2320
+ var STATE_KEY3 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
2321
+ function getState3() {
1896
2322
  const holder = globalThis;
1897
- let state = holder[STATE_KEY2];
2323
+ let state = holder[STATE_KEY3];
1898
2324
  if (!state) {
1899
2325
  state = {
1900
2326
  clientFlushers: /* @__PURE__ */ new Set(),
1901
2327
  pipelineFlushNeeded: false,
1902
2328
  handlerRegistered: false
1903
2329
  };
1904
- holder[STATE_KEY2] = state;
2330
+ holder[STATE_KEY3] = state;
1905
2331
  }
1906
2332
  return state;
1907
2333
  }
@@ -1914,7 +2340,7 @@ function ensureExitHandler(state) {
1914
2340
  });
1915
2341
  }
1916
2342
  function registerClientFlusher(flush) {
1917
- const state = getState2();
2343
+ const state = getState3();
1918
2344
  state.clientFlushers.add(flush);
1919
2345
  ensureExitHandler(state);
1920
2346
  return () => {
@@ -1922,12 +2348,12 @@ function registerClientFlusher(flush) {
1922
2348
  };
1923
2349
  }
1924
2350
  function markPipelineForExitFlush() {
1925
- const state = getState2();
2351
+ const state = getState3();
1926
2352
  state.pipelineFlushNeeded = true;
1927
2353
  ensureExitHandler(state);
1928
2354
  }
1929
2355
  async function flushAll() {
1930
- const state = getState2();
2356
+ const state = getState3();
1931
2357
  const tasks = [];
1932
2358
  for (const flush of state.clientFlushers) {
1933
2359
  tasks.push(Promise.resolve().then(flush).catch(() => {
@@ -1935,7 +2361,7 @@ async function flushAll() {
1935
2361
  }
1936
2362
  if (state.pipelineFlushNeeded) {
1937
2363
  tasks.push(
1938
- Promise.resolve().then(() => traceloop.forceFlush()).catch(() => {
2364
+ Promise.resolve().then(() => forceFlush()).catch(() => {
1939
2365
  })
1940
2366
  );
1941
2367
  }
@@ -1946,15 +2372,14 @@ async function flushAll() {
1946
2372
  import {
1947
2373
  SpanStatusCode as SpanStatusCode3,
1948
2374
  TraceFlags,
1949
- context as context3,
2375
+ context as context4,
1950
2376
  isValidSpanId as isValidSpanId2,
1951
2377
  isValidTraceId as isValidTraceId2,
1952
- trace as trace3
2378
+ trace as trace4
1953
2379
  } from "@opentelemetry/api";
1954
- import * as traceloop2 from "@traceloop/node-server-sdk";
1955
2380
 
1956
2381
  // src/tracing/subagents.ts
1957
- import { SpanStatusCode as SpanStatusCode2, context as context2, trace as trace2 } from "@opentelemetry/api";
2382
+ import { SpanStatusCode as SpanStatusCode2, context as context3, trace as trace3 } from "@opentelemetry/api";
1958
2383
  var DEFAULT_SUBAGENT_NAME = "subagent";
1959
2384
  var DISPATCH_ACCEPTED = "accepted";
1960
2385
  function reasonText(reason) {
@@ -1970,7 +2395,7 @@ function reasonText(reason) {
1970
2395
  }
1971
2396
  function stampCurrentSpan(attributes) {
1972
2397
  try {
1973
- const span = trace2.getSpan(context2.active());
2398
+ const span = trace3.getSpan(context3.active());
1974
2399
  if (!(span == null ? void 0 : span.isRecording())) return;
1975
2400
  for (const [key, value] of Object.entries(attributes)) {
1976
2401
  span.setAttribute(key, value);
@@ -1981,7 +2406,7 @@ function stampCurrentSpan(attributes) {
1981
2406
  function stampOwnSpan(attributes, frame) {
1982
2407
  if (!frame) return;
1983
2408
  try {
1984
- const span = trace2.getSpan(context2.active());
2409
+ const span = trace3.getSpan(context3.active());
1985
2410
  if (!(span == null ? void 0 : span.isRecording()) || !frame.ownsSpan(span)) return;
1986
2411
  for (const [key, value] of Object.entries(attributes)) {
1987
2412
  span.setAttribute(key, value);
@@ -1991,7 +2416,7 @@ function stampOwnSpan(attributes, frame) {
1991
2416
  }
1992
2417
  function failOwnSpan(reason, frame) {
1993
2418
  try {
1994
- const span = trace2.getSpan(context2.active());
2419
+ const span = trace3.getSpan(context3.active());
1995
2420
  if (!(span == null ? void 0 : span.isRecording())) return false;
1996
2421
  if (!(frame == null ? void 0 : frame.ownsSpan(span))) return false;
1997
2422
  const message = reasonText(reason);
@@ -2239,16 +2664,16 @@ var LiveSubagentRun = class {
2239
2664
  };
2240
2665
 
2241
2666
  // src/tracing/liveInteraction.ts
2242
- function getPropertiesFromContext(context6) {
2667
+ function getPropertiesFromContext(context7) {
2243
2668
  const properties = {
2244
- ...context6.userId && { user_id: context6.userId },
2245
- ...context6.convoId && { convo_id: context6.convoId },
2246
- ...context6.eventId && { event_id: context6.eventId },
2247
- ...context6.event && { event_name: context6.event },
2248
- ...context6.properties || {}
2669
+ ...context7.userId && { user_id: context7.userId },
2670
+ ...context7.convoId && { convo_id: context7.convoId },
2671
+ ...context7.eventId && { event_id: context7.eventId },
2672
+ ...context7.event && { event_name: context7.event },
2673
+ ...context7.properties || {}
2249
2674
  };
2250
- if (context6.attachments && context6.attachments.length > 0) {
2251
- properties.attachments = stringifyBounded(context6.attachments);
2675
+ if (context7.attachments && context7.attachments.length > 0) {
2676
+ properties.attachments = stringifyBounded(context7.attachments);
2252
2677
  }
2253
2678
  return properties;
2254
2679
  }
@@ -2268,12 +2693,12 @@ function serializeAssociationProperties(properties) {
2268
2693
  function serializeSpanValue(value) {
2269
2694
  return stringifyBounded(value);
2270
2695
  }
2271
- function getLocalDebuggerMetadata(context6) {
2696
+ function getLocalDebuggerMetadata(context7) {
2272
2697
  return {
2273
- ...context6.eventId ? { eventId: context6.eventId } : {},
2274
- ...context6.event ? { eventName: context6.event } : {},
2275
- ...context6.userId ? { userId: context6.userId } : {},
2276
- ...context6.convoId ? { convoId: context6.convoId } : {}
2698
+ ...context7.eventId ? { eventId: context7.eventId } : {},
2699
+ ...context7.event ? { eventName: context7.event } : {},
2700
+ ...context7.userId ? { userId: context7.userId } : {},
2701
+ ...context7.convoId ? { convoId: context7.convoId } : {}
2277
2702
  };
2278
2703
  }
2279
2704
  var LiveToolSpan = class {
@@ -2374,11 +2799,11 @@ var DirectToolSpan = class {
2374
2799
  }
2375
2800
  };
2376
2801
  var LiveInteraction = class {
2377
- constructor(context6, traceId, analytics, directShipper, routing) {
2802
+ constructor(context7, traceId, analytics, directShipper, routing) {
2378
2803
  this.usageEmitted = false;
2379
- this.context = context6;
2804
+ this.context = context7;
2380
2805
  this.analytics = analytics;
2381
- this.tracer = trace3.getTracer("traceloop.tracer");
2806
+ this.tracer = trace4.getTracer("traceloop.tracer");
2382
2807
  this.traceId = traceId;
2383
2808
  this.directShipper = directShipper;
2384
2809
  this.routing = routing;
@@ -2413,7 +2838,7 @@ var LiveInteraction = class {
2413
2838
  this.traceId = explicitTraceId;
2414
2839
  return explicitTraceId;
2415
2840
  }
2416
- const activeSpan = trace3.getSpan(context3.active());
2841
+ const activeSpan = trace4.getSpan(context4.active());
2417
2842
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
2418
2843
  if (activeTraceId) {
2419
2844
  this.traceId = activeTraceId;
@@ -2460,10 +2885,10 @@ var LiveInteraction = class {
2460
2885
  spanId: base64ToHex2(spanIdB64),
2461
2886
  traceFlags: TraceFlags.SAMPLED
2462
2887
  };
2463
- const wrappedContext = trace3.setSpan(context3.active(), trace3.wrapSpanContext(spanContext));
2888
+ const wrappedContext = trace4.setSpan(context4.active(), trace4.wrapSpanContext(spanContext));
2464
2889
  const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
2465
2890
  try {
2466
- const result = await context3.with(wrappedContext, invoke);
2891
+ const result = await context4.with(wrappedContext, invoke);
2467
2892
  const endTimeMs = Date.now();
2468
2893
  this.directShipper.sendSpan({
2469
2894
  name: taskName,
@@ -2498,7 +2923,7 @@ var LiveInteraction = class {
2498
2923
  }
2499
2924
  }
2500
2925
  const wrappedFn = (...fnArgs) => {
2501
- const activeSpan = trace3.getSpan(context3.active());
2926
+ const activeSpan = trace4.getSpan(context4.active());
2502
2927
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
2503
2928
  if (activeTraceId) {
2504
2929
  this.traceId = activeTraceId;
@@ -2511,7 +2936,7 @@ var LiveInteraction = class {
2511
2936
  }
2512
2937
  return fn.apply(thisArg, fnArgs);
2513
2938
  };
2514
- return traceloop2.withTask(
2939
+ return withTask(
2515
2940
  {
2516
2941
  name: taskName,
2517
2942
  associationProperties: serializeAssociationProperties(properties),
@@ -2552,12 +2977,12 @@ var LiveInteraction = class {
2552
2977
  spanId: base64ToHex2(spanIdB64),
2553
2978
  traceFlags: TraceFlags.SAMPLED
2554
2979
  };
2555
- const wrappedContext = trace3.setSpan(context3.active(), trace3.wrapSpanContext(spanContext));
2980
+ const wrappedContext = trace4.setSpan(context4.active(), trace4.wrapSpanContext(spanContext));
2556
2981
  const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
2557
2982
  let result;
2558
2983
  let error;
2559
2984
  try {
2560
- result = await context3.with(wrappedContext, invoke);
2985
+ result = await context4.with(wrappedContext, invoke);
2561
2986
  } catch (err) {
2562
2987
  error = err instanceof Error ? err.message : String(err);
2563
2988
  const endTimeMs2 = Date.now();
@@ -2622,7 +3047,7 @@ var LiveInteraction = class {
2622
3047
  const inputParams = params.inputParameters ? [params.inputParameters] : void 0;
2623
3048
  const emitLive = (event) => this.emitLiveEvent(event);
2624
3049
  const wrapped = async (...wrappedArgs) => {
2625
- const activeSpan = trace3.getSpan(context3.active());
3050
+ const activeSpan = trace4.getSpan(context4.active());
2626
3051
  const ctx = activeSpan == null ? void 0 : activeSpan.spanContext();
2627
3052
  const liveSpanId = ctx && isValidSpanId2(ctx.spanId) ? ctx.spanId : void 0;
2628
3053
  if (activeSpan) {
@@ -2662,7 +3087,7 @@ var LiveInteraction = class {
2662
3087
  throw error;
2663
3088
  }
2664
3089
  };
2665
- return traceloop2.withTool(
3090
+ return withTool(
2666
3091
  {
2667
3092
  name: toolName,
2668
3093
  associationProperties: serializeAssociationProperties(properties),
@@ -3118,11 +3543,10 @@ var LiveInteraction = class {
3118
3543
  };
3119
3544
 
3120
3545
  // src/tracing/liveTracer.ts
3121
- import { context as context4, isValidSpanId as isValidSpanId3, SpanStatusCode as SpanStatusCode4, trace as trace4 } from "@opentelemetry/api";
3122
- import * as traceloop3 from "@traceloop/node-server-sdk";
3546
+ import { context as context5, isValidSpanId as isValidSpanId3, SpanStatusCode as SpanStatusCode4, trace as trace5 } from "@opentelemetry/api";
3123
3547
  var LiveTracer = class {
3124
3548
  constructor(globalProperties, directShipper, routing) {
3125
- this.tracer = trace4.getTracer("traceloop.tracer");
3549
+ this.tracer = trace5.getTracer("traceloop.tracer");
3126
3550
  this.globalProperties = globalProperties || {};
3127
3551
  this.directShipper = directShipper;
3128
3552
  this.routing = routing;
@@ -3134,7 +3558,7 @@ var LiveTracer = class {
3134
3558
  }
3135
3559
  emitLiveEvent(event) {
3136
3560
  var _a, _b;
3137
- const activeSpan = trace4.getSpan(context4.active());
3561
+ const activeSpan = trace5.getSpan(context5.active());
3138
3562
  const activeTraceId = activeSpan == null ? void 0 : activeSpan.spanContext().traceId;
3139
3563
  const active = getActiveTraceContext();
3140
3564
  const traceId = (_b = (_a = event.traceId) != null ? _a : activeTraceId) != null ? _b : active.traceIdB64;
@@ -3154,7 +3578,7 @@ var LiveTracer = class {
3154
3578
  };
3155
3579
  const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
3156
3580
  const wrappedFn = (...fnArgs) => {
3157
- const activeSpan = trace4.getSpan(context4.active());
3581
+ const activeSpan = trace5.getSpan(context5.active());
3158
3582
  if (activeSpan) {
3159
3583
  this.stampRouting(activeSpan);
3160
3584
  }
@@ -3163,7 +3587,7 @@ var LiveTracer = class {
3163
3587
  }
3164
3588
  return fn.apply(thisArg, fnArgs);
3165
3589
  };
3166
- return traceloop3.withTask(
3590
+ return withTask(
3167
3591
  {
3168
3592
  name: taskName,
3169
3593
  associationProperties: properties,
@@ -3256,7 +3680,7 @@ var LiveTracer = class {
3256
3680
  }
3257
3681
  span.end(endTimeMs);
3258
3682
  const ctx = span.spanContext();
3259
- const traceId = ctx.traceId || ((_b = trace4.getSpan(context4.active())) == null ? void 0 : _b.spanContext().traceId);
3683
+ const traceId = ctx.traceId || ((_b = trace5.getSpan(context5.active())) == null ? void 0 : _b.spanContext().traceId);
3260
3684
  const spanIdHex = isValidSpanId3(ctx.spanId) ? ctx.spanId : void 0;
3261
3685
  if (traceId) {
3262
3686
  this.emitLiveEvent({
@@ -3416,7 +3840,7 @@ function createLocalDebuggerSpanProcessor(options) {
3416
3840
  headers: {}
3417
3841
  });
3418
3842
  try {
3419
- return traceloop4.createSpanProcessor({
3843
+ return createSpanProcessor({
3420
3844
  apiKey: options.writeKey,
3421
3845
  baseUrl: localDebuggerUrl,
3422
3846
  disableBatch: options.disableBatching,
@@ -3664,7 +4088,9 @@ function createDefaultInstrumentations() {
3664
4088
  const bedrockInst = new BedrockInstrumentation();
3665
4089
  patchBedrockStreamingBug(bedrockInst);
3666
4090
  return [
3667
- new OpenAIInstrumentation(),
4091
+ new OpenAIInstrumentation({
4092
+ enrichTokens: (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true"
4093
+ }),
3668
4094
  new AnthropicInstrumentation(),
3669
4095
  new CohereInstrumentation(),
3670
4096
  bedrockInst,
@@ -3673,7 +4099,9 @@ function createDefaultInstrumentations() {
3673
4099
  new PineconeInstrumentation(),
3674
4100
  new TogetherInstrumentation(),
3675
4101
  new ChromaDBInstrumentation(),
3676
- new QdrantInstrumentation()
4102
+ new QdrantInstrumentation(),
4103
+ new LangChainInstrumentation(),
4104
+ new LlamaIndexInstrumentation()
3677
4105
  ];
3678
4106
  }
3679
4107
  function createManualInstrumentations(instrumentModules) {
@@ -3729,17 +4157,29 @@ function createManualInstrumentations(instrumentModules) {
3729
4157
  inst.manuallyInstrument(instrumentModules.qdrant);
3730
4158
  instrumentations.push(inst);
3731
4159
  }
4160
+ instrumentations.push(new LangChainInstrumentation());
4161
+ if (instrumentModules.llamaIndex) {
4162
+ const inst = new LlamaIndexInstrumentation();
4163
+ inst.manuallyInstrument(instrumentModules.llamaIndex);
4164
+ instrumentations.push(inst);
4165
+ }
3732
4166
  return instrumentations;
3733
4167
  }
4168
+ function createConfiguredInstrumentations(options) {
4169
+ if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
4170
+ return createManualInstrumentations(options.instrumentModules);
4171
+ }
4172
+ return createDefaultInstrumentations();
4173
+ }
3734
4174
  function getCurrentTraceId() {
3735
4175
  var _a;
3736
- return (_a = trace5.getSpan(context5.active())) == null ? void 0 : _a.spanContext().traceId;
4176
+ return (_a = trace6.getSpan(context6.active())) == null ? void 0 : _a.spanContext().traceId;
3737
4177
  }
3738
4178
  var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3739
4179
  var _a;
3740
4180
  process.env.TRACELOOP_TELEMETRY = "false";
3741
4181
  const {
3742
- logLevel,
4182
+ logLevel: logLevel2,
3743
4183
  useExternalOtel,
3744
4184
  tracingEnabled,
3745
4185
  disableBatching,
@@ -3786,10 +4226,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3786
4226
  const activeInteractionsByEventId = new WeakValueMap();
3787
4227
  try {
3788
4228
  if (useExternalOtel) {
3789
- traceloop4.initialize({
4229
+ initialize({
3790
4230
  baseUrl: apiUrl,
3791
4231
  apiKey: writeKey,
3792
- logLevel,
4232
+ logLevel: logLevel2,
3793
4233
  // Traceloop's init banner ("Traceloop exporting traces to <baseUrl>") is
3794
4234
  // misleading inside our wrapper: in external-OTEL mode we create no
3795
4235
  // exporter at all (tracingEnabled: false). Suppress it.
@@ -3815,28 +4255,29 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3815
4255
  const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
3816
4256
  writeKey,
3817
4257
  disableBatching,
3818
- allowedInstrumentationLibraries: traceloop4.ALL_INSTRUMENTATION_LIBRARIES,
4258
+ allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES,
3819
4259
  localDebuggerUrlOpt: localDebuggerUrl
3820
4260
  });
3821
4261
  if (!cloudEnabledResolved) {
3822
4262
  if (localDebuggerProcessor) {
3823
- traceloop4.initialize({
4263
+ initialize({
3824
4264
  baseUrl: apiUrl,
3825
4265
  apiKey: writeKey,
3826
4266
  ...otherOptions,
3827
- logLevel,
4267
+ logLevel: logLevel2,
3828
4268
  silenceInitializationMessage: true,
3829
4269
  tracingEnabled: tracingEnabled !== false,
3830
4270
  disableBatch: disableBatching,
3831
- processor: localDebuggerProcessor
4271
+ processor: localDebuggerProcessor,
4272
+ instrumentations: createConfiguredInstrumentations(otherOptions)
3832
4273
  });
3833
4274
  traceloopInitialized = true;
3834
4275
  markTraceloopConfiguredWithoutClaim();
3835
4276
  } else {
3836
- traceloop4.initialize({
4277
+ initialize({
3837
4278
  baseUrl: apiUrl,
3838
4279
  apiKey: writeKey,
3839
- logLevel,
4280
+ logLevel: logLevel2,
3840
4281
  silenceInitializationMessage: true,
3841
4282
  tracingEnabled: false
3842
4283
  });
@@ -3882,18 +4323,19 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
3882
4323
  localDebuggerProcessor ? [localDebuggerProcessor] : []
3883
4324
  );
3884
4325
  try {
3885
- traceloop4.initialize({
4326
+ initialize({
3886
4327
  baseUrl: apiUrl,
3887
4328
  apiKey: writeKey,
3888
4329
  ...otherOptions,
3889
- logLevel,
4330
+ logLevel: logLevel2,
3890
4331
  silenceInitializationMessage: true,
3891
4332
  // This branch only runs when tracing is enabled (the disabled
3892
4333
  // case is handled above), so tracing is always on here.
3893
4334
  tracingEnabled: true,
3894
4335
  disableBatch: disableBatching,
3895
4336
  processor,
3896
- exporter: guardedExporter
4337
+ exporter: guardedExporter,
4338
+ instrumentations: createConfiguredInstrumentations(otherOptions)
3897
4339
  });
3898
4340
  traceloopInitialized = true;
3899
4341
  } catch (initError) {
@@ -4024,7 +4466,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4024
4466
  });
4025
4467
  return;
4026
4468
  }
4027
- const span = trace5.getTracer("traceloop.tracer").startSpan("ai.model.usage");
4469
+ const span = trace6.getTracer("traceloop.tracer").startSpan("ai.model.usage");
4028
4470
  span.setAttribute("traceloop.span.kind", "llm");
4029
4471
  span.setAttribute("traceloop.association.properties.event_id", params.eventId);
4030
4472
  stampSpan(span, projectId, authHint);
@@ -4132,7 +4574,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4132
4574
  );
4133
4575
  }
4134
4576
  const headers = withProjectIdHeaders(processorOptions == null ? void 0 : processorOptions.headers);
4135
- const productionProcessor = traceloop4.createSpanProcessor({
4577
+ const productionProcessor = createSpanProcessor({
4136
4578
  baseUrl: apiUrl,
4137
4579
  apiKey: writeKey,
4138
4580
  disableBatch: disableBatching,
@@ -4198,7 +4640,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4198
4640
  }
4199
4641
  if (traceloopInitialized) {
4200
4642
  try {
4201
- await traceloop4.forceFlush();
4643
+ await forceFlush();
4202
4644
  } catch (e) {
4203
4645
  }
4204
4646
  }
@@ -4210,7 +4652,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
4210
4652
  await (directShipper == null ? void 0 : directShipper.shutdown());
4211
4653
  if (traceloopInitialized) {
4212
4654
  try {
4213
- await traceloop4.forceFlush();
4655
+ await forceFlush();
4214
4656
  } catch (e) {
4215
4657
  }
4216
4658
  }