raindrop-ai 0.0.90 → 0.0.91-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.
@@ -163,7 +163,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
163
163
  // package.json
164
164
  var package_default = {
165
165
  name: "raindrop-ai",
166
- version: "0.0.90",
166
+ version: "0.0.91",
167
167
  main: "dist/index.js",
168
168
  module: "dist/index.mjs",
169
169
  types: "dist/index.d.ts",
@@ -213,13 +213,16 @@ var package_default = {
213
213
  "smoke:self-diagnostics:ai-sdk:all": "pnpm smoke:self-diagnostics:v4 && pnpm smoke:self-diagnostics:v5 && pnpm smoke:self-diagnostics:v6",
214
214
  "smoke:self-diagnostics:openai-sdk": "pnpm build && cd tests/openai && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
215
215
  "smoke:self-diagnostics:anthropic-sdk": "pnpm build && cd tests/anthropic && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
216
- "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk"
216
+ "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk",
217
+ "test:otelv1-local-debugger": "pnpm build && cd tests/otelv1-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test",
218
+ "test:otelv2-local-debugger": "pnpm build && cd tests/otelv2-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test"
217
219
  },
218
220
  devDependencies: {
219
221
  "@raindrop-ai/core": "workspace:*",
220
222
  "@raindrop-ai/redact-pii": "workspace:*",
221
223
  "@raindrop-ai/schemas": "workspace:*",
222
224
  ai: "^6.0.0",
225
+ "@opentelemetry/resources": "^2.0.1",
223
226
  "@types/node": "^20.11.17",
224
227
  msw: "^2.12.8",
225
228
  tsup: "^8.4.0",
@@ -230,7 +233,7 @@ var package_default = {
230
233
  },
231
234
  dependencies: {
232
235
  "@opentelemetry/api": "^1.9.0",
233
- "@opentelemetry/resources": "^2.0.1",
236
+ "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
234
237
  "@traceloop/node-server-sdk": "0.19.0-otel-v1",
235
238
  weakref: "^0.2.1",
236
239
  zod: "^3.23.8"
@@ -261,6 +264,7 @@ var package_default = {
261
264
  "@traceloop/instrumentation-qdrant",
262
265
  "@traceloop/instrumentation-together",
263
266
  "@opentelemetry/instrumentation",
267
+ "@opentelemetry/exporter-trace-otlp-http",
264
268
  "@opentelemetry/sdk-trace-base"
265
269
  ],
266
270
  noExternal: [
@@ -277,6 +281,7 @@ var package_default = {
277
281
 
278
282
  // src/tracing/tracer-core.ts
279
283
  import { context as context4, SpanStatusCode as SpanStatusCode4, trace as trace4 } from "@opentelemetry/api";
284
+ import { OTLPTraceExporter as OTLPHttpTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
280
285
  import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
281
286
  import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
282
287
  import { ChromaDBInstrumentation } from "@traceloop/instrumentation-chromadb";
@@ -1443,6 +1448,137 @@ if (localDebuggerEnabled()) {
1443
1448
  process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = "http/json";
1444
1449
  }
1445
1450
  }
1451
+ var CompositeSpanProcessor = class {
1452
+ constructor(requiredProcessors, bestEffortProcessors) {
1453
+ this.requiredProcessors = requiredProcessors;
1454
+ this.bestEffortProcessors = bestEffortProcessors;
1455
+ }
1456
+ onStart(span, parentContext) {
1457
+ for (const processor of this.requiredProcessors) {
1458
+ processor.onStart(span, parentContext);
1459
+ }
1460
+ for (const processor of this.bestEffortProcessors) {
1461
+ try {
1462
+ processor.onStart(span, parentContext);
1463
+ } catch (e) {
1464
+ }
1465
+ }
1466
+ }
1467
+ onEnd(span) {
1468
+ for (const processor of this.requiredProcessors) {
1469
+ processor.onEnd(span);
1470
+ }
1471
+ for (const processor of this.bestEffortProcessors) {
1472
+ try {
1473
+ processor.onEnd(span);
1474
+ } catch (e) {
1475
+ }
1476
+ }
1477
+ }
1478
+ async forceFlush() {
1479
+ const requiredFlushes = this.requiredProcessors.map(
1480
+ (processor) => callProcessorLifecycle(processor, "forceFlush")
1481
+ );
1482
+ const bestEffortFlushes = this.bestEffortProcessors.map(
1483
+ (processor) => callBestEffortProcessorLifecycle(processor, "forceFlush")
1484
+ );
1485
+ const [requiredResults] = await Promise.all([
1486
+ Promise.allSettled(requiredFlushes),
1487
+ Promise.allSettled(bestEffortFlushes)
1488
+ ]);
1489
+ throwFirstRejected(requiredResults);
1490
+ }
1491
+ async shutdown() {
1492
+ const requiredShutdowns = this.requiredProcessors.map(
1493
+ (processor) => callProcessorLifecycle(processor, "shutdown")
1494
+ );
1495
+ const bestEffortShutdowns = this.bestEffortProcessors.map(
1496
+ (processor) => callBestEffortProcessorLifecycle(processor, "shutdown")
1497
+ );
1498
+ const [requiredResults] = await Promise.all([
1499
+ Promise.allSettled(requiredShutdowns),
1500
+ Promise.allSettled(bestEffortShutdowns)
1501
+ ]);
1502
+ throwFirstRejected(requiredResults);
1503
+ }
1504
+ };
1505
+ function callProcessorLifecycle(processor, method) {
1506
+ try {
1507
+ return processor[method]();
1508
+ } catch (error) {
1509
+ return Promise.reject(error);
1510
+ }
1511
+ }
1512
+ function callBestEffortProcessorLifecycle(processor, method) {
1513
+ try {
1514
+ return processor[method]().catch(() => {
1515
+ });
1516
+ } catch (e) {
1517
+ return Promise.resolve();
1518
+ }
1519
+ }
1520
+ function throwFirstRejected(results) {
1521
+ const rejected = results.find(
1522
+ (result) => result.status === "rejected"
1523
+ );
1524
+ if (rejected) {
1525
+ throw rejected.reason;
1526
+ }
1527
+ }
1528
+ function isLocalDebuggerUrl(baseUrl) {
1529
+ try {
1530
+ const url = new URL(baseUrl);
1531
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
1532
+ return false;
1533
+ }
1534
+ const hostname = url.hostname.toLowerCase();
1535
+ return hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "0.0.0.0" || hostname === "127.0.0.1" || hostname.startsWith("127.") || hostname === "::1" || hostname === "[::1]";
1536
+ } catch (e) {
1537
+ return false;
1538
+ }
1539
+ }
1540
+ function resolveLocalDebuggerExporterBaseUrl() {
1541
+ const localDebuggerUrl = resolveLocalDebuggerBaseUrl();
1542
+ if (!localDebuggerUrl || !isLocalDebuggerUrl(localDebuggerUrl)) {
1543
+ return null;
1544
+ }
1545
+ return localDebuggerUrl;
1546
+ }
1547
+ function createLocalDebuggerOtlpExporter(config) {
1548
+ return new OTLPHttpTraceExporter(config);
1549
+ }
1550
+ function createLocalDebuggerSpanProcessor(options) {
1551
+ const localDebuggerUrl = resolveLocalDebuggerExporterBaseUrl();
1552
+ if (!localDebuggerUrl) {
1553
+ return void 0;
1554
+ }
1555
+ const localExporter = createLocalDebuggerOtlpExporter({
1556
+ url: `${localDebuggerUrl}traces`,
1557
+ headers: {}
1558
+ });
1559
+ try {
1560
+ return traceloop3.createSpanProcessor({
1561
+ apiKey: options.writeKey,
1562
+ baseUrl: localDebuggerUrl,
1563
+ disableBatch: options.disableBatching,
1564
+ exporter: localExporter,
1565
+ headers: {},
1566
+ allowedInstrumentationLibraries: options.allowedInstrumentationLibraries
1567
+ });
1568
+ } catch (error) {
1569
+ console.warn(
1570
+ "[raindrop] Failed to initialize local debugger trace exporter.",
1571
+ error instanceof Error ? error.message : error
1572
+ );
1573
+ return void 0;
1574
+ }
1575
+ }
1576
+ function mergeWithBestEffortLocalDebuggerProcessor(processor, localDebuggerProcessor) {
1577
+ if (!localDebuggerProcessor) {
1578
+ return processor;
1579
+ }
1580
+ return new CompositeSpanProcessor(processor ? [processor] : [], [localDebuggerProcessor]);
1581
+ }
1446
1582
  try {
1447
1583
  const _bedrockProto = BedrockInstrumentation.prototype;
1448
1584
  _bedrockProto._wrapPromise = function(span, promise) {
@@ -1740,13 +1876,23 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
1740
1876
  }
1741
1877
  }
1742
1878
  } else {
1879
+ const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
1880
+ writeKey,
1881
+ disableBatching,
1882
+ allowedInstrumentationLibraries: traceloop3.ALL_INSTRUMENTATION_LIBRARIES
1883
+ });
1884
+ const processor = mergeWithBestEffortLocalDebuggerProcessor(
1885
+ otherOptions.processor,
1886
+ localDebuggerProcessor
1887
+ );
1743
1888
  traceloop3.initialize({
1744
1889
  baseUrl: apiUrl,
1745
1890
  apiKey: writeKey,
1746
1891
  ...otherOptions,
1747
1892
  logLevel,
1748
1893
  tracingEnabled: tracingEnabled !== false,
1749
- disableBatch: disableBatching
1894
+ disableBatch: disableBatching,
1895
+ ...processor ? { processor } : {}
1750
1896
  });
1751
1897
  traceloopInitialized = true;
1752
1898
  }
@@ -1822,12 +1968,21 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
1822
1968
  }
