langsmith 0.2.3 → 0.2.4
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 +24 -2
- package/dist/vercel.d.ts +3 -0
- package/dist/vercel.js +25 -3
- 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";
|
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";
|
package/dist/index.js
CHANGED
package/dist/vercel.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const index_js_1 = require("./index.cjs");
|
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const traceable_js_1 = require("./singletons/traceable.cjs");
|
|
7
7
|
const env_js_1 = require("./utils/env.cjs");
|
|
8
|
+
const env_js_2 = require("./env.cjs");
|
|
8
9
|
// Attempt to convert CoreMessage to a LangChain-compatible format
|
|
9
10
|
// which allows us to render messages more nicely in LangSmith
|
|
10
11
|
function convertCoreToSmith(message) {
|
|
@@ -202,6 +203,12 @@ class AISDKExporter {
|
|
|
202
203
|
writable: true,
|
|
203
204
|
value: {}
|
|
204
205
|
});
|
|
206
|
+
Object.defineProperty(this, "debug", {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
configurable: true,
|
|
209
|
+
writable: true,
|
|
210
|
+
value: void 0
|
|
211
|
+
});
|
|
205
212
|
/** @internal */
|
|
206
213
|
Object.defineProperty(this, "getSpanAttributeKey", {
|
|
207
214
|
enumerable: true,
|
|
@@ -215,6 +222,9 @@ class AISDKExporter {
|
|
|
215
222
|
}
|
|
216
223
|
});
|
|
217
224
|
this.client = args?.client ?? new index_js_1.Client();
|
|
225
|
+
this.debug =
|
|
226
|
+
args?.debug ?? (0, env_js_1.getEnvironmentVariable)("OTEL_LOG_LEVEL") === "DEBUG";
|
|
227
|
+
this.logDebug("creating exporter", { tracingEnabled: (0, env_js_2.isTracingEnabled)() });
|
|
218
228
|
}
|
|
219
229
|
static getSettings(settings) {
|
|
220
230
|
const { runId, runName, ...rest } = settings ?? {};
|
|
@@ -224,7 +234,7 @@ class AISDKExporter {
|
|
|
224
234
|
if (runName != null)
|
|
225
235
|
metadata[RUN_NAME_METADATA_KEY.input] = runName;
|
|
226
236
|
// attempt to obtain the run tree if used within a traceable function
|
|
227
|
-
let defaultEnabled =
|
|
237
|
+
let defaultEnabled = settings?.isEnabled ?? (0, env_js_2.isTracingEnabled)();
|
|
228
238
|
try {
|
|
229
239
|
const runTree = (0, traceable_js_1.getCurrentRunTree)();
|
|
230
240
|
const headers = runTree.toHeaders();
|
|
@@ -517,6 +527,7 @@ class AISDKExporter {
|
|
|
517
527
|
}
|
|
518
528
|
}
|
|
519
529
|
export(spans, resultCallback) {
|
|
530
|
+
this.logDebug("exporting spans", spans);
|
|
520
531
|
const typedSpans = spans
|
|
521
532
|
.slice()
|
|
522
533
|
.sort((a, b) => sortByHr(a.startTime, b.startTime));
|
|
@@ -538,8 +549,10 @@ class AISDKExporter {
|
|
|
538
549
|
parentRunId = undefined;
|
|
539
550
|
const traceMap = this.traceByMap[traceId];
|
|
540
551
|
const run = this.getRunCreate(span);
|
|
541
|
-
if (!run)
|
|
552
|
+
if (!run) {
|
|
553
|
+
this.logDebug("skipping span", span);
|
|
542
554
|
continue;
|
|
555
|
+
}
|
|
543
556
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] ??= -1;
|
|
544
557
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] += 1;
|
|
545
558
|
traceMap.nodeMap[runId] ??= {
|
|
@@ -550,6 +563,8 @@ class AISDKExporter {
|
|
|
550
563
|
sent: false,
|
|
551
564
|
executionOrder: traceMap.relativeExecutionOrder[parentRunId ?? ROOT],
|
|
552
565
|
};
|
|
566
|
+
if (this.debug)
|
|
567
|
+
console.log(`[${span.name}] ${runId}`, run);
|
|
553
568
|
traceMap.childMap[parentRunId ?? ROOT] ??= [];
|
|
554
569
|
traceMap.childMap[parentRunId ?? ROOT].push(traceMap.nodeMap[runId]);
|
|
555
570
|
traceMap.interop = this.parseInteropFromMetadata(span);
|
|
@@ -628,11 +643,13 @@ class AISDKExporter {
|
|
|
628
643
|
}));
|
|
629
644
|
}
|
|
630
645
|
}
|
|
646
|
+
this.logDebug(`sampled runs to be sent to LangSmith`, sampled);
|
|
631
647
|
Promise.all(sampled.map(([override, value]) => this.client.createRun({ ...value, ...override }))).then(() => resultCallback({ code: 0 }), (error) => resultCallback({ code: 1, error }));
|
|
632
648
|
}
|
|
633
649
|
async shutdown() {
|
|
634
650
|
// find nodes which are incomplete
|
|
635
651
|
const incompleteNodes = Object.values(this.traceByMap).flatMap((trace) => Object.values(trace.nodeMap).filter((i) => !i.sent));
|
|
652
|
+
this.logDebug("shutting down", { incompleteNodes: incompleteNodes.length });
|
|
636
653
|
if (incompleteNodes.length > 0) {
|
|
637
654
|
console.warn("Some incomplete nodes were found before shutdown and not sent to LangSmith.");
|
|
638
655
|
}
|
|
@@ -641,5 +658,10 @@ class AISDKExporter {
|
|
|
641
658
|
async forceFlush() {
|
|
642
659
|
await this.client?.awaitPendingTraceBatches();
|
|
643
660
|
}
|
|
661
|
+
logDebug(...args) {
|
|
662
|
+
if (!this.debug)
|
|
663
|
+
return;
|
|
664
|
+
console.debug(`[${new Date().toISOString()}] [LangSmith]`, ...args);
|
|
665
|
+
}
|
|
644
666
|
}
|
|
645
667
|
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,8 @@
|
|
|
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
|
+
import { isTracingEnabled } from "./env.js";
|
|
5
6
|
// Attempt to convert CoreMessage to a LangChain-compatible format
|
|
6
7
|
// which allows us to render messages more nicely in LangSmith
|
|
7
8
|
function convertCoreToSmith(message) {
|
|
@@ -199,6 +200,12 @@ export class AISDKExporter {
|
|
|
199
200
|
writable: true,
|
|
200
201
|
value: {}
|
|
201
202
|
});
|
|
203
|
+
Object.defineProperty(this, "debug", {
|
|
204
|
+
enumerable: true,
|
|
205
|
+
configurable: true,
|
|
206
|
+
writable: true,
|
|
207
|
+
value: void 0
|
|
208
|
+
});
|
|
202
209
|
/** @internal */
|
|
203
210
|
Object.defineProperty(this, "getSpanAttributeKey", {
|
|
204
211
|
enumerable: true,
|
|
@@ -212,6 +219,9 @@ export class AISDKExporter {
|
|
|
212
219
|
}
|
|
213
220
|
});
|
|
214
221
|
this.client = args?.client ?? new Client();
|
|
222
|
+
this.debug =
|
|
223
|
+
args?.debug ?? getEnvironmentVariable("OTEL_LOG_LEVEL") === "DEBUG";
|
|
224
|
+
this.logDebug("creating exporter", { tracingEnabled: isTracingEnabled() });
|
|
215
225
|
}
|
|
216
226
|
static getSettings(settings) {
|
|
217
227
|
const { runId, runName, ...rest } = settings ?? {};
|
|
@@ -221,7 +231,7 @@ export class AISDKExporter {
|
|
|
221
231
|
if (runName != null)
|
|
222
232
|
metadata[RUN_NAME_METADATA_KEY.input] = runName;
|
|
223
233
|
// attempt to obtain the run tree if used within a traceable function
|
|
224
|
-
let defaultEnabled =
|
|
234
|
+
let defaultEnabled = settings?.isEnabled ?? isTracingEnabled();
|
|
225
235
|
try {
|
|
226
236
|
const runTree = getCurrentRunTree();
|
|
227
237
|
const headers = runTree.toHeaders();
|
|
@@ -514,6 +524,7 @@ export class AISDKExporter {
|
|
|
514
524
|
}
|
|
515
525
|
}
|
|
516
526
|
export(spans, resultCallback) {
|
|
527
|
+
this.logDebug("exporting spans", spans);
|
|
517
528
|
const typedSpans = spans
|
|
518
529
|
.slice()
|
|
519
530
|
.sort((a, b) => sortByHr(a.startTime, b.startTime));
|
|
@@ -535,8 +546,10 @@ export class AISDKExporter {
|
|
|
535
546
|
parentRunId = undefined;
|
|
536
547
|
const traceMap = this.traceByMap[traceId];
|
|
537
548
|
const run = this.getRunCreate(span);
|
|
538
|
-
if (!run)
|
|
549
|
+
if (!run) {
|
|
550
|
+
this.logDebug("skipping span", span);
|
|
539
551
|
continue;
|
|
552
|
+
}
|
|
540
553
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] ??= -1;
|
|
541
554
|
traceMap.relativeExecutionOrder[parentRunId ?? ROOT] += 1;
|
|
542
555
|
traceMap.nodeMap[runId] ??= {
|
|
@@ -547,6 +560,8 @@ export class AISDKExporter {
|
|
|
547
560
|
sent: false,
|
|
548
561
|
executionOrder: traceMap.relativeExecutionOrder[parentRunId ?? ROOT],
|
|
549
562
|
};
|
|
563
|
+
if (this.debug)
|
|
564
|
+
console.log(`[${span.name}] ${runId}`, run);
|
|
550
565
|
traceMap.childMap[parentRunId ?? ROOT] ??= [];
|
|
551
566
|
traceMap.childMap[parentRunId ?? ROOT].push(traceMap.nodeMap[runId]);
|
|
552
567
|
traceMap.interop = this.parseInteropFromMetadata(span);
|
|
@@ -625,11 +640,13 @@ export class AISDKExporter {
|
|
|
625
640
|
}));
|
|
626
641
|
}
|
|
627
642
|
}
|
|
643
|
+
this.logDebug(`sampled runs to be sent to LangSmith`, sampled);
|
|
628
644
|
Promise.all(sampled.map(([override, value]) => this.client.createRun({ ...value, ...override }))).then(() => resultCallback({ code: 0 }), (error) => resultCallback({ code: 1, error }));
|
|
629
645
|
}
|
|
630
646
|
async shutdown() {
|
|
631
647
|
// find nodes which are incomplete
|
|
632
648
|
const incompleteNodes = Object.values(this.traceByMap).flatMap((trace) => Object.values(trace.nodeMap).filter((i) => !i.sent));
|
|
649
|
+
this.logDebug("shutting down", { incompleteNodes: incompleteNodes.length });
|
|
633
650
|
if (incompleteNodes.length > 0) {
|
|
634
651
|
console.warn("Some incomplete nodes were found before shutdown and not sent to LangSmith.");
|
|
635
652
|
}
|
|
@@ -638,4 +655,9 @@ export class AISDKExporter {
|
|
|
638
655
|
async forceFlush() {
|
|
639
656
|
await this.client?.awaitPendingTraceBatches();
|
|
640
657
|
}
|
|
658
|
+
logDebug(...args) {
|
|
659
|
+
if (!this.debug)
|
|
660
|
+
return;
|
|
661
|
+
console.debug(`[${new Date().toISOString()}] [LangSmith]`, ...args);
|
|
662
|
+
}
|
|
641
663
|
}
|