langsmith 0.3.49-rc.2 → 0.3.49-rc.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/experimental/otel/processor.cjs +12 -33
- package/dist/experimental/otel/processor.d.ts +1 -4
- package/dist/experimental/otel/processor.js +12 -33
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ exports.isTraceableSpan = isTraceableSpan;
|
|
|
5
5
|
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
6
6
|
const constants_js_1 = require("./constants.cjs");
|
|
7
7
|
const utils_js_1 = require("./utils.cjs");
|
|
8
|
+
const run_trees_js_1 = require("../../run_trees.cjs");
|
|
8
9
|
function isTraceableSpan(span) {
|
|
9
10
|
return (span.attributes[constants_js_1.LANGSMITH_TRACEABLE] === "true" ||
|
|
10
11
|
typeof span.attributes["ai.operationId"] === "string");
|
|
@@ -27,45 +28,15 @@ class LangSmithOTLPSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
|
|
|
27
28
|
writable: true,
|
|
28
29
|
value: {}
|
|
29
30
|
});
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
Object.defineProperty(this, "cleanupInterval", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(this, "TRACE_TTL_MS", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
configurable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
value: 10 * 60 * 1000
|
|
42
|
-
}); // 10 minutes
|
|
43
|
-
// We must use a cleanup interval because LangSmith can start child spans
|
|
44
|
-
// after arbitrary OTEL parent spans have ended since it uses batching.
|
|
45
|
-
this.cleanupInterval = setInterval(() => this.cleanupStaleTraces(), 60000);
|
|
46
|
-
}
|
|
47
|
-
cleanupStaleTraces() {
|
|
48
|
-
const now = Date.now();
|
|
49
|
-
for (const [traceId, traceInfo] of Object.entries(this.traceMap)) {
|
|
50
|
-
if (now - traceInfo.lastAccessed > this.TRACE_TTL_MS) {
|
|
51
|
-
delete this.traceMap[traceId];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
shutdown() {
|
|
56
|
-
if (this.cleanupInterval) {
|
|
57
|
-
clearInterval(this.cleanupInterval);
|
|
58
|
-
}
|
|
59
|
-
return super.shutdown();
|
|
60
31
|
}
|
|
61
32
|
onStart(span, parentContext) {
|
|
62
33
|
if (!this.traceMap[span.spanContext().traceId]) {
|
|
63
34
|
this.traceMap[span.spanContext().traceId] = {
|
|
64
35
|
spanInfo: {},
|
|
65
|
-
|
|
36
|
+
spanCount: 0,
|
|
66
37
|
};
|
|
67
38
|
}
|
|
68
|
-
this.traceMap[span.spanContext().traceId].
|
|
39
|
+
this.traceMap[span.spanContext().traceId].spanCount++;
|
|
69
40
|
const isTraceable = isTraceableSpan(span);
|
|
70
41
|
const parentSpanId = getParentSpanId(span);
|
|
71
42
|
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
@@ -97,13 +68,21 @@ class LangSmithOTLPSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
|
|
|
97
68
|
const traceInfo = this.traceMap[span.spanContext().traceId];
|
|
98
69
|
if (!traceInfo)
|
|
99
70
|
return;
|
|
100
|
-
traceInfo.lastAccessed = Date.now();
|
|
101
71
|
const spanInfo = traceInfo.spanInfo[span.spanContext().spanId];
|
|
102
72
|
if (!spanInfo)
|
|
103
73
|
return;
|
|
74
|
+
// Decrement span count and cleanup trace if all spans are done
|
|
75
|
+
traceInfo.spanCount--;
|
|
76
|
+
if (traceInfo.spanCount <= 0) {
|
|
77
|
+
delete this.traceMap[span.spanContext().traceId];
|
|
78
|
+
}
|
|
104
79
|
if (spanInfo.isTraceable) {
|
|
105
80
|
super.onEnd(span);
|
|
106
81
|
}
|
|
107
82
|
}
|
|
83
|
+
async shutdown() {
|
|
84
|
+
await run_trees_js_1.RunTree.getSharedClient().awaitPendingTraceBatches();
|
|
85
|
+
await super.shutdown();
|
|
86
|
+
}
|
|
108
87
|
}
|
|
109
88
|
exports.LangSmithOTLPSpanProcessor = LangSmithOTLPSpanProcessor;
|
|
@@ -7,11 +7,8 @@ export declare function isTraceableSpan(span: ReadableSpan): boolean;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
|
|
9
9
|
private traceMap;
|
|
10
|
-
private cleanupInterval;
|
|
11
|
-
private TRACE_TTL_MS;
|
|
12
10
|
constructor(...args: ConstructorParameters<typeof BatchSpanProcessor>);
|
|
13
|
-
private cleanupStaleTraces;
|
|
14
|
-
shutdown(): Promise<void>;
|
|
15
11
|
onStart(span: Span, parentContext: Context): void;
|
|
16
12
|
onEnd(span: ReadableSpan): void;
|
|
13
|
+
shutdown(): Promise<void>;
|
|
17
14
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BatchSpanProcessor, } from "@opentelemetry/sdk-trace-base";
|
|
2
2
|
import { LANGSMITH_IS_ROOT, LANGSMITH_PARENT_RUN_ID, LANGSMITH_TRACEABLE, } from "./constants.js";
|
|
3
3
|
import { getUuidFromOtelSpanId } from "./utils.js";
|
|
4
|
+
import { RunTree } from "../../run_trees.js";
|
|
4
5
|
export function isTraceableSpan(span) {
|
|
5
6
|
return (span.attributes[LANGSMITH_TRACEABLE] === "true" ||
|
|
6
7
|
typeof span.attributes["ai.operationId"] === "string");
|
|
@@ -23,45 +24,15 @@ export class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
|
|
|
23
24
|
writable: true,
|
|
24
25
|
value: {}
|
|
25
26
|
});
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
Object.defineProperty(this, "cleanupInterval", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: void 0
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "TRACE_TTL_MS", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: 10 * 60 * 1000
|
|
38
|
-
}); // 10 minutes
|
|
39
|
-
// We must use a cleanup interval because LangSmith can start child spans
|
|
40
|
-
// after arbitrary OTEL parent spans have ended since it uses batching.
|
|
41
|
-
this.cleanupInterval = setInterval(() => this.cleanupStaleTraces(), 60000);
|
|
42
|
-
}
|
|
43
|
-
cleanupStaleTraces() {
|
|
44
|
-
const now = Date.now();
|
|
45
|
-
for (const [traceId, traceInfo] of Object.entries(this.traceMap)) {
|
|
46
|
-
if (now - traceInfo.lastAccessed > this.TRACE_TTL_MS) {
|
|
47
|
-
delete this.traceMap[traceId];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
shutdown() {
|
|
52
|
-
if (this.cleanupInterval) {
|
|
53
|
-
clearInterval(this.cleanupInterval);
|
|
54
|
-
}
|
|
55
|
-
return super.shutdown();
|
|
56
27
|
}
|
|
57
28
|
onStart(span, parentContext) {
|
|
58
29
|
if (!this.traceMap[span.spanContext().traceId]) {
|
|
59
30
|
this.traceMap[span.spanContext().traceId] = {
|
|
60
31
|
spanInfo: {},
|
|
61
|
-
|
|
32
|
+
spanCount: 0,
|
|
62
33
|
};
|
|
63
34
|
}
|
|
64
|
-
this.traceMap[span.spanContext().traceId].
|
|
35
|
+
this.traceMap[span.spanContext().traceId].spanCount++;
|
|
65
36
|
const isTraceable = isTraceableSpan(span);
|
|
66
37
|
const parentSpanId = getParentSpanId(span);
|
|
67
38
|
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
@@ -93,12 +64,20 @@ export class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
|
|
|
93
64
|
const traceInfo = this.traceMap[span.spanContext().traceId];
|
|
94
65
|
if (!traceInfo)
|
|
95
66
|
return;
|
|
96
|
-
traceInfo.lastAccessed = Date.now();
|
|
97
67
|
const spanInfo = traceInfo.spanInfo[span.spanContext().spanId];
|
|
98
68
|
if (!spanInfo)
|
|
99
69
|
return;
|
|
70
|
+
// Decrement span count and cleanup trace if all spans are done
|
|
71
|
+
traceInfo.spanCount--;
|
|
72
|
+
if (traceInfo.spanCount <= 0) {
|
|
73
|
+
delete this.traceMap[span.spanContext().traceId];
|
|
74
|
+
}
|
|
100
75
|
if (spanInfo.isTraceable) {
|
|
101
76
|
super.onEnd(span);
|
|
102
77
|
}
|
|
103
78
|
}
|
|
79
|
+
async shutdown() {
|
|
80
|
+
await RunTree.getSharedClient().awaitPendingTraceBatches();
|
|
81
|
+
await super.shutdown();
|
|
82
|
+
}
|
|
104
83
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
|
|
|
10
10
|
var project_js_1 = require("./utils/project.cjs");
|
|
11
11
|
Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
|
|
12
12
|
// Update using yarn bump-version
|
|
13
|
-
exports.__version__ = "0.3.49-rc.
|
|
13
|
+
exports.__version__ = "0.3.49-rc.4";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
|
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
|
-
export declare const __version__ = "0.3.49-rc.
|
|
6
|
+
export declare const __version__ = "0.3.49-rc.4";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
|
|
|
3
3
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
4
4
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
5
5
|
// Update using yarn bump-version
|
|
6
|
-
export const __version__ = "0.3.49-rc.
|
|
6
|
+
export const __version__ = "0.3.49-rc.4";
|
package/dist/run_trees.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export declare class RunTree implements BaseRun {
|
|
|
101
101
|
set metadata(metadata: KVMap);
|
|
102
102
|
get metadata(): KVMap;
|
|
103
103
|
private static getDefaultConfig;
|
|
104
|
-
|
|
104
|
+
static getSharedClient(): Client;
|
|
105
105
|
createChild(config: RunTreeConfig): RunTree;
|
|
106
106
|
end(outputs?: KVMap, error?: string, endTime?: number, metadata?: KVMap): Promise<void>;
|
|
107
107
|
private _convertToCreate;
|