raindrop-ai 0.0.75 → 0.0.76-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.
@@ -16,38 +16,8 @@ import * as traceloop3 from "@traceloop/node-server-sdk";
16
16
  import { WeakValueMap } from "weakref";
17
17
 
18
18
  // src/tracing/liveInteraction.ts
19
- import { context, trace } from "@opentelemetry/api";
19
+ import { trace } from "@opentelemetry/api";
20
20
  import * as traceloop from "@traceloop/node-server-sdk";
21
-
22
- // src/tracing/raindropSpanProcessor.ts
23
- import { createContextKey } from "@opentelemetry/api";
24
- var RAINDROP_CONTEXT_KEY = createContextKey("raindrop.association_properties");
25
- var RaindropContextSpanProcessor = class {
26
- onStart(span, parentContext) {
27
- const properties = parentContext.getValue(RAINDROP_CONTEXT_KEY);
28
- if (!properties) {
29
- return;
30
- }
31
- for (const [key, value] of Object.entries(properties)) {
32
- if (value !== void 0) {
33
- span.setAttribute(`traceloop.association.properties.${key}`, value);
34
- }
35
- }
36
- }
37
- onEnd(_span) {
38
- }
39
- shutdown() {
40
- return Promise.resolve();
41
- }
42
- forceFlush() {
43
- return Promise.resolve();
44
- }
45
- };
46
- function setRaindropContext(ctx, properties) {
47
- return ctx.setValue(RAINDROP_CONTEXT_KEY, properties);
48
- }
49
-
50
- // src/tracing/liveInteraction.ts
51
21
  function getPropertiesFromContext(context3) {
52
22
  const properties = {
53
23
  ...context3.userId && { user_id: context3.userId },
@@ -80,21 +50,18 @@ var LiveInteraction = class {
80
50
  if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
81
51
  console.log("[raindrop] using withSpan in liveInteraction");
82
52
  }
83
- const raindropContext = setRaindropContext(context.active(), properties);
84
- return context.with(raindropContext, () => {
85
- return traceloop.withTask(
86
- {
87
- name: taskName,
88
- associationProperties: properties,
89
- inputParameters,
90
- traceContent: params.traceContent,
91
- suppressTracing: params.suppressTracing
92
- },
93
- fn,
94
- thisArg,
95
- ...args
96
- );
97
- });
53
+ return traceloop.withTask(
54
+ {
55
+ name: taskName,
56
+ associationProperties: properties,
57
+ inputParameters,
58
+ traceContent: params.traceContent,
59
+ suppressTracing: params.suppressTracing
60
+ },
61
+ fn,
62
+ thisArg,
63
+ ...args
64
+ );
98
65
  }
99
66
  async withTool(params, fn, thisArg, ...args) {
100
67
  var _a;
@@ -107,22 +74,19 @@ var LiveInteraction = class {
107
74
  if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
108
75
  console.log("[raindrop] using withTool in liveInteraction");
109
76
  }
110
- const raindropContext = setRaindropContext(context.active(), properties);
111
- return context.with(raindropContext, () => {
112
- return traceloop.withTool(
113
- {
114
- name: toolName,
115
- associationProperties: properties,
116
- inputParameters: inputParams,
117
- version: params.version,
118
- traceContent: params.traceContent,
119
- suppressTracing: params.suppressTracing
120
- },
121
- fn,
122
- thisArg,
123
- ...args
124
- );
125
- });
77
+ return traceloop.withTool(
78
+ {
79
+ name: toolName,
80
+ associationProperties: properties,
81
+ inputParameters: inputParams,
82
+ version: params.version,
83
+ traceContent: params.traceContent,
84
+ suppressTracing: params.suppressTracing
85
+ },
86
+ fn,
87
+ thisArg,
88
+ ...args
89
+ );
126
90
  }
127
91
  startSpan(params) {
128
92
  const { name, properties = {} } = params;
@@ -306,7 +270,7 @@ function getCurrentTraceId() {
306
270
  return (_a = trace2.getSpan(context2.active())) == null ? void 0 : _a.spanContext().traceId;
307
271
  }
308
272
  var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
309
- const { logLevel, useExternalOtel, tracingEnabled, ...otherOptions } = options;
273
+ const { logLevel, useExternalOtel, tracingEnabled, disableBatching, ...otherOptions } = options;
310
274
  if (isDebug) {
311
275
  const mode = useExternalOtel ? "(external OTEL mode)" : tracingEnabled === false ? "(tracing disabled)" : "";
312
276
  console.log("[raindrop] Initializing tracing", mode);
@@ -340,24 +304,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
340
304
  apiKey: writeKey,
341
305
  ...otherOptions,
342
306
  logLevel,
343
- tracingEnabled: tracingEnabled !== false
307
+ tracingEnabled: tracingEnabled !== false,
308
+ disableBatch: disableBatching
344
309
  });
345
310
  traceloopInitialized = true;
346
- if (tracingEnabled !== false) {
347
- try {
348
- const provider = trace2.getTracerProvider();
349
- if (provider && typeof provider.addSpanProcessor === "function") {
350
- provider.addSpanProcessor(new RaindropContextSpanProcessor());
351
- if (isDebug) {
352
- console.log("[raindrop] Registered RaindropContextSpanProcessor for Vercel AI SDK support");
353
- }
354
- }
355
- } catch (e) {
356
- if (isDebug) {
357
- console.log("[raindrop] Could not register context span processor:", e);
358
- }
359
- }
360
- }
361
311
  }