1823
1969
  };
1824
1970
  }
1825
- return traceloop3.createSpanProcessor({
1971
+ const productionProcessor = traceloop3.createSpanProcessor({
1826
1972
  baseUrl: apiUrl,
1827
1973
  apiKey: writeKey,
1828
1974
  disableBatch: disableBatching,
1829
1975
  ...processorOptions != null ? processorOptions : {}
1830
1976
  });
1977
+ const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
1978
+ writeKey,
1979
+ disableBatching,
1980
+ allowedInstrumentationLibraries: processorOptions == null ? void 0 : processorOptions.allowedInstrumentationLibraries
1981
+ });
1982
+ return mergeWithBestEffortLocalDebuggerProcessor(
1983
+ productionProcessor,
1984
+ localDebuggerProcessor
1985
+ );
1831
1986
  },
1832
1987
  begin(traceContext) {
1833
1988
  var _a;
package/dist/index.js CHANGED
@@ -10041,7 +10041,7 @@ var SignalEventSchema = external_exports.object({
10041
10041
  // package.json
10042
10042
  var package_default = {
10043
10043
  name: "raindrop-ai",
10044
- version: "0.0.90",
10044
+ version: "0.0.91",
10045
10045
  main: "dist/index.js",
10046
10046
  module: "dist/index.mjs",
10047
10047
  types: "dist/index.d.ts",
@@ -10091,13 +10091,16 @@ var package_default = {
10091
10091
  "smoke:self-diagnostics:ai-sdk:all": "pnpm smoke:self-diagnostics:v4 && pnpm smoke:self-diagnostics:v5 && pnpm smoke:self-diagnostics:v6",
10092
10092
  "smoke:self-diagnostics:openai-sdk": "pnpm build && cd tests/openai && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
10093
10093
  "smoke:self-diagnostics:anthropic-sdk": "pnpm build && cd tests/anthropic && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
10094
- "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk"
10094
+ "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk",
10095
+ "test:otelv1-local-debugger": "pnpm build && cd tests/otelv1-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test",
10096
+ "test:otelv2-local-debugger": "pnpm build && cd tests/otelv2-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test"
10095
10097
  },
10096
10098
  devDependencies: {
10097
10099
  "@raindrop-ai/core": "workspace:*",
10098
10100
  "@raindrop-ai/redact-pii": "workspace:*",
10099
10101
  "@raindrop-ai/schemas": "workspace:*",
10100
10102
  ai: "^6.0.0",
10103
+ "@opentelemetry/resources": "^2.0.1",
10101
10104
  "@types/node": "^20.11.17",
10102
10105
  msw: "^2.12.8",
10103
10106
  tsup: "^8.4.0",
@@ -10108,7 +10111,7 @@ var package_default = {
10108
10111
  },
10109
10112
  dependencies: {
10110
10113
  "@opentelemetry/api": "^1.9.0",
10111
- "@opentelemetry/resources": "^2.0.1",
10114
+ "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
10112
10115
  "@traceloop/node-server-sdk": "0.19.0-otel-v1",
10113
10116
  weakref: "^0.2.1",
10114
10117
  zod: "^3.23.8"
@@ -10139,6 +10142,7 @@ var package_default = {
10139
10142
  "@traceloop/instrumentation-qdrant",
10140
10143
  "@traceloop/instrumentation-together",
10141
10144
  "@opentelemetry/instrumentation",
10145
+ "@opentelemetry/exporter-trace-otlp-http",
10142
10146
  "@opentelemetry/sdk-trace-base"
10143
10147
  ],
10144
10148
  noExternal: [
@@ -10244,6 +10248,7 @@ function redactPII(event) {
10244
10248
 
10245
10249
  // src/tracing/tracer-core.ts
10246
10250
  var import_api4 = require("@opentelemetry/api");
10251
+ var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
10247
10252
  var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
10248
10253
  var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
10249
10254
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
@@ -11407,6 +11412,137 @@ if (localDebuggerEnabled()) {
11407
11412
  process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = "http/json";
11408
11413
  }
11409
11414
  }
11415
+ var CompositeSpanProcessor = class {
11416
+ constructor(requiredProcessors, bestEffortProcessors) {
11417
+ this.requiredProcessors = requiredProcessors;
11418
+ this.bestEffortProcessors = bestEffortProcessors;
11419
+ }
11420
+ onStart(span, parentContext) {
11421
+ for (const processor of this.requiredProcessors) {
11422
+ processor.onStart(span, parentContext);
11423
+ }
11424
+ for (const processor of this.bestEffortProcessors) {
11425
+ try {
11426
+ processor.onStart(span, parentContext);
11427
+ } catch (e) {
11428
+ }
11429
+ }
11430
+ }
11431
+ onEnd(span) {
11432
+ for (const processor of this.requiredProcessors) {
11433
+ processor.onEnd(span);
11434
+ }
11435
+ for (const processor of this.bestEffortProcessors) {
11436
+ try {
11437
+ processor.onEnd(span);
11438
+ } catch (e) {
11439
+ }
11440
+ }
11441
+ }
11442
+ async forceFlush() {
11443
+ const requiredFlushes = this.requiredProcessors.map(
11444
+ (processor) => callProcessorLifecycle(processor, "forceFlush")
11445
+ );
11446
+ const bestEffortFlushes = this.bestEffortProcessors.map(
11447
+ (processor) => callBestEffortProcessorLifecycle(processor, "forceFlush")
11448
+ );
11449
+ const [requiredResults] = await Promise.all([
11450
+ Promise.allSettled(requiredFlushes),
11451
+ Promise.allSettled(bestEffortFlushes)
11452
+ ]);
11453
+ throwFirstRejected(requiredResults);
11454
+ }
11455
+ async shutdown() {
11456
+ const requiredShutdowns = this.requiredProcessors.map(
11457
+ (processor) => callProcessorLifecycle(processor, "shutdown")
11458
+ );
11459
+ const bestEffortShutdowns = this.bestEffortProcessors.map(
11460
+ (processor) => callBestEffortProcessorLifecycle(processor, "shutdown")
11461
+ );
11462
+ const [requiredResults] = await Promise.all([
11463
+ Promise.allSettled(requiredShutdowns),
11464
+ Promise.allSettled(bestEffortShutdowns)
11465
+ ]);
11466
+ throwFirstRejected(requiredResults);
11467
+ }
11468
+ };
11469
+ function callProcessorLifecycle(processor, method) {
11470
+ try {
11471
+ return processor[method]();
11472
+ } catch (error) {
11473
+ return Promise.reject(error);
11474
+ }
11475
+ }
11476
+ function callBestEffortProcessorLifecycle(processor, method) {
11477
+ try {
11478
+ return processor[method]().catch(() => {
11479
+ });
11480
+ } catch (e) {
11481
+ return Promise.resolve();
11482
+ }
11483
+ }
11484
+ function throwFirstRejected(results) {
11485
+ const rejected = results.find(
11486
+ (result) => result.status === "rejected"
11487
+ );
11488
+ if (rejected) {
11489
+ throw rejected.reason;
11490
+ }
11491
+ }
11492
+ function isLocalDebuggerUrl(baseUrl) {
11493
+ try {
11494
+ const url = new URL(baseUrl);
11495
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
11496
+ return false;
11497
+ }
11498
+ const hostname = url.hostname.toLowerCase();
11499
+ return hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "0.0.0.0" || hostname === "127.0.0.1" || hostname.startsWith("127.") || hostname === "::1" || hostname === "[::1]";
11500
+ } catch (e) {
11501
+ return false;
11502
+ }
11503
+ }
11504
+ function resolveLocalDebuggerExporterBaseUrl() {
11505
+ const localDebuggerUrl = resolveLocalDebuggerBaseUrl();
11506
+ if (!localDebuggerUrl || !isLocalDebuggerUrl(localDebuggerUrl)) {
11507
+ return null;
11508
+ }
11509
+ return localDebuggerUrl;
11510
+ }
11511
+ function createLocalDebuggerOtlpExporter(config) {
11512
+ return new import_exporter_trace_otlp_http.OTLPTraceExporter(config);
11513
+ }
11514
+ function createLocalDebuggerSpanProcessor(options) {
11515
+ const localDebuggerUrl = resolveLocalDebuggerExporterBaseUrl();
11516
+ if (!localDebuggerUrl) {
11517
+ return void 0;
11518
+ }
11519
+ const localExporter = createLocalDebuggerOtlpExporter({
11520
+ url: `${localDebuggerUrl}traces`,
11521
+ headers: {}
11522
+ });
11523
+ try {
11524
+ return traceloop3.createSpanProcessor({
11525
+ apiKey: options.writeKey,
11526
+ baseUrl: localDebuggerUrl,
11527
+ disableBatch: options.disableBatching,
11528
+ exporter: localExporter,
11529
+ headers: {},
11530
+ allowedInstrumentationLibraries: options.allowedInstrumentationLibraries
11531
+ });
11532
+ } catch (error) {
11533
+ console.warn(
11534
+ "[raindrop] Failed to initialize local debugger trace exporter.",
11535
+ error instanceof Error ? error.message : error
11536
+ );
11537
+ return void 0;
11538
+ }
11539
+ }
11540
+ function mergeWithBestEffortLocalDebuggerProcessor(processor, localDebuggerProcessor) {
11541
+ if (!localDebuggerProcessor) {
11542
+ return processor;
11543
+ }
11544
+ return new CompositeSpanProcessor(processor ? [processor] : [], [localDebuggerProcessor]);
11545
+ }
11410
11546
  try {
11411
11547
  const _bedrockProto = import_instrumentation_bedrock.BedrockInstrumentation.prototype;
11412
11548
  _bedrockProto._wrapPromise = function(span, promise) {
@@ -11704,13 +11840,23 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
11704
11840
  }
11705
11841
  }
11706
11842
  } else {
11843
+ const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
11844
+ writeKey,
11845
+ disableBatching,
11846
+ allowedInstrumentationLibraries: traceloop3.ALL_INSTRUMENTATION_LIBRARIES
11847
+ });
11848
+ const processor = mergeWithBestEffortLocalDebuggerProcessor(
11849
+ otherOptions.processor,
11850
+ localDebuggerProcessor
11851
+ );
11707
11852
  traceloop3.initialize({
11708
11853
  baseUrl: apiUrl,
11709
11854
  apiKey: writeKey,
11710
11855
  ...otherOptions,
11711
11856
  logLevel,
11712
11857
  tracingEnabled: tracingEnabled !== false,
11713
- disableBatch: disableBatching
11858
+ disableBatch: disableBatching,
11859
+ ...processor ? { processor } : {}
11714
11860
  });
11715
11861
  traceloopInitialized = true;
11716
11862
  }
@@ -11786,12 +11932,21 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
11786
11932
  }
11787
11933
  };
11788
11934
  }
