raindrop-ai 0.3.0 → 0.3.1
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-5Y3LWBKV.mjs → chunk-4TM4IWHB.mjs} +192 -77
- package/dist/{index-DBdUrUXc.d.mts → index-DuXeVnSq.d.mts} +32 -1
- package/dist/{index-DBdUrUXc.d.ts → index-DuXeVnSq.d.ts} +32 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +224 -74
- package/dist/index.mjs +36 -1
- package/dist/tracing/index.d.mts +6 -16
- package/dist/tracing/index.d.ts +6 -16
- package/dist/tracing/index.js +208 -91
- package/dist/tracing/index.mjs +1 -1
- package/package.json +2 -2
package/dist/tracing/index.js
CHANGED
|
@@ -35,28 +35,11 @@ __export(tracing_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(tracing_exports);
|
|
37
37
|
|
|
38
|
-
// src/lib/inject-als.ts
|
|
39
|
-
var import_node_async_hooks = require("async_hooks");
|
|
40
|
-
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
|
41
|
-
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = import_node_async_hooks.AsyncLocalStorage;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
38
|
// src/tracing/tracer-core.ts
|
|
45
39
|
var import_api5 = require("@opentelemetry/api");
|
|
46
40
|
var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
|
|
47
|
-
var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
|
|
48
|
-
var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
|
|
49
|
-
var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
|
|
50
|
-
var import_instrumentation_cohere = require("@traceloop/instrumentation-cohere");
|
|
51
|
-
var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
|
|
52
|
-
var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
|
|
53
|
-
var import_instrumentation_qdrant = require("@traceloop/instrumentation-qdrant");
|
|
54
|
-
var import_instrumentation_together = require("@traceloop/instrumentation-together");
|
|
55
|
-
var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
|
|
56
|
-
var traceloop4 = __toESM(require("@traceloop/node-server-sdk"));
|
|
57
|
-
var import_weakref = require("weakref");
|
|
58
41
|
|
|
59
|
-
// ../core/dist/chunk-
|
|
42
|
+
// ../core/dist/chunk-3V4MIA75.js
|
|
60
43
|
function normalizeFeatureFlags(input) {
|
|
61
44
|
if (Array.isArray(input)) {
|
|
62
45
|
return Object.fromEntries(input.map((name) => [name, "true"]));
|
|
@@ -593,6 +576,20 @@ function stringifyBounded(value, limit) {
|
|
|
593
576
|
}
|
|
594
577
|
return json.length <= max ? json : truncateToLimit(json, max);
|
|
595
578
|
}
|
|
579
|
+
function attrString(key, value) {
|
|
580
|
+
if (value === void 0) return void 0;
|
|
581
|
+
return { key, value: { stringValue: value } };
|
|
582
|
+
}
|
|
583
|
+
function attrInt(key, value) {
|
|
584
|
+
if (value === void 0) return void 0;
|
|
585
|
+
if (!Number.isFinite(value)) return void 0;
|
|
586
|
+
return { key, value: { intValue: String(Math.trunc(value)) } };
|
|
587
|
+
}
|
|
588
|
+
function attrDouble(key, value) {
|
|
589
|
+
if (value === void 0) return void 0;
|
|
590
|
+
if (!Number.isFinite(value)) return void 0;
|
|
591
|
+
return { key, value: { doubleValue: value } };
|
|
592
|
+
}
|
|
596
593
|
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
597
594
|
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
598
595
|
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
@@ -696,6 +693,7 @@ function projectIdHeaders(projectId) {
|
|
|
696
693
|
var SHUTDOWN_DEADLINE_MS = 1e4;
|
|
697
694
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
698
695
|
var MODEL_USAGE_ATTRIBUTES = {
|
|
696
|
+
usageSource: "raindrop.usage.source",
|
|
699
697
|
providerName: "gen_ai.provider.name",
|
|
700
698
|
requestModel: "gen_ai.request.model",
|
|
701
699
|
responseModel: "gen_ai.response.model",
|
|
@@ -704,6 +702,7 @@ var MODEL_USAGE_ATTRIBUTES = {
|
|
|
704
702
|
reasoningTokens: "gen_ai.usage.reasoning_tokens",
|
|
705
703
|
cacheReadInputTokens: "gen_ai.usage.cache_read_input_tokens",
|
|
706
704
|
cacheWriteInputTokens: "gen_ai.usage.cache_write_input_tokens",
|
|
705
|
+
providerReportedCost: "gen_ai.usage.provider_reported_cost",
|
|
707
706
|
nonCachedInputTokens: "raindrop.usage.input_tokens.non_cached",
|
|
708
707
|
nonReasoningOutputTokens: "raindrop.usage.output_tokens.non_reasoning",
|
|
709
708
|
totalOutputTokens: "raindrop.usage.output_tokens.total",
|
|
@@ -711,6 +710,47 @@ var MODEL_USAGE_ATTRIBUTES = {
|
|
|
711
710
|
cacheReadTokens: "raindrop.usage.input_tokens.cache_read",
|
|
712
711
|
cacheWriteTokens: "raindrop.usage.input_tokens.cache_write"
|
|
713
712
|
};
|
|
713
|
+
var MODEL_PROVIDER_NAMES = [
|
|
714
|
+
["google.vertex.anthropic", "google-vertex"],
|
|
715
|
+
["google.vertex_ai", "google-vertex"],
|
|
716
|
+
["google.vertex", "google-vertex"],
|
|
717
|
+
["gcp.vertex_ai", "google-vertex"],
|
|
718
|
+
["gcp.gemini", "google"],
|
|
719
|
+
["google_vertexai", "google-vertex"],
|
|
720
|
+
["vertex.anthropic", "google-vertex"],
|
|
721
|
+
["amazon-bedrock", "amazon-bedrock"],
|
|
722
|
+
["aws.bedrock", "amazon-bedrock"],
|
|
723
|
+
["bedrock", "amazon-bedrock"],
|
|
724
|
+
["anthropic", "anthropic"],
|
|
725
|
+
["openai", "openai"],
|
|
726
|
+
["google", "google"],
|
|
727
|
+
["az.ai.openai", "azure"],
|
|
728
|
+
["azure", "azure"],
|
|
729
|
+
["openrouter", "openrouter"]
|
|
730
|
+
];
|
|
731
|
+
function canonicalModelProvider(provider) {
|
|
732
|
+
var _a;
|
|
733
|
+
const normalizedProvider = provider.trim().toLowerCase();
|
|
734
|
+
if (normalizedProvider === "gateway") return "vercel";
|
|
735
|
+
const match = MODEL_PROVIDER_NAMES.find(
|
|
736
|
+
([family]) => normalizedProvider === family || normalizedProvider.startsWith(`${family}.`)
|
|
737
|
+
);
|
|
738
|
+
return (_a = match == null ? void 0 : match[1]) != null ? _a : normalizedProvider;
|
|
739
|
+
}
|
|
740
|
+
function tokenCount(value) {
|
|
741
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
742
|
+
}
|
|
743
|
+
function buildRawModelUsageAttributes(usage) {
|
|
744
|
+
const providerReportedCost = typeof usage.providerReportedCost === "number" && Number.isFinite(usage.providerReportedCost) && usage.providerReportedCost >= 0 ? usage.providerReportedCost : void 0;
|
|
745
|
+
return [
|
|
746
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.inputTokens, tokenCount(usage.inputTokens)),
|
|
747
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.outputTokens, tokenCount(usage.outputTokens)),
|
|
748
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.reasoningTokens, tokenCount(usage.reasoningTokens)),
|
|
749
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.cacheReadInputTokens, tokenCount(usage.cacheReadInputTokens)),
|
|
750
|
+
attrInt(MODEL_USAGE_ATTRIBUTES.cacheWriteInputTokens, tokenCount(usage.cacheWriteInputTokens)),
|
|
751
|
+
attrDouble(MODEL_USAGE_ATTRIBUTES.providerReportedCost, providerReportedCost)
|
|
752
|
+
].filter((attribute) => attribute !== void 0);
|
|
753
|
+
}
|
|
714
754
|
var STRING_ALIASES = {
|
|
715
755
|
[MODEL_USAGE_ATTRIBUTES.requestModel]: ["ai.model.id", "ai.model"]
|
|
716
756
|
};
|
|
@@ -1051,6 +1091,25 @@ function installTracingSuppressionHook() {
|
|
|
1051
1091
|
}
|
|
1052
1092
|
installTracingSuppressionHook();
|
|
1053
1093
|
|
|
1094
|
+
// src/tracing/tracer-core.ts
|
|
1095
|
+
var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic");
|
|
1096
|
+
var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
|
|
1097
|
+
var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
|
|
1098
|
+
var import_instrumentation_cohere = require("@traceloop/instrumentation-cohere");
|
|
1099
|
+
var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
|
|
1100
|
+
var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
|
|
1101
|
+
var import_instrumentation_qdrant = require("@traceloop/instrumentation-qdrant");
|
|
1102
|
+
var import_instrumentation_together = require("@traceloop/instrumentation-together");
|
|
1103
|
+
var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
|
|
1104
|
+
var traceloop4 = __toESM(require("@traceloop/node-server-sdk"));
|
|
1105
|
+
var import_weakref = require("weakref");
|
|
1106
|
+
|
|
1107
|
+
// src/lib/inject-als.ts
|
|
1108
|
+
var import_node_async_hooks = require("async_hooks");
|
|
1109
|
+
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
|
1110
|
+
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = import_node_async_hooks.AsyncLocalStorage;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1054
1113
|
// src/tracing/direct/http.ts
|
|
1055
1114
|
function wait2(ms) {
|
|
1056
1115
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -1207,7 +1266,7 @@ function base64ToHex2(base64) {
|
|
|
1207
1266
|
// package.json
|
|
1208
1267
|
var package_default = {
|
|
1209
1268
|
name: "raindrop-ai",
|
|
1210
|
-
version: "0.3.
|
|
1269
|
+
version: "0.3.1",
|
|
1211
1270
|
main: "dist/index.js",
|
|
1212
1271
|
module: "dist/index.mjs",
|
|
1213
1272
|
types: "dist/index.d.ts",
|
|
@@ -1632,7 +1691,7 @@ var DirectTraceShipper = class {
|
|
|
1632
1691
|
* so spans still appear as children in the trace tree.
|
|
1633
1692
|
*/
|
|
1634
1693
|
sendSpan(params) {
|
|
1635
|
-
var _a, _b;
|
|
1694
|
+
var _a, _b, _c;
|
|
1636
1695
|
if (!this.enabled) return;
|
|
1637
1696
|
let traceIdB64 = params.traceId;
|
|
1638
1697
|
let parentSpanIdB64 = params.parentSpanId;
|
|
@@ -1676,6 +1735,7 @@ var DirectTraceShipper = class {
|
|
|
1676
1735
|
})) {
|
|
1677
1736
|
attributes.push(attrString2(key, value));
|
|
1678
1737
|
}
|
|
1738
|
+
attributes.push(...(_c = params.otlpAttributes) != null ? _c : []);
|
|
1679
1739
|
let status;
|
|
1680
1740
|
if (params.error) {
|
|
1681
1741
|
status = { code: 2, message: params.error };
|
|
@@ -1827,9 +1887,62 @@ var DirectTraceShipper = class {
|
|
|
1827
1887
|
}
|
|
1828
1888
|
};
|
|
1829
1889
|
|
|
1890
|
+
// src/tracing/exit-flush.ts
|
|
1891
|
+
var traceloop = __toESM(require("@traceloop/node-server-sdk"));
|
|
1892
|
+
var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
|
|
1893
|
+
function getState2() {
|
|
1894
|
+
const holder = globalThis;
|
|
1895
|
+
let state = holder[STATE_KEY2];
|
|
1896
|
+
if (!state) {
|
|
1897
|
+
state = {
|
|
1898
|
+
clientFlushers: /* @__PURE__ */ new Set(),
|
|
1899
|
+
pipelineFlushNeeded: false,
|
|
1900
|
+
handlerRegistered: false
|
|
1901
|
+
};
|
|
1902
|
+
holder[STATE_KEY2] = state;
|
|
1903
|
+
}
|
|
1904
|
+
return state;
|
|
1905
|
+
}
|
|
1906
|
+
function ensureExitHandler(state) {
|
|
1907
|
+
if (state.handlerRegistered) return;
|
|
1908
|
+
if (typeof process === "undefined" || typeof process.once !== "function") return;
|
|
1909
|
+
state.handlerRegistered = true;
|
|
1910
|
+
process.once("beforeExit", () => {
|
|
1911
|
+
void flushAll();
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
function registerClientFlusher(flush) {
|
|
1915
|
+
const state = getState2();
|
|
1916
|
+
state.clientFlushers.add(flush);
|
|
1917
|
+
ensureExitHandler(state);
|
|
1918
|
+
return () => {
|
|
1919
|
+
state.clientFlushers.delete(flush);
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
function markPipelineForExitFlush() {
|
|
1923
|
+
const state = getState2();
|
|
1924
|
+
state.pipelineFlushNeeded = true;
|
|
1925
|
+
ensureExitHandler(state);
|
|
1926
|
+
}
|
|
1927
|
+
async function flushAll() {
|
|
1928
|
+
const state = getState2();
|
|
1929
|
+
const tasks = [];
|
|
1930
|
+
for (const flush of state.clientFlushers) {
|
|
1931
|
+
tasks.push(Promise.resolve().then(flush).catch(() => {
|
|
1932
|
+
}));
|
|
1933
|
+
}
|
|
1934
|
+
if (state.pipelineFlushNeeded) {
|
|
1935
|
+
tasks.push(
|
|
1936
|
+
Promise.resolve().then(() => traceloop.forceFlush()).catch(() => {
|
|
1937
|
+
})
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
await Promise.all(tasks);
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1830
1943
|
// src/tracing/liveInteraction.ts
|
|
1831
1944
|
var import_api3 = require("@opentelemetry/api");
|
|
1832
|
-
var
|
|
1945
|
+
var traceloop2 = __toESM(require("@traceloop/node-server-sdk"));
|
|
1833
1946
|
|
|
1834
1947
|
// src/tracing/subagents.ts
|
|
1835
1948
|
var import_api2 = require("@opentelemetry/api");
|
|
@@ -2253,6 +2366,7 @@ var DirectToolSpan = class {
|
|
|
2253
2366
|
};
|
|
2254
2367
|
var LiveInteraction = class {
|
|
2255
2368
|
constructor(context6, traceId, analytics, directShipper, routing) {
|
|
2369
|
+
this.usageEmitted = false;
|
|
2256
2370
|
this.context = context6;
|
|
2257
2371
|
this.analytics = analytics;
|
|
2258
2372
|
this.tracer = import_api3.trace.getTracer("traceloop.tracer");
|
|
@@ -2337,10 +2451,7 @@ var LiveInteraction = class {
|
|
|
2337
2451
|
spanId: base64ToHex2(spanIdB64),
|
|
2338
2452
|
traceFlags: import_api3.TraceFlags.SAMPLED
|
|
2339
2453
|
};
|
|
2340
|
-
const wrappedContext = import_api3.trace.setSpan(
|
|
2341
|
-
import_api3.context.active(),
|
|
2342
|
-
import_api3.trace.wrapSpanContext(spanContext)
|
|
2343
|
-
);
|
|
2454
|
+
const wrappedContext = import_api3.trace.setSpan(import_api3.context.active(), import_api3.trace.wrapSpanContext(spanContext));
|
|
2344
2455
|
const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
|
|
2345
2456
|
try {
|
|
2346
2457
|
const result = await import_api3.context.with(wrappedContext, invoke);
|
|
@@ -2391,7 +2502,7 @@ var LiveInteraction = class {
|
|
|
2391
2502
|
}
|
|
2392
2503
|
return fn.apply(thisArg, fnArgs);
|
|
2393
2504
|
};
|
|
2394
|
-
return
|
|
2505
|
+
return traceloop2.withTask(
|
|
2395
2506
|
{
|
|
2396
2507
|
name: taskName,
|
|
2397
2508
|
associationProperties: serializeAssociationProperties(properties),
|
|
@@ -2432,10 +2543,7 @@ var LiveInteraction = class {
|
|
|
2432
2543
|
spanId: base64ToHex2(spanIdB64),
|
|
2433
2544
|
traceFlags: import_api3.TraceFlags.SAMPLED
|
|
2434
2545
|
};
|
|
2435
|
-
const wrappedContext = import_api3.trace.setSpan(
|
|
2436
|
-
import_api3.context.active(),
|
|
2437
|
-
import_api3.trace.wrapSpanContext(spanContext)
|
|
2438
|
-
);
|
|
2546
|
+
const wrappedContext = import_api3.trace.setSpan(import_api3.context.active(), import_api3.trace.wrapSpanContext(spanContext));
|
|
2439
2547
|
const invoke = () => this.routing ? withRoutingContext(this.routing, () => fn.apply(thisArg, args)) : fn.apply(thisArg, args);
|
|
2440
2548
|
let result;
|
|
2441
2549
|
let error;
|
|
@@ -2545,7 +2653,7 @@ var LiveInteraction = class {
|
|
|
2545
2653
|
throw error;
|
|
2546
2654
|
}
|
|
2547
2655
|
};
|
|
2548
|
-
return
|
|
2656
|
+
return traceloop2.withTool(
|
|
2549
2657
|
{
|
|
2550
2658
|
name: toolName,
|
|
2551
2659
|
associationProperties: serializeAssociationProperties(properties),
|
|
@@ -2848,7 +2956,7 @@ var LiveInteraction = class {
|
|
|
2848
2956
|
span.end();
|
|
2849
2957
|
}
|
|
2850
2958
|
async finish(resultEvent) {
|
|
2851
|
-
var _a, _b, _c, _d;
|
|
2959
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2852
2960
|
unbindRoutingContext(this.boundContext);
|
|
2853
2961
|
this.boundContext = void 0;
|
|
2854
2962
|
unbindSpanAttributes(this.toolEventsFrame);
|
|
@@ -2856,6 +2964,15 @@ var LiveInteraction = class {
|
|
|
2856
2964
|
if (!this.traceId) {
|
|
2857
2965
|
this.resolveLiveTraceId();
|
|
2858
2966
|
}
|
|
2967
|
+
const eventId = resultEvent.eventId || this.context.eventId;
|
|
2968
|
+
if (!this.usageEmitted) {
|
|
2969
|
+
(_c = this.analytics) == null ? void 0 : _c._recordModelUsage(
|
|
2970
|
+
eventId,
|
|
2971
|
+
(_a = resultEvent.model) != null ? _a : this.context.model,
|
|
2972
|
+
(_b = resultEvent.usage) != null ? _b : this.context.usage
|
|
2973
|
+
);
|
|
2974
|
+
this.usageEmitted = true;
|
|
2975
|
+
}
|
|
2859
2976
|
const spanFlush = (async () => {
|
|
2860
2977
|
var _a2;
|
|
2861
2978
|
try {
|
|
@@ -2863,21 +2980,20 @@ var LiveInteraction = class {
|
|
|
2863
2980
|
} catch (e) {
|
|
2864
2981
|
}
|
|
2865
2982
|
})();
|
|
2866
|
-
if ((
|
|
2983
|
+
if ((_e = (_d = this.analytics) == null ? void 0 : _d._shouldBlockFinishFlush()) != null ? _e : true) {
|
|
2867
2984
|
await spanFlush;
|
|
2868
2985
|
} else {
|
|
2869
2986
|
void spanFlush.catch(() => {
|
|
2870
2987
|
});
|
|
2871
2988
|
}
|
|
2872
|
-
const eventId = resultEvent.eventId || this.context.eventId;
|
|
2873
2989
|
try {
|
|
2874
|
-
await ((
|
|
2990
|
+
await ((_f = this.analytics) == null ? void 0 : _f._drainInFlightPartials(eventId));
|
|
2875
2991
|
} catch (e) {
|
|
2876
2992
|
}
|
|
2877
2993
|
if (this.traceId) {
|
|
2878
2994
|
this.setProperty("trace_id", this.traceId);
|
|
2879
2995
|
}
|
|
2880
|
-
await ((
|
|
2996
|
+
await ((_g = this.analytics) == null ? void 0 : _g._trackAiPartial({
|
|
2881
2997
|
...resultEvent,
|
|
2882
2998
|
eventId,
|
|
2883
2999
|
isPending: false
|
|
@@ -2994,7 +3110,7 @@ var LiveInteraction = class {
|
|
|
2994
3110
|
|
|
2995
3111
|
// src/tracing/liveTracer.ts
|
|
2996
3112
|
var import_api4 = require("@opentelemetry/api");
|
|
2997
|
-
var
|
|
3113
|
+
var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
|
|
2998
3114
|
var LiveTracer = class {
|
|
2999
3115
|
constructor(globalProperties, directShipper, routing) {
|
|
3000
3116
|
this.tracer = import_api4.trace.getTracer("traceloop.tracer");
|
|
@@ -3038,7 +3154,7 @@ var LiveTracer = class {
|
|
|
3038
3154
|
}
|
|
3039
3155
|
return fn.apply(thisArg, fnArgs);
|
|
3040
3156
|
};
|
|
3041
|
-
return
|
|
3157
|
+
return traceloop3.withTask(
|
|
3042
3158
|
{
|
|
3043
3159
|
name: taskName,
|
|
3044
3160
|
associationProperties: properties,
|
|
@@ -3150,59 +3266,6 @@ var LiveTracer = class {
|
|
|
3150
3266
|
}
|
|
3151
3267
|
};
|
|
3152
3268
|
|
|
3153
|
-
// src/tracing/exit-flush.ts
|
|
3154
|
-
var traceloop3 = __toESM(require("@traceloop/node-server-sdk"));
|
|
3155
|
-
var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
|
|
3156
|
-
function getState2() {
|
|
3157
|
-
const holder = globalThis;
|
|
3158
|
-
let state = holder[STATE_KEY2];
|
|
3159
|
-
if (!state) {
|
|
3160
|
-
state = {
|
|
3161
|
-
clientFlushers: /* @__PURE__ */ new Set(),
|
|
3162
|
-
pipelineFlushNeeded: false,
|
|
3163
|
-
handlerRegistered: false
|
|
3164
|
-
};
|
|
3165
|
-
holder[STATE_KEY2] = state;
|
|
3166
|
-
}
|
|
3167
|
-
return state;
|
|
3168
|
-
}
|
|
3169
|
-
function ensureExitHandler(state) {
|
|
3170
|
-
if (state.handlerRegistered) return;
|
|
3171
|
-
if (typeof process === "undefined" || typeof process.once !== "function") return;
|
|
3172
|
-
state.handlerRegistered = true;
|
|
3173
|
-
process.once("beforeExit", () => {
|
|
3174
|
-
void flushAll();
|
|
3175
|
-
});
|
|
3176
|
-
}
|
|
3177
|
-
function registerClientFlusher(flush) {
|
|
3178
|
-
const state = getState2();
|
|
3179
|
-
state.clientFlushers.add(flush);
|
|
3180
|
-
ensureExitHandler(state);
|
|
3181
|
-
return () => {
|
|
3182
|
-
state.clientFlushers.delete(flush);
|
|
3183
|
-
};
|
|
3184
|
-
}
|
|
3185
|
-
function markPipelineForExitFlush() {
|
|
3186
|
-
const state = getState2();
|
|
3187
|
-
state.pipelineFlushNeeded = true;
|
|
3188
|
-
ensureExitHandler(state);
|
|
3189
|
-
}
|
|
3190
|
-
async function flushAll() {
|
|
3191
|
-
const state = getState2();
|
|
3192
|
-
const tasks = [];
|
|
3193
|
-
for (const flush of state.clientFlushers) {
|
|
3194
|
-
tasks.push(Promise.resolve().then(flush).catch(() => {
|
|
3195
|
-
}));
|
|
3196
|
-
}
|
|
3197
|
-
if (state.pipelineFlushNeeded) {
|
|
3198
|
-
tasks.push(
|
|
3199
|
-
Promise.resolve().then(() => traceloop3.forceFlush()).catch(() => {
|
|
3200
|
-
})
|
|
3201
|
-
);
|
|
3202
|
-
}
|
|
3203
|
-
await Promise.all(tasks);
|
|
3204
|
-
}
|
|
3205
|
-
|
|
3206
3269
|
// src/tracing/tracer-core.ts
|
|
3207
3270
|
if (localDebuggerEnabled()) {
|
|
3208
3271
|
if (!process.env.OTEL_EXPORTER_OTLP_PROTOCOL) {
|
|
@@ -3920,6 +3983,59 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
3920
3983
|
...frame ? { frame, frameOwner } : {}
|
|
3921
3984
|
});
|
|
3922
3985
|
};
|
|
3986
|
+
const recordModelUsage = (params) => {
|
|
3987
|
+
try {
|
|
3988
|
+
const attributes = [
|
|
3989
|
+
attrString(MODEL_USAGE_ATTRIBUTES.usageSource, "manual"),
|
|
3990
|
+
attrString(
|
|
3991
|
+
MODEL_USAGE_ATTRIBUTES.providerName,
|
|
3992
|
+
canonicalModelProvider(params.usage.provider)
|
|
3993
|
+
),
|
|
3994
|
+
attrString(MODEL_USAGE_ATTRIBUTES.requestModel, params.model),
|
|
3995
|
+
attrString(MODEL_USAGE_ATTRIBUTES.responseModel, params.model),
|
|
3996
|
+
...buildRawModelUsageAttributes({
|
|
3997
|
+
inputTokens: params.usage.inputTokens,
|
|
3998
|
+
outputTokens: params.usage.outputTokens,
|
|
3999
|
+
cacheReadInputTokens: params.usage.cacheReadTokens,
|
|
4000
|
+
cacheWriteInputTokens: params.usage.cacheWriteTokens,
|
|
4001
|
+
reasoningTokens: params.usage.reasoningTokens,
|
|
4002
|
+
providerReportedCost: params.usage.providerReportedCost
|
|
4003
|
+
})
|
|
4004
|
+
].filter((attribute) => attribute !== void 0);
|
|
4005
|
+
if (directShipper) {
|
|
4006
|
+
const timeMs = Date.now();
|
|
4007
|
+
directShipper.sendSpan({
|
|
4008
|
+
name: "ai.model.usage",
|
|
4009
|
+
spanKind: "llm",
|
|
4010
|
+
properties: { event_id: params.eventId },
|
|
4011
|
+
startTimeMs: timeMs,
|
|
4012
|
+
endTimeMs: timeMs,
|
|
4013
|
+
durationMs: 0,
|
|
4014
|
+
otlpAttributes: attributes
|
|
4015
|
+
});
|
|
4016
|
+
return;
|
|
4017
|
+
}
|
|
4018
|
+
const span = import_api5.trace.getTracer("traceloop.tracer").startSpan("ai.model.usage");
|
|
4019
|
+
span.setAttribute("traceloop.span.kind", "llm");
|
|
4020
|
+
span.setAttribute("traceloop.association.properties.event_id", params.eventId);
|
|
4021
|
+
stampSpan(span, projectId, authHint);
|
|
4022
|
+
for (const attribute of attributes) {
|
|
4023
|
+
const value = attribute.value;
|
|
4024
|
+
if (value.stringValue !== void 0) {
|
|
4025
|
+
span.setAttribute(attribute.key, value.stringValue);
|
|
4026
|
+
} else if (value.intValue !== void 0) {
|
|
4027
|
+
const parsed = Number(value.intValue);
|
|
4028
|
+
if (Number.isSafeInteger(parsed)) span.setAttribute(attribute.key, parsed);
|
|
4029
|
+
} else if (value.doubleValue !== void 0) {
|
|
4030
|
+
span.setAttribute(attribute.key, value.doubleValue);
|
|
4031
|
+
} else if (value.boolValue !== void 0) {
|
|
4032
|
+
span.setAttribute(attribute.key, value.boolValue);
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
span.end();
|
|
4036
|
+
} catch (e) {
|
|
4037
|
+
}
|
|
4038
|
+
};
|
|
3923
4039
|
return {
|
|
3924
4040
|
/**
|
|
3925
4041
|
* Returns instrumentation instances for your NodeSDK.
|
|
@@ -4031,6 +4147,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
4031
4147
|
begin(traceContext) {
|
|
4032
4148
|
return beginInteraction(traceContext);
|
|
4033
4149
|
},
|
|
4150
|
+
recordModelUsage,
|
|
4034
4151
|
resumeSubagent(carrierOrHeaders, options2 = {}) {
|
|
4035
4152
|
return openSubagentRun(carrierOrHeaders, options2);
|
|
4036
4153
|
},
|
package/dist/tracing/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raindrop-ai",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typescript": "^5.3.3",
|
|
42
42
|
"vite": "^7.3.2",
|
|
43
43
|
"vitest": "^4.0.10",
|
|
44
|
-
"@raindrop-ai/core": "0.2.
|
|
44
|
+
"@raindrop-ai/core": "0.2.1",
|
|
45
45
|
"@raindrop-ai/redact-pii": "0.1.2",
|
|
46
46
|
"@raindrop-ai/schemas": "0.1.0"
|
|
47
47
|
},
|