362
312
  } catch (error) {
363
313
  console.warn(
@@ -407,7 +357,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
407
357
  * @example
408
358
  * ```typescript
409
359
  * const sdk = new NodeSDK({
410
- * spanProcessors: [raindrop.createSpanProcessor(), yourOtherProcessor],
360
+ * spanProcessors: [raindrop.createSpanProcessor()],
411
361
  * instrumentations: raindrop.getInstrumentations(),
412
362
  * });
413
363
  * ```
@@ -431,28 +381,12 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
431
381
  }
432
382
  };
433
383
  }
434
- const traceloopProcessor = traceloop3.createSpanProcessor({
384
+ return traceloop3.createSpanProcessor({
435
385
  baseUrl: apiUrl,
436
386
  apiKey: writeKey,
387
+ disableBatch: disableBatching,
437
388
  ...processorOptions != null ? processorOptions : {}
438
389
  });
439
- const contextProcessor = new RaindropContextSpanProcessor();
440
- return {
441
- onStart(span, parentContext) {
442
- contextProcessor.onStart(span, parentContext);
443
- traceloopProcessor.onStart(span, parentContext);
444
- },
445
- onEnd(span) {
446
- contextProcessor.onEnd(span);
447
- traceloopProcessor.onEnd(span);
448
- },
449
- async forceFlush() {
450
- await traceloopProcessor.forceFlush();
451
- },
452
- async shutdown() {
453
- await traceloopProcessor.shutdown();
454
- }
455
- };
456
390
  },
457
391
  begin(traceContext) {
458
392
  if (!traceContext.eventId) {
package/dist/index.d.mts CHANGED
@@ -466,6 +466,12 @@ interface AnalyticsConfig {
466
466
  * Useful for development/test environments.
467
467
  */
468
468
  disabled?: boolean;
469
+ /**
470
+ * Disable span batching for local development.
471
+ * When true, spans are sent immediately instead of being batched.
472
+ * Defaults to true in development (NODE_ENV !== 'production').
473
+ */
474
+ disableBatching?: boolean;
469
475
  /**
470
476
  * Explicitly specify modules to instrument. Optional.
471
477
  *
package/dist/index.d.ts CHANGED
@@ -466,6 +466,12 @@ interface AnalyticsConfig {
466
466
  * Useful for development/test environments.
467
467
  */
468
468
  disabled?: boolean;
469
+ /**
470
+ * Disable span batching for local development.
471
+ * When true, spans are sent immediately instead of being batched.
472
+ * Defaults to true in development (NODE_ENV !== 'production').
473
+ */
474
+ disableBatching?: boolean;
469
475
  /**
470
476
  * Explicitly specify modules to instrument. Optional.
471
477
  *
package/dist/index.js CHANGED
@@ -138,7 +138,7 @@ var CategorizationRequestSchema = import_zod.z.object({
138
138
  // package.json
139
139
  var package_default = {
140
140
  name: "raindrop-ai",
141
- version: "0.0.75",
141
+ version: "0.0.76",
142
142
  main: "dist/index.js",
143
143
  module: "dist/index.mjs",
144
144
  types: "dist/index.d.ts",
@@ -316,7 +316,7 @@ function redactPII(event) {
316
316
  }
317
317
 
318
318
  // src/tracing/tracer-core.ts
319
- var import_api3 = require("@opentelemetry/api");
319
+ var import_api2 = require("@opentelemetry/api");
320
320
  var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
321
321
  var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
322
322
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
@@ -330,38 +330,8 @@ var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
330
330
  var import_weakref = require("weakref");
331
331
 
332
332
  // src/tracing/liveInteraction.ts
333
- var import_api2 = require("@opentelemetry/api");
334
- var traceloop = __toESM(require("@traceloop/node-server-sdk"));
335
-
336
- // src/tracing/raindropSpanProcessor.ts
337
333
  var import_api = require("@opentelemetry/api");
338
- var RAINDROP_CONTEXT_KEY = (0, import_api.createContextKey)("raindrop.association_properties");
339
- var RaindropContextSpanProcessor = class {
340
- onStart(span, parentContext) {
341
- const properties = parentContext.getValue(RAINDROP_CONTEXT_KEY);
342
- if (!properties) {
343
- return;
344
- }
345
- for (const [key, value] of Object.entries(properties)) {
346
- if (value !== void 0) {
347
- span.setAttribute(`traceloop.association.properties.${key}`, value);
348
- }
349
- }
350
- }
351
- onEnd(_span) {
352
- }
353
- shutdown() {
354
- return Promise.resolve();
355
- }
356
- forceFlush() {
357
- return Promise.resolve();
358
- }
359
- };
360
- function setRaindropContext(ctx, properties) {
361
- return ctx.setValue(RAINDROP_CONTEXT_KEY, properties);
362
- }
363
-
364
- // src/tracing/liveInteraction.ts
334
+ var traceloop = __toESM(require("@traceloop/node-server-sdk"));
365
335
  function getPropertiesFromContext(context3) {
366
336
  const properties = {
367
337
  ...context3.userId && { user_id: context3.userId },
@@ -378,7 +348,7 @@ var LiveInteraction = class {
378
348
  constructor(context3, traceId, analytics) {
379
349
  this.context = context3;
380
350
  this.analytics = analytics;
381
- this.tracer = import_api2.trace.getTracer("traceloop.tracer");
351
+ this.tracer = import_api.trace.getTracer("traceloop.tracer");
382
352
  this.traceId = traceId;
383
353
  }
384
354
  async withSpan(params, fn, thisArg, ...args) {
@@ -394,21 +364,18 @@ var LiveInteraction = class {
394
364
  if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
395
365
  console.log("[raindrop] using withSpan in liveInteraction");
396
366
  }
397
- const raindropContext = setRaindropContext(import_api2.context.active(), properties);
398
- return import_api2.context.with(raindropContext, () => {
399
- return traceloop.withTask(
400
- {
401
- name: taskName,
402
- associationProperties: properties,
403
- inputParameters,
404
- traceContent: params.traceContent,
405
- suppressTracing: params.suppressTracing
406
- },
407
- fn,
408
- thisArg,
409
- ...args
410
- );
411
- });
367
+ return traceloop.withTask(
368
+ {
369
+ name: taskName,
370
+ associationProperties: properties,
371
+ inputParameters,
372
+ traceContent: params.traceContent,
373
+ suppressTracing: params.suppressTracing
374
+ },
375
+ fn,
376
+ thisArg,
377
+ ...args
378
+ );
412
379
  }
413
380
  async withTool(params, fn, thisArg, ...args) {
414
381
  var _a;
@@ -421,22 +388,19 @@ var LiveInteraction = class {
421
388
  if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
422
389
  console.log("[raindrop] using withTool in liveInteraction");
423
390
  }
424
- const raindropContext = setRaindropContext(import_api2.context.active(), properties);
425
- return import_api2.context.with(raindropContext, () => {
426
- return traceloop.withTool(
427
- {
428
- name: toolName,
429
- associationProperties: properties,
430
- inputParameters: inputParams,
431
- version: params.version,
432
- traceContent: params.traceContent,
433
- suppressTracing: params.suppressTracing
434
- },
435
- fn,
436
- thisArg,
437
- ...args
438
- );
439
- });
391
+ return traceloop.withTool(
392
+ {
393
+ name: toolName,
394
+ associationProperties: properties,
395
+ inputParameters: inputParams,
396
+ version: params.version,
397
+ traceContent: params.traceContent,
398
+ suppressTracing: params.suppressTracing
399
+ },
400
+ fn,
401
+ thisArg,
402
+ ...args
403
+ );
440
404
  }
441
405
  startSpan(params) {
442
406
  const { name, properties = {} } = params;
@@ -617,10 +581,10 @@ var activeInteractions = new import_weakref.WeakValueMap();
617
581
  var activeInteractionsByEventId = new import_weakref.WeakValueMap();
618
582
  function getCurrentTraceId() {
619
583
  var _a;
620
- return (_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId;
584
+ return (_a = import_api2.trace.getSpan(import_api2.context.active())) == null ? void 0 : _a.spanContext().traceId;
621
585
  }
622
586
  var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
623
- const { logLevel, useExternalOtel, tracingEnabled, ...otherOptions } = options;
587
+ const { logLevel, useExternalOtel, tracingEnabled, disableBatching, ...otherOptions } = options;
624
588
  if (isDebug) {
625
589
  const mode = useExternalOtel ? "(external OTEL mode)" : tracingEnabled === false ? "(tracing disabled)" : "";
626
590
  console.log("[raindrop] Initializing tracing", mode);
@@ -654,24 +618,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
654
618
  apiKey: writeKey,
655
619
  ...otherOptions,
656
620
  logLevel,
657
- tracingEnabled: tracingEnabled !== false
621
+ tracingEnabled: tracingEnabled !== false,
622
+ disableBatch: disableBatching
658
623
  });
659
624
  traceloopInitialized = true;
660
- if (tracingEnabled !== false) {
661
- try {
662
- const provider = import_api3.trace.getTracerProvider();
663
- if (provider && typeof provider.addSpanProcessor === "function") {
664
- provider.addSpanProcessor(new RaindropContextSpanProcessor());
665
- if (isDebug) {
666
- console.log("[raindrop] Registered RaindropContextSpanProcessor for Vercel AI SDK support");
667
- }
668
- }
669
- } catch (e) {
670
- if (isDebug) {
671
- console.log("[raindrop] Could not register context span processor:", e);
672
- }
673
- }
674
- }
675
625
  }
676
626
  } catch (error) {
677
627
  console.warn(
@@ -721,7 +671,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
721
671
  * @example
722
672
  * ```typescript
723
673
  * const sdk = new NodeSDK({
724
- * spanProcessors: [raindrop.createSpanProcessor(), yourOtherProcessor],
674
+ * spanProcessors: [raindrop.createSpanProcessor()],
725
675
  * instrumentations: raindrop.getInstrumentations(),
726
676
  * });
727
677
  * ```
@@ -745,28 +695,12 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
745
695
  }
746
696
  };
747
697
  }
748
- const traceloopProcessor = traceloop3.createSpanProcessor({
698
+ return traceloop3.createSpanProcessor({
749
699
  baseUrl: apiUrl,
750
700
  apiKey: writeKey,
701
+ disableBatch: disableBatching,
751
702
  ...processorOptions != null ? processorOptions : {}
752
703
  });
753
- const contextProcessor = new RaindropContextSpanProcessor();
754
- return {
755
- onStart(span, parentContext) {
756
- contextProcessor.onStart(span, parentContext);
757
- traceloopProcessor.onStart(span, parentContext);
758
- },
759
- onEnd(span) {
760
- contextProcessor.onEnd(span);
761
- traceloopProcessor.onEnd(span);
762
- },
763
- async forceFlush() {
764
- await traceloopProcessor.forceFlush();
765
- },
766
- async shutdown() {
767
- await traceloopProcessor.shutdown();
768
- }
769
- };
770
704
  },
771
705
  begin(traceContext) {
772
706
  if (!traceContext.eventId) {
@@ -909,7 +843,7 @@ var Raindrop = class {
909
843
  //page might get closed/reloaded before the buffer is flushed.
910
844
  // Node 25/26 are making breaking changes here: https://github.com/nodejs/node/issues/60303
911
845
  this.isEnvWithLocalStorage = typeof localStorage !== "undefined" && typeof localStorage.getItem === "function" && typeof localStorage.setItem === "function" && typeof localStorage.removeItem === "function";
912
- var _a, _b, _c, _d, _e, _f, _g, _h;
846
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
913
847
  if (!config.writeKey) {
914
848
  throw new Error("A writeKey is required to use Raindrop");
915
849
  }
@@ -939,12 +873,15 @@ var Raindrop = class {
939
873
  }
940
874
  const useExternalOtel = (_h = (_g = config.useExternalOtel) != null ? _g : config.disableTracing) != null ? _h : false;
941
875
  const url = new URL(this.apiUrl);
876
+ const isProduction = process.env.NODE_ENV === "production";
877
+ const disableBatching = (_i = config.disableBatching) != null ? _i : !isProduction;
942
878
  this._tracing = tracing(
943
879
  this,
944
880
  url.origin,
945
881
  this.writeKey,
946
882
  {
947
- disableBatch: false,
883
+ disableBatch: disableBatching,
884
+ disableBatching,
948
885
  logLevel: this.debugLogs ? "debug" : "error",
949
886
  // Pass through disabled state - tracer-core handles no-op exporter logic
950
887
  tracingEnabled: !this.disabled,
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  tracing
3
- } from "./chunk-CCT3KBLT.mjs";
3
+ } from "./chunk-7PZNI6M6.mjs";
4
4
 
5
5
  // ../schemas/src/ingest/index.ts
6
6
  import { z } from "zod";
@@ -104,7 +104,7 @@ var CategorizationRequestSchema = z.object({
104
104
  // package.json
105
105
  var package_default = {
106
106
  name: "raindrop-ai",
107
- version: "0.0.75",
107
+ version: "0.0.76",
108
108
  main: "dist/index.js",
109
109
  module: "dist/index.mjs",
110
110
  types: "dist/index.d.ts",
@@ -371,7 +371,7 @@ var Raindrop = class {
371
371
  //page might get closed/reloaded before the buffer is flushed.
372
372
  // Node 25/26 are making breaking changes here: https://github.com/nodejs/node/issues/60303
373
373
  this.isEnvWithLocalStorage = typeof localStorage !== "undefined" && typeof localStorage.getItem === "function" && typeof localStorage.setItem === "function" && typeof localStorage.removeItem === "function";
374
- var _a, _b, _c, _d, _e, _f, _g, _h;
374
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
375
375
  if (!config.writeKey) {
376
376
  throw new Error("A writeKey is required to use Raindrop");
377
377
  }
@@ -401,12 +401,15 @@ var Raindrop = class {
401
401
  }
402
402
  const useExternalOtel = (_h = (_g = config.useExternalOtel) != null ? _g : config.disableTracing) != null ? _h : false;
403
403
  const url = new URL(this.apiUrl);
404
+ const isProduction = process.env.NODE_ENV === "production";
405
+ const disableBatching = (_i = config.disableBatching) != null ? _i : !isProduction;
404
406
  this._tracing = tracing(
405
407
  this,
406
408
  url.origin,
407
409
  this.writeKey,
408
410
  {
409
- disableBatch: false,
411
+ disableBatch: disableBatching,
412
+ disableBatching,
410
413
  logLevel: this.debugLogs ? "debug" : "error",
411
414
  // Pass through disabled state - tracer-core handles no-op exporter logic
412
415
  tracingEnabled: !this.disabled,
@@ -14,6 +14,11 @@ interface TracingOptions extends traceloop.InitializeOptions {
14
14
  * - You must register instrumentations yourself (e.g., AnthropicInstrumentation)
15
15
  */
16
16
  useExternalOtel?: boolean;
17
+ /**
18
+ * Disable span batching for local development.
19
+ * When true, spans are sent immediately instead of being batched.
20
+ */
21
+ disableBatching?: boolean;
17
22
  }
18
23
  declare const tracing: (analytics: Raindrop, apiUrl: string, writeKey: string, options: TracingOptions, isDebug?: boolean) => {
19
24
  /**
@@ -45,7 +50,7 @@ declare const tracing: (analytics: Raindrop, apiUrl: string, writeKey: string, o
45
50
  * @example
46
51
  * ```typescript
47
52
  * const sdk = new NodeSDK({
48
- * spanProcessors: [raindrop.createSpanProcessor(), yourOtherProcessor],
53
+ * spanProcessors: [raindrop.createSpanProcessor()],
49
54
  * instrumentations: raindrop.getInstrumentations(),
50
55
  * });
51
56
  * ```
@@ -14,6 +14,11 @@ interface TracingOptions extends traceloop.InitializeOptions {
14
14
  * - You must register instrumentations yourself (e.g., AnthropicInstrumentation)
15
15
  */
16
16
  useExternalOtel?: boolean;
17
+ /**
18
+ * Disable span batching for local development.
19
+ * When true, spans are sent immediately instead of being batched.
20
+ */
21
+ disableBatching?: boolean;
17
22
  }
18
23
  declare const tracing: (analytics: Raindrop, apiUrl: string, writeKey: string, options: TracingOptions, isDebug?: boolean) => {
19
24
  /**
@@ -45,7 +50,7 @@ declare const tracing: (analytics: Raindrop, apiUrl: string, writeKey: string, o
45
50
  * @example
46
51
  * ```typescript
47
52
  * const sdk = new NodeSDK({
48
- * spanProcessors: [raindrop.createSpanProcessor(), yourOtherProcessor],
53
+ * spanProcessors: [raindrop.createSpanProcessor()],
49
54
  * instrumentations: raindrop.getInstrumentations(),
50
55
  * });
51
56
  * ```
@@ -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_api3 = require("@opentelemetry/api");
39
+ var import_api2 = require("@opentelemetry/api");
40
40
  var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
41
41
  var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
42
42
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
@@ -50,38 +50,8 @@ var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
50
50
  var import_weakref = require("weakref");
51
51
 
52
52
  // src/tracing/liveInteraction.ts
53
- var import_api2 = require("@opentelemetry/api");
54
- var traceloop = __toESM(require("@traceloop/node-server-sdk"));
55
-
56
- // src/tracing/raindropSpanProcessor.ts
57
53
  var import_api = require("@opentelemetry/api");
58
- var RAINDROP_CONTEXT_KEY = (0, import_api.createContextKey)("raindrop.association_properties");
59
- var RaindropContextSpanProcessor = class {
60
- onStart(span, parentContext) {
61
- const properties = parentContext.getValue(RAINDROP_CONTEXT_KEY);
62
- if (!properties) {
63
- return;
64
- }
65
- for (const [key, value] of Object.entries(properties)) {
66
- if (value !== void 0) {
67
- span.setAttribute(`traceloop.association.properties.${key}`, value);
68
- }
69
- }
70
- }
71
- onEnd(_span) {
72
- }
73
- shutdown() {
74
- return Promise.resolve();
75
- }
76
- forceFlush() {
77
- return Promise.resolve();
78
- }
79
- };
80
- function setRaindropContext(ctx, properties) {
81
- return ctx.setValue(RAINDROP_CONTEXT_KEY, properties);
82
- }
83
-
84
- // src/tracing/liveInteraction.ts
54
+ var traceloop = __toESM(require("@traceloop/node-server-sdk"));
85
55
  function getPropertiesFromContext(context3) {
86
56
  const properties = {
87
57
  ...context3.userId && { user_id: context3.userId },
@@ -98,7 +68,7 @@ var LiveInteraction = class {
98
68
  constructor(context3, traceId, analytics) {
99
69
  this.context = context3;
100
70
  this.analytics = analytics;
101
- this.tracer = import_api2.trace.getTracer("traceloop.tracer");
71
+ this.tracer = import_api.trace.getTracer("traceloop.tracer");
102
72
  this.traceId = traceId;
103
73
  }
104
74
  async withSpan(params, fn, thisArg, ...args) {
@@ -114,21 +84,18 @@ var LiveInteraction = class {
114
84
  if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
115
85
  console.log("[raindrop] using withSpan in liveInteraction");
116
86
  }
117
- const raindropContext = setRaindropContext(import_api2.context.active(), properties);
118
- return import_api2.context.with(raindropContext, () => {
119
- return traceloop.withTask(
120
- {
121
- name: taskName,
122
- associationProperties: properties,
123
- inputParameters,
124
- traceContent: params.traceContent,
125
- suppressTracing: params.suppressTracing
126
- },
127
- fn,
128
- thisArg,
129
- ...args
130
- );
131
- });
87
+ return traceloop.withTask(
88
+ {
89
+ name: taskName,
90
+ associationProperties: properties,
91
+ inputParameters,
92
+ traceContent: params.traceContent,
93
+ suppressTracing: params.suppressTracing
94
+ },
95
+ fn,
96
+ thisArg,
97
+ ...args
98
+ );
132
99
  }
133
100
  async withTool(params, fn, thisArg, ...args) {
134
101
  var _a;
@@ -141,22 +108,19 @@ var LiveInteraction = class {
141
108
  if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
142
109
  console.log("[raindrop] using withTool in liveInteraction");
143
110
  }
144
- const raindropContext = setRaindropContext(import_api2.context.active(), properties);
145
- return import_api2.context.with(raindropContext, () => {
146
- return traceloop.withTool(
147
- {
148
- name: toolName,
149
- associationProperties: properties,
150
- inputParameters: inputParams,
151
- version: params.version,
152
- traceContent: params.traceContent,
153
- suppressTracing: params.suppressTracing
154
- },
155
- fn,
156
- thisArg,
157
- ...args
158
- );
159
- });
111
+ return traceloop.withTool(
112
+ {
113
+ name: toolName,
114
+ associationProperties: properties,
115
+ inputParameters: inputParams,
116
+ version: params.version,
117
+ traceContent: params.traceContent,
118
+ suppressTracing: params.suppressTracing
119
+ },
120
+ fn,
121
+ thisArg,
122
+ ...args
123
+ );
160
124
  }
161
125
  startSpan(params) {
162
126
  const { name, properties = {} } = params;
@@ -337,10 +301,10 @@ var activeInteractions = new import_weakref.WeakValueMap();
337
301
  var activeInteractionsByEventId = new import_weakref.WeakValueMap();
338
302
  function getCurrentTraceId() {
339
303
  var _a;
340
- return (_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId;
304
+ return (_a = import_api2.trace.getSpan(import_api2.context.active())) == null ? void 0 : _a.spanContext().traceId;
341
305
  }
342
306
  var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
343
- const { logLevel, useExternalOtel, tracingEnabled, ...otherOptions } = options;
307
+ const { logLevel, useExternalOtel, tracingEnabled, disableBatching, ...otherOptions } = options;
344
308
  if (isDebug) {
345
309
  const mode = useExternalOtel ? "(external OTEL mode)" : tracingEnabled === false ? "(tracing disabled)" : "";
346
310
  console.log("[raindrop] Initializing tracing", mode);
@@ -374,24 +338,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
374
338
  apiKey: writeKey,
375
339
  ...otherOptions,
376
340
  logLevel,
377
- tracingEnabled: tracingEnabled !== false
341
+ tracingEnabled: tracingEnabled !== false,
342
+ disableBatch: disableBatching
378
343
  });
379
344
  traceloopInitialized = true;
380
- if (tracingEnabled !== false) {
381
- try {
382
- const provider = import_api3.trace.getTracerProvider();
383
- if (provider && typeof provider.addSpanProcessor === "function") {
384
- provider.addSpanProcessor(new RaindropContextSpanProcessor());
385
- if (isDebug) {
386
- console.log("[raindrop] Registered RaindropContextSpanProcessor for Vercel AI SDK support");
387
- }
388
- }
389
- } catch (e) {
390
- if (isDebug) {
391
- console.log("[raindrop] Could not register context span processor:", e);
392
- }
393
- }
394
- }
395
345
  }
396
346
  } catch (error) {
397
347
  console.warn(
@@ -441,7 +391,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
441
391
  * @example
442
392
  * ```typescript
443
393
  * const sdk = new NodeSDK({
444
- * spanProcessors: [raindrop.createSpanProcessor(), yourOtherProcessor],
394
+ * spanProcessors: [raindrop.createSpanProcessor()],
445
395
  * instrumentations: raindrop.getInstrumentations(),
446
396
  * });
447
397
  * ```
@@ -465,28 +415,12 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
465
415
  }
466
416
  };
467
417
  }
468
- const traceloopProcessor = traceloop3.createSpanProcessor({
418
+ return traceloop3.createSpanProcessor({
469
419
  baseUrl: apiUrl,
470
420
  apiKey: writeKey,
421
+ disableBatch: disableBatching,
471
422
  ...processorOptions != null ? processorOptions : {}
472
423
  });
473
- const contextProcessor = new RaindropContextSpanProcessor();
474
- return {
475
- onStart(span, parentContext) {
476
- contextProcessor.onStart(span, parentContext);
477
- traceloopProcessor.onStart(span, parentContext);
478
- },
479
- onEnd(span) {
480
- contextProcessor.onEnd(span);
481
- traceloopProcessor.onEnd(span);
482
- },
483
- async forceFlush() {
484
- await traceloopProcessor.forceFlush();
485
- },
486
- async shutdown() {
487
- await traceloopProcessor.shutdown();
488
- }
489
- };
490
424
  },
491
425
  begin(traceContext) {
492
426
  if (!traceContext.eventId) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  tracing
3
- } from "../chunk-CCT3KBLT.mjs";
3
+ } from "../chunk-7PZNI6M6.mjs";
4
4
 
5
5
  // src/tracing/index.ts
6
6
  function initTracing() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raindrop-ai",
3
- "version": "0.0.75",
3
+ "version": "0.0.76-otelv2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -46,7 +46,6 @@
46
46
  "@dawn-analytics/redact-pii": "0.1.2",
47
47
  "@opentelemetry/api": "^1.9.0",
48
48
  "@opentelemetry/resources": "^2.0.1",
49
- "@traceloop/node-server-sdk": "0.19.0-otel-v1",
50
49
  "weakref": "^0.2.1",
51
50
  "zod": "^3.23.8"
52
51
  },
@@ -85,5 +84,8 @@
85
84
  "resolve": true
86
85
  },
87
86
  "clean": true
87
+ },
88
+ "optionalDependencies": {
89
+ "@traceloop/node-server-sdk": "0.22.2"
88
90
  }
89
91
  }