11789
- return traceloop3.createSpanProcessor({
11935
+ const productionProcessor = traceloop3.createSpanProcessor({
11790
11936
  baseUrl: apiUrl,
11791
11937
  apiKey: writeKey,
11792
11938
  disableBatch: disableBatching,
11793
11939
  ...processorOptions != null ? processorOptions : {}
11794
11940
  });
11941
+ const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
11942
+ writeKey,
11943
+ disableBatching,
11944
+ allowedInstrumentationLibraries: processorOptions == null ? void 0 : processorOptions.allowedInstrumentationLibraries
11945
+ });
11946
+ return mergeWithBestEffortLocalDebuggerProcessor(
11947
+ productionProcessor,
11948
+ localDebuggerProcessor
11949
+ );
11795
11950
  },
11796
11951
  begin(traceContext) {
11797
11952
  var _a;
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  mirrorPartialEventToLocalDebugger,
3
3
  package_default,
4
4
  tracing
5
- } from "./chunk-CPBZ7IYG.mjs";
5
+ } from "./chunk-4KBZONJV.mjs";
6
6
  import {
7
7
  __commonJS,
8
8
  __toESM
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(tracing_exports);
37
37
 
38
38
  // src/tracing/tracer-core.ts
39
39
  var import_api4 = require("@opentelemetry/api");
40
+ var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
40
41
  var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
41
42
  var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
42
43
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
@@ -350,7 +351,7 @@ function base64ToHex(base64) {
350
351
  // package.json
351
352
  var package_default = {
352
353
  name: "raindrop-ai",
353
- version: "0.0.90",
354
+ version: "0.0.91",
354
355
  main: "dist/index.js",
355
356
  module: "dist/index.mjs",
356
357
  types: "dist/index.d.ts",
@@ -400,13 +401,16 @@ var package_default = {
400
401
  "smoke:self-diagnostics:ai-sdk:all": "pnpm smoke:self-diagnostics:v4 && pnpm smoke:self-diagnostics:v5 && pnpm smoke:self-diagnostics:v6",
401
402
  "smoke:self-diagnostics:openai-sdk": "pnpm build && cd tests/openai && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
402
403
  "smoke:self-diagnostics:anthropic-sdk": "pnpm build && cd tests/anthropic && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
403
- "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk"
404
+ "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk",
405
+ "test:otelv1-local-debugger": "pnpm build && cd tests/otelv1-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test",
406
+ "test:otelv2-local-debugger": "pnpm build && cd tests/otelv2-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test"
404
407
  },
405
408
  devDependencies: {
406
409
  "@raindrop-ai/core": "workspace:*",
407
410
  "@raindrop-ai/redact-pii": "workspace:*",
408
411
  "@raindrop-ai/schemas": "workspace:*",
409
412
  ai: "^6.0.0",
413
+ "@opentelemetry/resources": "^2.0.1",
410
414
  "@types/node": "^20.11.17",
411
415
  msw: "^2.12.8",
412
416
  tsup: "^8.4.0",
@@ -417,7 +421,7 @@ var package_default = {
417
421
  },
418
422
  dependencies: {
419
423
  "@opentelemetry/api": "^1.9.0",
420
- "@opentelemetry/resources": "^2.0.1",
424
+ "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
421
425
  "@traceloop/node-server-sdk": "0.19.0-otel-v1",
422
426
  weakref: "^0.2.1",
423
427
  zod: "^3.23.8"
@@ -448,6 +452,7 @@ var package_default = {
448
452
  "@traceloop/instrumentation-qdrant",
449
453
  "@traceloop/instrumentation-together",
450
454
  "@opentelemetry/instrumentation",
455
+ "@opentelemetry/exporter-trace-otlp-http",
451
456
  "@opentelemetry/sdk-trace-base"
452
457
  ],
453
458
  noExternal: [
@@ -1465,6 +1470,137 @@ if (localDebuggerEnabled()) {
1465
1470
  process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = "http/json";
1466
1471
  }
1467
1472
  }
1473
+ var CompositeSpanProcessor = class {
1474
+ constructor(requiredProcessors, bestEffortProcessors) {
1475
+ this.requiredProcessors = requiredProcessors;
1476
+ this.bestEffortProcessors = bestEffortProcessors;
1477
+ }
1478
+ onStart(span, parentContext) {
1479
+ for (const processor of this.requiredProcessors) {
1480
+ processor.onStart(span, parentContext);
1481
+ }
1482
+ for (const processor of this.bestEffortProcessors) {
1483
+ try {
1484
+ processor.onStart(span, parentContext);
1485
+ } catch (e) {
1486
+ }
1487
+ }
1488
+ }
1489
+ onEnd(span) {
1490
+ for (const processor of this.requiredProcessors) {
1491
+ processor.onEnd(span);
1492
+ }
1493
+ for (const processor of this.bestEffortProcessors) {
1494
+ try {
1495
+ processor.onEnd(span);
1496
+ } catch (e) {
1497
+ }
1498
+ }
1499
+ }
1500
+ async forceFlush() {
1501
+ const requiredFlushes = this.requiredProcessors.map(
1502
+ (processor) => callProcessorLifecycle(processor, "forceFlush")
1503
+ );
1504
+ const bestEffortFlushes = this.bestEffortProcessors.map(
1505
+ (processor) => callBestEffortProcessorLifecycle(processor, "forceFlush")
1506
+ );
1507
+ const [requiredResults] = await Promise.all([
1508
+ Promise.allSettled(requiredFlushes),
1509
+ Promise.allSettled(bestEffortFlushes)
1510
+ ]);
1511
+ throwFirstRejected(requiredResults);
1512
+ }
1513
+ async shutdown() {
1514
+ const requiredShutdowns = this.requiredProcessors.map(
1515
+ (processor) => callProcessorLifecycle(processor, "shutdown")
1516
+ );
1517
+ const bestEffortShutdowns = this.bestEffortProcessors.map(
1518
+ (processor) => callBestEffortProcessorLifecycle(processor, "shutdown")
1519
+ );
1520
+ const [requiredResults] = await Promise.all([
1521
+ Promise.allSettled(requiredShutdowns),
1522
+ Promise.allSettled(bestEffortShutdowns)
1523
+ ]);
1524
+ throwFirstRejected(requiredResults);
1525
+ }
1526
+ };
1527
+ function callProcessorLifecycle(processor, method) {
1528
+ try {
1529
+ return processor[method]();
1530
+ } catch (error) {
1531
+ return Promise.reject(error);
1532
+ }
1533
+ }
1534
+ function callBestEffortProcessorLifecycle(processor, method) {
1535
+ try {
1536
+ return processor[method]().catch(() => {
1537
+ });
1538
+ } catch (e) {
1539
+ return Promise.resolve();
1540
+ }
1541
+ }
1542
+ function throwFirstRejected(results) {
1543
+ const rejected = results.find(
1544
+ (result) => result.status === "rejected"
1545
+ );
1546
+ if (rejected) {
1547
+ throw rejected.reason;
1548
+ }
1549
+ }
1550
+ function isLocalDebuggerUrl(baseUrl) {
1551
+ try {
1552
+ const url = new URL(baseUrl);
1553
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
1554
+ return false;
1555
+ }
1556
+ const hostname = url.hostname.toLowerCase();
1557
+ return hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "0.0.0.0" || hostname === "127.0.0.1" || hostname.startsWith("127.") || hostname === "::1" || hostname === "[::1]";
1558
+ } catch (e) {
1559
+ return false;
1560
+ }
1561
+ }
1562
+ function resolveLocalDebuggerExporterBaseUrl() {
1563
+ const localDebuggerUrl = resolveLocalDebuggerBaseUrl();
1564
+ if (!localDebuggerUrl || !isLocalDebuggerUrl(localDebuggerUrl)) {
1565
+ return null;
1566
+ }
1567
+ return localDebuggerUrl;
1568
+ }
1569
+ function createLocalDebuggerOtlpExporter(config) {
1570
+ return new import_exporter_trace_otlp_http.OTLPTraceExporter(config);
1571
+ }
1572
+ function createLocalDebuggerSpanProcessor(options) {
1573
+ const localDebuggerUrl = resolveLocalDebuggerExporterBaseUrl();
1574
+ if (!localDebuggerUrl) {
1575
+ return void 0;
1576
+ }
1577
+ const localExporter = createLocalDebuggerOtlpExporter({
1578
+ url: `${localDebuggerUrl}traces`,
1579
+ headers: {}
1580
+ });
1581
+ try {
1582
+ return traceloop3.createSpanProcessor({
1583
+ apiKey: options.writeKey,
1584
+ baseUrl: localDebuggerUrl,
1585
+ disableBatch: options.disableBatching,
1586
+ exporter: localExporter,
1587
+ headers: {},
1588
+ allowedInstrumentationLibraries: options.allowedInstrumentationLibraries
1589
+ });
1590
+ } catch (error) {
1591
+ console.warn(
1592
+ "[raindrop] Failed to initialize local debugger trace exporter.",
1593
+ error instanceof Error ? error.message : error
1594
+ );
1595
+ return void 0;
1596
+ }
1597
+ }
1598
+ function mergeWithBestEffortLocalDebuggerProcessor(processor, localDebuggerProcessor) {
1599
+ if (!localDebuggerProcessor) {
1600
+ return processor;
1601
+ }
1602
+ return new CompositeSpanProcessor(processor ? [processor] : [], [localDebuggerProcessor]);
1603
+ }
1468
1604
  try {
1469
1605
  const _bedrockProto = import_instrumentation_bedrock.BedrockInstrumentation.prototype;
1470
1606
  _bedrockProto._wrapPromise = function(span, promise) {
@@ -1762,13 +1898,23 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
1762
1898
  }
1763
1899
  }
1764
1900
  } else {
1901
+ const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
1902
+ writeKey,
1903
+ disableBatching,
1904
+ allowedInstrumentationLibraries: traceloop3.ALL_INSTRUMENTATION_LIBRARIES
1905
+ });
1906
+ const processor = mergeWithBestEffortLocalDebuggerProcessor(
1907
+ otherOptions.processor,
1908
+ localDebuggerProcessor
1909
+ );
1765
1910
  traceloop3.initialize({
1766
1911
  baseUrl: apiUrl,
1767
1912
  apiKey: writeKey,
1768
1913
  ...otherOptions,
1769
1914
  logLevel,
1770
1915
  tracingEnabled: tracingEnabled !== false,
1771
- disableBatch: disableBatching
1916
+ disableBatch: disableBatching,
1917
+ ...processor ? { processor } : {}
1772
1918
  });
1773
1919
  traceloopInitialized = true;
1774
1920
  }
@@ -1844,12 +1990,21 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
1844
1990
  }
