langsmith 0.2.3 → 0.2.4-dev.0
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/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/vercel.cjs +21 -1
- package/dist/vercel.d.ts +3 -0
- package/dist/vercel.js +22 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () {
|
|
|
8
8
|
var fetch_js_1 = require("./singletons/fetch.cjs");
|
|
9
9
|
Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
|
|
10
10
|
// Update using yarn bump-version
|
|
11
|
-
exports.__version__ = "0.2.
|
|
11
|
+
exports.__version__ = "0.2.4-dev.0";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { Client, type ClientConfig } from "./client.js";
|
|
|
2
2
|
export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
|
-
export declare const __version__ = "0.2.
|
|
5
|
+
export declare const __version__ = "0.2.4-dev.0";
|
package/dist/index.js
CHANGED
package/dist/vercel.cjs
CHANGED
|
@@ -202,6 +202,12 @@ class AISDKExporter {
|
|
|
202
202
|
writable: true,
|
|
203
203
|
value: {}
|
|
204
204
|
});
|
|
205
|
+
Object.defineProperty(this, "debug", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
configurable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: void 0
|
|
210
|
+
});
|
|
205
211
|
/** @internal */
|
|
206
212
|
Object.defineProperty(this, "getSpanAttributeKey", {
|
|
207
213
|
enumerable: true,
|
|
@@ -215,6 +221,8 @@ class AISDKExporter {
|
|
|
215
221
|
}
|
|
216
222
|
});
|
|
217
223
|
this.client = args?.client ?? new index_js_1.Client();
|
|
224
|
+
this.debug =
|
|
225
|
+
args?.debug ?? (0, env_js_1.getEnvironmentVariable)("OTEL_LOG_LEVEL") === "DEBUG";
|
|
218
226
|
}
|
|
219
227
|
static getSettings(settings) {
|
|
220
228
|
const { runId, runName, ...rest } = settings ?? {};
|
|
@@ -517,6 +525,7 @@ class AISDKExporter {
|
|
|
517
525
|
}
|
|
518
526
|
}
|
|
519
527
|
export(spans, resultCallback) {
|
|
528
|
+
this.logDebug("exporting spans", spans);
|
|
520
529
|
const typedSpans = spans
|
|
521
530
|
.slice()
|
|
522
531
|
.sort((a, b) => sortByHr(a.startTime, b.startTime));
|
|
@@ -538,8 +547,10 @@ class AISDKExporter {
|
|
|
538
547
|
parentRunId = undefined;
|
|
539
548
|
const traceMap = this.traceByMap[traceId];
|
|
540
549
|
const run = this.getRunCreate(span);
|
|
541
|
-
if (!run)
|
|
550
|
+
if (!run) {
|
|
551
|
+
this.logDebug("skipping span", span);
|
|
542
552
|
continue;
|
|
553
|
+
}
|
|
543
554
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] ??= -1;
|
|
544
555
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] += 1;
|
|
545
556
|
traceMap.nodeMap[runId] ??= {
|
|
@@ -550,6 +561,8 @@ class AISDKExporter {
|
|
|
550
561
|
sent: false,
|
|
551
562
|
executionOrder: traceMap.relativeExecutionOrder[parentRunId ?? ROOT],
|
|
552
563
|
};
|
|
564
|
+
if (this.debug)
|
|
565
|
+
console.log(`[${span.name}] ${runId}`, run);
|
|
553
566
|
traceMap.childMap[parentRunId ?? ROOT] ??= [];
|
|
554
567
|
traceMap.childMap[parentRunId ?? ROOT].push(traceMap.nodeMap[runId]);
|
|
555
568
|
traceMap.interop = this.parseInteropFromMetadata(span);
|
|
@@ -628,11 +641,13 @@ class AISDKExporter {
|
|
|
628
641
|
}));
|
|
629
642
|
}
|
|
630
643
|
}
|
|
644
|
+
this.logDebug(`sampled runs to be sent to LangSmith`, sampled);
|
|
631
645
|
Promise.all(sampled.map(([override, value]) => this.client.createRun({ ...value, ...override }))).then(() => resultCallback({ code: 0 }), (error) => resultCallback({ code: 1, error }));
|
|
632
646
|
}
|
|
633
647
|
async shutdown() {
|
|
634
648
|
// find nodes which are incomplete
|
|
635
649
|
const incompleteNodes = Object.values(this.traceByMap).flatMap((trace) => Object.values(trace.nodeMap).filter((i) => !i.sent));
|
|
650
|
+
this.logDebug("shutting down", { incompleteNodes: incompleteNodes.length });
|
|
636
651
|
if (incompleteNodes.length > 0) {
|
|
637
652
|
console.warn("Some incomplete nodes were found before shutdown and not sent to LangSmith.");
|
|
638
653
|
}
|
|
@@ -641,5 +656,10 @@ class AISDKExporter {
|
|
|
641
656
|
async forceFlush() {
|
|
642
657
|
await this.client?.awaitPendingTraceBatches();
|
|
643
658
|
}
|
|
659
|
+
logDebug(...args) {
|
|
660
|
+
if (!this.debug)
|
|
661
|
+
return;
|
|
662
|
+
console.debug(`[${new Date().toISOString()}] [LangSmith]`, ...args);
|
|
663
|
+
}
|
|
644
664
|
}
|
|
645
665
|
exports.AISDKExporter = AISDKExporter;
|
package/dist/vercel.d.ts
CHANGED
|
@@ -50,8 +50,10 @@ export interface TelemetrySettings extends AITelemetrySettings {
|
|
|
50
50
|
export declare class AISDKExporter {
|
|
51
51
|
private client;
|
|
52
52
|
private traceByMap;
|
|
53
|
+
private debug;
|
|
53
54
|
constructor(args?: {
|
|
54
55
|
client?: Client;
|
|
56
|
+
debug?: boolean;
|
|
55
57
|
});
|
|
56
58
|
static getSettings(settings?: TelemetrySettings): {
|
|
57
59
|
isEnabled: boolean;
|
|
@@ -69,4 +71,5 @@ export declare class AISDKExporter {
|
|
|
69
71
|
}) => void): void;
|
|
70
72
|
shutdown(): Promise<void>;
|
|
71
73
|
forceFlush?(): Promise<void>;
|
|
74
|
+
protected logDebug(...args: Parameters<typeof console.debug>): void;
|
|
72
75
|
}
|
package/dist/vercel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client, RunTree } from "./index.js";
|
|
2
2
|
import { v5 as uuid5, v4 as uuid4 } from "uuid";
|
|
3
3
|
import { getCurrentRunTree } from "./singletons/traceable.js";
|
|
4
|
-
import { getLangSmithEnvironmentVariable } from "./utils/env.js";
|
|
4
|
+
import { getLangSmithEnvironmentVariable, getEnvironmentVariable, } from "./utils/env.js";
|
|
5
5
|
// Attempt to convert CoreMessage to a LangChain-compatible format
|
|
6
6
|
// which allows us to render messages more nicely in LangSmith
|
|
7
7
|
function convertCoreToSmith(message) {
|
|
@@ -199,6 +199,12 @@ export class AISDKExporter {
|
|
|
199
199
|
writable: true,
|
|
200
200
|
value: {}
|
|
201
201
|
});
|
|
202
|
+
Object.defineProperty(this, "debug", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
configurable: true,
|
|
205
|
+
writable: true,
|
|
206
|
+
value: void 0
|
|
207
|
+
});
|
|
202
208
|
/** @internal */
|
|
203
209
|
Object.defineProperty(this, "getSpanAttributeKey", {
|
|
204
210
|
enumerable: true,
|
|
@@ -212,6 +218,8 @@ export class AISDKExporter {
|
|
|
212
218
|
}
|
|
213
219
|
});
|
|
214
220
|
this.client = args?.client ?? new Client();
|
|
221
|
+
this.debug =
|
|
222
|
+
args?.debug ?? getEnvironmentVariable("OTEL_LOG_LEVEL") === "DEBUG";
|
|
215
223
|
}
|
|
216
224
|
static getSettings(settings) {
|
|
217
225
|
const { runId, runName, ...rest } = settings ?? {};
|
|
@@ -514,6 +522,7 @@ export class AISDKExporter {
|
|
|
514
522
|
}
|
|
515
523
|
}
|
|
516
524
|
export(spans, resultCallback) {
|
|
525
|
+
this.logDebug("exporting spans", spans);
|
|
517
526
|
const typedSpans = spans
|
|
518
527
|
.slice()
|
|
519
528
|
.sort((a, b) => sortByHr(a.startTime, b.startTime));
|
|
@@ -535,8 +544,10 @@ export class AISDKExporter {
|
|
|
535
544
|
parentRunId = undefined;
|
|
536
545
|
const traceMap = this.traceByMap[traceId];
|
|
537
546
|
const run = this.getRunCreate(span);
|
|
538
|
-
if (!run)
|
|
547
|
+
if (!run) {
|
|
548
|
+
this.logDebug("skipping span", span);
|
|
539
549
|
continue;
|
|
550
|
+
}
|
|
540
551
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] ??= -1;
|
|
541
552
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] += 1;
|
|
542
553
|
traceMap.nodeMap[runId] ??= {
|
|
@@ -547,6 +558,8 @@ export class AISDKExporter {
|
|
|
547
558
|
sent: false,
|
|
548
559
|
executionOrder: traceMap.relativeExecutionOrder[parentRunId ?? ROOT],
|
|
549
560
|
};
|
|
561
|
+
if (this.debug)
|
|
562
|
+
console.log(`[${span.name}] ${runId}`, run);
|
|
550
563
|
traceMap.childMap[parentRunId ?? ROOT] ??= [];
|
|
551
564
|
traceMap.childMap[parentRunId ?? ROOT].push(traceMap.nodeMap[runId]);
|
|
552
565
|
traceMap.interop = this.parseInteropFromMetadata(span);
|
|
@@ -625,11 +638,13 @@ export class AISDKExporter {
|
|
|
625
638
|
}));
|
|
626
639
|
}
|
|
627
640
|
}
|
|
641
|
+
this.logDebug(`sampled runs to be sent to LangSmith`, sampled);
|
|
628
642
|
Promise.all(sampled.map(([override, value]) => this.client.createRun({ ...value, ...override }))).then(() => resultCallback({ code: 0 }), (error) => resultCallback({ code: 1, error }));
|
|
629
643
|
}
|
|
630
644
|
async shutdown() {
|
|
631
645
|
// find nodes which are incomplete
|
|
632
646
|
const incompleteNodes = Object.values(this.traceByMap).flatMap((trace) => Object.values(trace.nodeMap).filter((i) => !i.sent));
|
|
647
|
+
this.logDebug("shutting down", { incompleteNodes: incompleteNodes.length });
|
|
633
648
|
if (incompleteNodes.length > 0) {
|
|
634
649
|
console.warn("Some incomplete nodes were found before shutdown and not sent to LangSmith.");
|
|
635
650
|
}
|
|
@@ -638,4 +653,9 @@ export class AISDKExporter {
|
|
|
638
653
|
async forceFlush() {
|
|
639
654
|
await this.client?.awaitPendingTraceBatches();
|
|
640
655
|
}
|
|
656
|
+
logDebug(...args) {
|
|
657
|
+
if (!this.debug)
|
|
658
|
+
return;
|
|
659
|
+
console.debug(`[${new Date().toISOString()}] [LangSmith]`, ...args);
|
|
660
|
+
}
|
|
641
661
|
}
|