raindrop-ai 0.0.74 → 0.0.75-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.
- package/dist/{chunk-VLA74EMW.mjs → chunk-CCT3KBLT.mjs} +124 -38
- package/dist/index.d.mts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +129 -43
- package/dist/index.mjs +2 -2
- package/dist/tracing/index.js +125 -39
- package/dist/tracing/index.mjs +1 -1
- package/package.json +4 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/tracing/tracer-core.ts
|
|
2
|
-
import { context, trace as trace2 } from "@opentelemetry/api";
|
|
2
|
+
import { context as context2, trace as trace2 } from "@opentelemetry/api";
|
|
3
3
|
import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
|
|
4
4
|
import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
|
|
5
5
|
import { ChromaDBInstrumentation } from "@traceloop/instrumentation-chromadb";
|
|
@@ -16,23 +16,53 @@ import * as traceloop3 from "@traceloop/node-server-sdk";
|
|
|
16
16
|
import { WeakValueMap } from "weakref";
|
|
17
17
|
|
|
18
18
|
// src/tracing/liveInteraction.ts
|
|
19
|
-
import { trace } from "@opentelemetry/api";
|
|
19
|
+
import { context, trace } from "@opentelemetry/api";
|
|
20
20
|
import * as traceloop from "@traceloop/node-server-sdk";
|
|
21
|
-
|
|
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
|
+
function getPropertiesFromContext(context3) {
|
|
22
52
|
const properties = {
|
|
23
|
-
...
|
|
24
|
-
...
|
|
25
|
-
...
|
|
26
|
-
...
|
|
53
|
+
...context3.userId && { user_id: context3.userId },
|
|
54
|
+
...context3.convoId && { convo_id: context3.convoId },
|
|
55
|
+
...context3.eventId && { event_id: context3.eventId },
|
|
56
|
+
...context3.properties || {}
|
|
27
57
|
};
|
|
28
|
-
if (
|
|
29
|
-
properties.attachments = JSON.stringify(
|
|
58
|
+
if (context3.attachments && context3.attachments.length > 0) {
|
|
59
|
+
properties.attachments = JSON.stringify(context3.attachments);
|
|
30
60
|
}
|
|
31
61
|
return properties;
|
|
32
62
|
}
|
|
33
63
|
var LiveInteraction = class {
|
|
34
|
-
constructor(
|
|
35
|
-
this.context =
|
|
64
|
+
constructor(context3, traceId, analytics) {
|
|
65
|
+
this.context = context3;
|
|
36
66
|
this.analytics = analytics;
|
|
37
67
|
this.tracer = trace.getTracer("traceloop.tracer");
|
|
38
68
|
this.traceId = traceId;
|
|
@@ -50,18 +80,21 @@ var LiveInteraction = class {
|
|
|
50
80
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
51
81
|
console.log("[raindrop] using withSpan in liveInteraction");
|
|
52
82
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
});
|
|
65
98
|
}
|
|
66
99
|
async withTool(params, fn, thisArg, ...args) {
|
|
67
100
|
var _a;
|
|
@@ -74,19 +107,22 @@ var LiveInteraction = class {
|
|
|
74
107
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
75
108
|
console.log("[raindrop] using withTool in liveInteraction");
|
|
76
109
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
});
|
|
90
126
|
}
|
|
91
127
|
startSpan(params) {
|
|
92
128
|
const { name, properties = {} } = params;
|
|
@@ -133,6 +169,24 @@ var LiveInteraction = class {
|
|
|
133
169
|
input
|
|
134
170
|
});
|
|
135
171
|
}
|
|
172
|
+
vercelAiSdkMetadata() {
|
|
173
|
+
const metadata = {};
|
|
174
|
+
if (this.context.userId) {
|
|
175
|
+
metadata["traceloop.association.properties.user_id"] = this.context.userId;
|
|
176
|
+
}
|
|
177
|
+
if (this.context.convoId) {
|
|
178
|
+
metadata["traceloop.association.properties.convo_id"] = this.context.convoId;
|
|
179
|
+
}
|
|
180
|
+
if (this.context.eventId) {
|
|
181
|
+
metadata["traceloop.association.properties.event_id"] = this.context.eventId;
|
|
182
|
+
}
|
|
183
|
+
if (this.context.properties) {
|
|
184
|
+
for (const [key, value] of Object.entries(this.context.properties)) {
|
|
185
|
+
metadata[`traceloop.association.properties.${key}`] = value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return metadata;
|
|
189
|
+
}
|
|
136
190
|
finish(resultEvent) {
|
|
137
191
|
var _a;
|
|
138
192
|
if (this.traceId) {
|
|
@@ -249,7 +303,7 @@ var activeInteractions = new WeakValueMap();
|
|
|
249
303
|
var activeInteractionsByEventId = new WeakValueMap();
|
|
250
304
|
function getCurrentTraceId() {
|
|
251
305
|
var _a;
|
|
252
|
-
return (_a = trace2.getSpan(
|
|
306
|
+
return (_a = trace2.getSpan(context2.active())) == null ? void 0 : _a.spanContext().traceId;
|
|
253
307
|
}
|
|
254
308
|
var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
255
309
|
const { logLevel, useExternalOtel, tracingEnabled, ...otherOptions } = options;
|
|
@@ -289,6 +343,21 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
289
343
|
tracingEnabled: tracingEnabled !== false
|
|
290
344
|
});
|
|
291
345
|
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
|
+
}
|
|
292
361
|
}
|
|
293
362
|
} catch (error) {
|
|
294
363
|
console.warn(
|
|
@@ -362,11 +431,28 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
362
431
|
}
|
|
363
432
|
};
|
|
364
433
|
}
|
|
365
|
-
|
|
434
|
+
const traceloopProcessor = traceloop3.createSpanProcessor({
|
|
366
435
|
baseUrl: apiUrl,
|
|
367
436
|
apiKey: writeKey,
|
|
368
437
|
...processorOptions != null ? processorOptions : {}
|
|
369
438
|
});
|
|
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
|
+
};
|
|
370
456
|
},
|
|
371
457
|
begin(traceContext) {
|
|
372
458
|
if (!traceContext.eventId) {
|
package/dist/index.d.mts
CHANGED
|
@@ -380,6 +380,37 @@ type Interaction = {
|
|
|
380
380
|
* interaction.end("I can help you with various tasks. Here are some examples...");
|
|
381
381
|
*/
|
|
382
382
|
finish(resultEvent: FinishInteractionOptions): void;
|
|
383
|
+
/**
|
|
384
|
+
* Returns metadata for Vercel AI SDK's experimental_telemetry option.
|
|
385
|
+
*
|
|
386
|
+
* Use this when making Vercel AI SDK calls outside of withSpan() to ensure
|
|
387
|
+
* the interaction's properties (userId, convoId, eventId) are attached to the spans.
|
|
388
|
+
*
|
|
389
|
+
* When using withSpan(), this is handled automatically via context propagation.
|
|
390
|
+
* This method is a fallback for cases where you can't use withSpan().
|
|
391
|
+
*
|
|
392
|
+
* @returns Metadata object with traceloop association properties
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const interaction = raindrop.begin({ userId: "user-123", convoId: "convo-456" });
|
|
397
|
+
*
|
|
398
|
+
* // Option 1: Use withSpan (recommended - automatic context propagation)
|
|
399
|
+
* await interaction.withSpan("my-task", async () => {
|
|
400
|
+
* await generateText({ experimental_telemetry: { isEnabled: true }, ... });
|
|
401
|
+
* });
|
|
402
|
+
*
|
|
403
|
+
* // Option 2: Use vercelAiSdkMetadata (fallback when withSpan isn't possible)
|
|
404
|
+
* await generateText({
|
|
405
|
+
* experimental_telemetry: {
|
|
406
|
+
* isEnabled: true,
|
|
407
|
+
* metadata: interaction.vercelAiSdkMetadata(),
|
|
408
|
+
* },
|
|
409
|
+
* ...
|
|
410
|
+
* });
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
vercelAiSdkMetadata(): Record<string, string>;
|
|
383
414
|
};
|
|
384
415
|
type Tracer = {
|
|
385
416
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -380,6 +380,37 @@ type Interaction = {
|
|
|
380
380
|
* interaction.end("I can help you with various tasks. Here are some examples...");
|
|
381
381
|
*/
|
|
382
382
|
finish(resultEvent: FinishInteractionOptions): void;
|
|
383
|
+
/**
|
|
384
|
+
* Returns metadata for Vercel AI SDK's experimental_telemetry option.
|
|
385
|
+
*
|
|
386
|
+
* Use this when making Vercel AI SDK calls outside of withSpan() to ensure
|
|
387
|
+
* the interaction's properties (userId, convoId, eventId) are attached to the spans.
|
|
388
|
+
*
|
|
389
|
+
* When using withSpan(), this is handled automatically via context propagation.
|
|
390
|
+
* This method is a fallback for cases where you can't use withSpan().
|
|
391
|
+
*
|
|
392
|
+
* @returns Metadata object with traceloop association properties
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const interaction = raindrop.begin({ userId: "user-123", convoId: "convo-456" });
|
|
397
|
+
*
|
|
398
|
+
* // Option 1: Use withSpan (recommended - automatic context propagation)
|
|
399
|
+
* await interaction.withSpan("my-task", async () => {
|
|
400
|
+
* await generateText({ experimental_telemetry: { isEnabled: true }, ... });
|
|
401
|
+
* });
|
|
402
|
+
*
|
|
403
|
+
* // Option 2: Use vercelAiSdkMetadata (fallback when withSpan isn't possible)
|
|
404
|
+
* await generateText({
|
|
405
|
+
* experimental_telemetry: {
|
|
406
|
+
* isEnabled: true,
|
|
407
|
+
* metadata: interaction.vercelAiSdkMetadata(),
|
|
408
|
+
* },
|
|
409
|
+
* ...
|
|
410
|
+
* });
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
vercelAiSdkMetadata(): Record<string, string>;
|
|
383
414
|
};
|
|
384
415
|
type Tracer = {
|
|
385
416
|
/**
|
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.
|
|
141
|
+
version: "0.0.75",
|
|
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
|
|
319
|
+
var import_api3 = 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,25 +330,55 @@ 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
|
|
333
|
+
var import_api2 = require("@opentelemetry/api");
|
|
334
334
|
var traceloop = __toESM(require("@traceloop/node-server-sdk"));
|
|
335
|
-
|
|
335
|
+
|
|
336
|
+
// src/tracing/raindropSpanProcessor.ts
|
|
337
|
+
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
|
|
365
|
+
function getPropertiesFromContext(context3) {
|
|
336
366
|
const properties = {
|
|
337
|
-
...
|
|
338
|
-
...
|
|
339
|
-
...
|
|
340
|
-
...
|
|
367
|
+
...context3.userId && { user_id: context3.userId },
|
|
368
|
+
...context3.convoId && { convo_id: context3.convoId },
|
|
369
|
+
...context3.eventId && { event_id: context3.eventId },
|
|
370
|
+
...context3.properties || {}
|
|
341
371
|
};
|
|
342
|
-
if (
|
|
343
|
-
properties.attachments = JSON.stringify(
|
|
372
|
+
if (context3.attachments && context3.attachments.length > 0) {
|
|
373
|
+
properties.attachments = JSON.stringify(context3.attachments);
|
|
344
374
|
}
|
|
345
375
|
return properties;
|
|
346
376
|
}
|
|
347
377
|
var LiveInteraction = class {
|
|
348
|
-
constructor(
|
|
349
|
-
this.context =
|
|
378
|
+
constructor(context3, traceId, analytics) {
|
|
379
|
+
this.context = context3;
|
|
350
380
|
this.analytics = analytics;
|
|
351
|
-
this.tracer =
|
|
381
|
+
this.tracer = import_api2.trace.getTracer("traceloop.tracer");
|
|
352
382
|
this.traceId = traceId;
|
|
353
383
|
}
|
|
354
384
|
async withSpan(params, fn, thisArg, ...args) {
|
|
@@ -364,18 +394,21 @@ var LiveInteraction = class {
|
|
|
364
394
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
365
395
|
console.log("[raindrop] using withSpan in liveInteraction");
|
|
366
396
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
+
});
|
|
379
412
|
}
|
|
380
413
|
async withTool(params, fn, thisArg, ...args) {
|
|
381
414
|
var _a;
|
|
@@ -388,19 +421,22 @@ var LiveInteraction = class {
|
|
|
388
421
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
389
422
|
console.log("[raindrop] using withTool in liveInteraction");
|
|
390
423
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
+
});
|
|
404
440
|
}
|
|
405
441
|
startSpan(params) {
|
|
406
442
|
const { name, properties = {} } = params;
|
|
@@ -447,6 +483,24 @@ var LiveInteraction = class {
|
|
|
447
483
|
input
|
|
448
484
|
});
|
|
449
485
|
}
|
|
486
|
+
vercelAiSdkMetadata() {
|
|
487
|
+
const metadata = {};
|
|
488
|
+
if (this.context.userId) {
|
|
489
|
+
metadata["traceloop.association.properties.user_id"] = this.context.userId;
|
|
490
|
+
}
|
|
491
|
+
if (this.context.convoId) {
|
|
492
|
+
metadata["traceloop.association.properties.convo_id"] = this.context.convoId;
|
|
493
|
+
}
|
|
494
|
+
if (this.context.eventId) {
|
|
495
|
+
metadata["traceloop.association.properties.event_id"] = this.context.eventId;
|
|
496
|
+
}
|
|
497
|
+
if (this.context.properties) {
|
|
498
|
+
for (const [key, value] of Object.entries(this.context.properties)) {
|
|
499
|
+
metadata[`traceloop.association.properties.${key}`] = value;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return metadata;
|
|
503
|
+
}
|
|
450
504
|
finish(resultEvent) {
|
|
451
505
|
var _a;
|
|
452
506
|
if (this.traceId) {
|
|
@@ -563,7 +617,7 @@ var activeInteractions = new import_weakref.WeakValueMap();
|
|
|
563
617
|
var activeInteractionsByEventId = new import_weakref.WeakValueMap();
|
|
564
618
|
function getCurrentTraceId() {
|
|
565
619
|
var _a;
|
|
566
|
-
return (_a =
|
|
620
|
+
return (_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId;
|
|
567
621
|
}
|
|
568
622
|
var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
569
623
|
const { logLevel, useExternalOtel, tracingEnabled, ...otherOptions } = options;
|
|
@@ -603,6 +657,21 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
603
657
|
tracingEnabled: tracingEnabled !== false
|
|
604
658
|
});
|
|
605
659
|
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
|
+
}
|
|
606
675
|
}
|
|
607
676
|
} catch (error) {
|
|
608
677
|
console.warn(
|
|
@@ -676,11 +745,28 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
676
745
|
}
|
|
677
746
|
};
|
|
678
747
|
}
|
|
679
|
-
|
|
748
|
+
const traceloopProcessor = traceloop3.createSpanProcessor({
|
|
680
749
|
baseUrl: apiUrl,
|
|
681
750
|
apiKey: writeKey,
|
|
682
751
|
...processorOptions != null ? processorOptions : {}
|
|
683
752
|
});
|
|
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
|
+
};
|
|
684
770
|
},
|
|
685
771
|
begin(traceContext) {
|
|
686
772
|
if (!traceContext.eventId) {
|
|
@@ -1167,7 +1253,7 @@ var Raindrop = class {
|
|
|
1167
1253
|
}
|
|
1168
1254
|
getContext() {
|
|
1169
1255
|
const runtime = detectRuntime();
|
|
1170
|
-
const
|
|
1256
|
+
const context3 = {
|
|
1171
1257
|
library: {
|
|
1172
1258
|
name: package_default.name,
|
|
1173
1259
|
version: package_default.version
|
|
@@ -1177,9 +1263,9 @@ var Raindrop = class {
|
|
|
1177
1263
|
}
|
|
1178
1264
|
};
|
|
1179
1265
|
if (runtime === "node") {
|
|
1180
|
-
|
|
1266
|
+
context3.metadata.nodeVersion = process.version;
|
|
1181
1267
|
}
|
|
1182
|
-
return
|
|
1268
|
+
return context3;
|
|
1183
1269
|
}
|
|
1184
1270
|
formatZodError(error) {
|
|
1185
1271
|
return error.issues.map((issue) => `(path: ${issue.path.join(".")}): ${issue.message}`).join(", ");
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
tracing
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CCT3KBLT.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.
|
|
107
|
+
version: "0.0.75",
|
|
108
108
|
main: "dist/index.js",
|
|
109
109
|
module: "dist/index.mjs",
|
|
110
110
|
types: "dist/index.d.ts",
|
package/dist/tracing/index.js
CHANGED
|
@@ -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
|
|
39
|
+
var import_api3 = 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,25 +50,55 @@ 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
|
|
53
|
+
var import_api2 = require("@opentelemetry/api");
|
|
54
54
|
var traceloop = __toESM(require("@traceloop/node-server-sdk"));
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
// src/tracing/raindropSpanProcessor.ts
|
|
57
|
+
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
|
|
85
|
+
function getPropertiesFromContext(context3) {
|
|
56
86
|
const properties = {
|
|
57
|
-
...
|
|
58
|
-
...
|
|
59
|
-
...
|
|
60
|
-
...
|
|
87
|
+
...context3.userId && { user_id: context3.userId },
|
|
88
|
+
...context3.convoId && { convo_id: context3.convoId },
|
|
89
|
+
...context3.eventId && { event_id: context3.eventId },
|
|
90
|
+
...context3.properties || {}
|
|
61
91
|
};
|
|
62
|
-
if (
|
|
63
|
-
properties.attachments = JSON.stringify(
|
|
92
|
+
if (context3.attachments && context3.attachments.length > 0) {
|
|
93
|
+
properties.attachments = JSON.stringify(context3.attachments);
|
|
64
94
|
}
|
|
65
95
|
return properties;
|
|
66
96
|
}
|
|
67
97
|
var LiveInteraction = class {
|
|
68
|
-
constructor(
|
|
69
|
-
this.context =
|
|
98
|
+
constructor(context3, traceId, analytics) {
|
|
99
|
+
this.context = context3;
|
|
70
100
|
this.analytics = analytics;
|
|
71
|
-
this.tracer =
|
|
101
|
+
this.tracer = import_api2.trace.getTracer("traceloop.tracer");
|
|
72
102
|
this.traceId = traceId;
|
|
73
103
|
}
|
|
74
104
|
async withSpan(params, fn, thisArg, ...args) {
|
|
@@ -84,18 +114,21 @@ var LiveInteraction = class {
|
|
|
84
114
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
85
115
|
console.log("[raindrop] using withSpan in liveInteraction");
|
|
86
116
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
});
|
|
99
132
|
}
|
|
100
133
|
async withTool(params, fn, thisArg, ...args) {
|
|
101
134
|
var _a;
|
|
@@ -108,19 +141,22 @@ var LiveInteraction = class {
|
|
|
108
141
|
if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
|
|
109
142
|
console.log("[raindrop] using withTool in liveInteraction");
|
|
110
143
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
+
});
|
|
124
160
|
}
|
|
125
161
|
startSpan(params) {
|
|
126
162
|
const { name, properties = {} } = params;
|
|
@@ -167,6 +203,24 @@ var LiveInteraction = class {
|
|
|
167
203
|
input
|
|
168
204
|
});
|
|
169
205
|
}
|
|
206
|
+
vercelAiSdkMetadata() {
|
|
207
|
+
const metadata = {};
|
|
208
|
+
if (this.context.userId) {
|
|
209
|
+
metadata["traceloop.association.properties.user_id"] = this.context.userId;
|
|
210
|
+
}
|
|
211
|
+
if (this.context.convoId) {
|
|
212
|
+
metadata["traceloop.association.properties.convo_id"] = this.context.convoId;
|
|
213
|
+
}
|
|
214
|
+
if (this.context.eventId) {
|
|
215
|
+
metadata["traceloop.association.properties.event_id"] = this.context.eventId;
|
|
216
|
+
}
|
|
217
|
+
if (this.context.properties) {
|
|
218
|
+
for (const [key, value] of Object.entries(this.context.properties)) {
|
|
219
|
+
metadata[`traceloop.association.properties.${key}`] = value;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return metadata;
|
|
223
|
+
}
|
|
170
224
|
finish(resultEvent) {
|
|
171
225
|
var _a;
|
|
172
226
|
if (this.traceId) {
|
|
@@ -283,7 +337,7 @@ var activeInteractions = new import_weakref.WeakValueMap();
|
|
|
283
337
|
var activeInteractionsByEventId = new import_weakref.WeakValueMap();
|
|
284
338
|
function getCurrentTraceId() {
|
|
285
339
|
var _a;
|
|
286
|
-
return (_a =
|
|
340
|
+
return (_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId;
|
|
287
341
|
}
|
|
288
342
|
var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
289
343
|
const { logLevel, useExternalOtel, tracingEnabled, ...otherOptions } = options;
|
|
@@ -323,6 +377,21 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
323
377
|
tracingEnabled: tracingEnabled !== false
|
|
324
378
|
});
|
|
325
379
|
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
|
+
}
|
|
326
395
|
}
|
|
327
396
|
} catch (error) {
|
|
328
397
|
console.warn(
|
|
@@ -396,11 +465,28 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
396
465
|
}
|
|
397
466
|
};
|
|
398
467
|
}
|
|
399
|
-
|
|
468
|
+
const traceloopProcessor = traceloop3.createSpanProcessor({
|
|
400
469
|
baseUrl: apiUrl,
|
|
401
470
|
apiKey: writeKey,
|
|
402
471
|
...processorOptions != null ? processorOptions : {}
|
|
403
472
|
});
|
|
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
|
+
};
|
|
404
490
|
},
|
|
405
491
|
begin(traceContext) {
|
|
406
492
|
if (!traceContext.eventId) {
|
package/dist/tracing/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raindrop-ai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.75-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
|
}
|