1845
1991
  };
1846
1992
  }
1847
- return traceloop3.createSpanProcessor({
1993
+ const productionProcessor = traceloop3.createSpanProcessor({
1848
1994
  baseUrl: apiUrl,
1849
1995
  apiKey: writeKey,
1850
1996
  disableBatch: disableBatching,
1851
1997
  ...processorOptions != null ? processorOptions : {}
1852
1998
  });
1999
+ const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
2000
+ writeKey,
2001
+ disableBatching,
2002
+ allowedInstrumentationLibraries: processorOptions == null ? void 0 : processorOptions.allowedInstrumentationLibraries
2003
+ });
2004
+ return mergeWithBestEffortLocalDebuggerProcessor(
2005
+ productionProcessor,
2006
+ localDebuggerProcessor
2007
+ );
1853
2008
  },
1854
2009
  begin(traceContext) {
1855
2010
  var _a;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  tracing
3
- } from "../chunk-CPBZ7IYG.mjs";
3
+ } from "../chunk-4KBZONJV.mjs";
4
4
  import "../chunk-UJCSKKID.mjs";
5
5
 
6
6
  // src/tracing/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raindrop-ai",
3
- "version": "0.0.90",
3
+ "version": "0.0.91-otelv2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -37,8 +37,9 @@
37
37
  "dist/**"
38
38
  ],
39
39
  "devDependencies": {
40
- "ai": "^6.0.0",
40
+ "@opentelemetry/resources": "^2.0.1",
41
41
  "@types/node": "^20.11.17",
42
+ "ai": "^6.0.0",
42
43
  "msw": "^2.12.8",
43
44
  "tsup": "^8.4.0",
44
45
  "tsx": "^4.20.3",
@@ -46,13 +47,12 @@
46
47
  "vite": "^7.3.2",
47
48
  "vitest": "^4.0.10",
48
49
  "@raindrop-ai/core": "0.0.1",
49
- "@raindrop-ai/redact-pii": "0.1.2",
50
- "@raindrop-ai/schemas": "0.0.1"
50
+ "@raindrop-ai/schemas": "0.0.1",
51
+ "@raindrop-ai/redact-pii": "0.1.2"
51
52
  },
52
53
  "dependencies": {
53
54
  "@opentelemetry/api": "^1.9.0",
54
- "@opentelemetry/resources": "^2.0.1",
55
- "@traceloop/node-server-sdk": "0.19.0-otel-v1",
55
+ "@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
56
56
  "weakref": "^0.2.1",
57
57
  "zod": "^3.23.8"
58
58
  },
@@ -82,6 +82,7 @@
82
82
  "@traceloop/instrumentation-qdrant",
83
83
  "@traceloop/instrumentation-together",
84
84
  "@opentelemetry/instrumentation",
85
+ "@opentelemetry/exporter-trace-otlp-http",
85
86
  "@opentelemetry/sdk-trace-base"
86
87
  ],
87
88
  "noExternal": [
@@ -94,6 +95,9 @@
94
95
  },
95
96
  "clean": true
96
97
  },
98
+ "optionalDependencies": {
99
+ "@traceloop/node-server-sdk": "0.22.2"
100
+ },
97
101
  "scripts": {
98
102
  "build": "tsup",
99
103
  "dev": "tsup --watch",
@@ -108,6 +112,8 @@
108
112
  "smoke:self-diagnostics:ai-sdk:all": "pnpm smoke:self-diagnostics:v4 && pnpm smoke:self-diagnostics:v5 && pnpm smoke:self-diagnostics:v6",
109
113
  "smoke:self-diagnostics:openai-sdk": "pnpm build && cd tests/openai && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
110
114
  "smoke:self-diagnostics:anthropic-sdk": "pnpm build && cd tests/anthropic && pnpm install --ignore-workspace --lockfile=false && pnpm smoke",
111
- "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk"
115
+ "smoke:self-diagnostics:all": "pnpm smoke:self-diagnostics:ai-sdk:all && pnpm smoke:self-diagnostics:openai-sdk && pnpm smoke:self-diagnostics:anthropic-sdk",
116
+ "test:otelv1-local-debugger": "pnpm build && cd tests/otelv1-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test",
117
+ "test:otelv2-local-debugger": "pnpm build && cd tests/otelv2-local-debugger && pnpm install --ignore-workspace --lockfile=false && pnpm test"
112
118
  }
113
119
  }