langsmith 0.3.49-rc.2 → 0.3.49-rc.3
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 +11 -32
- package/dist/experimental/otel/processor.d.ts +1 -4
- package/dist/experimental/otel/processor.js +11 -32
- 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,19 @@ 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
31
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return super.shutdown();
|
|
32
|
+
async forceFlush() {
|
|
33
|
+
await run_trees_js_1.RunTree.getSharedClient().awaitPendingTraceBatches();
|
|
34
|
+
await super.forceFlush();
|
|
60
35
|
}
|
|
61
36
|
onStart(span, parentContext) {
|
|
62
37
|
if (!this.traceMap[span.spanContext().traceId]) {
|
|
63
38
|
this.traceMap[span.spanContext().traceId] = {
|
|
64
39
|
spanInfo: {},
|
|
65
|
-
|
|
40
|
+
spanCount: 0,
|
|
66
41
|
};
|
|
67
42
|
}
|
|
68
|
-
this.traceMap[span.spanContext().traceId].
|
|
43
|
+
this.traceMap[span.spanContext().traceId].spanCount++;
|
|
69
44
|
const isTraceable = isTraceableSpan(span);
|
|
70
45
|
const parentSpanId = getParentSpanId(span);
|
|
71
46
|
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
@@ -97,10 +72,14 @@ class LangSmithOTLPSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
|
|
|
97
72
|
const traceInfo = this.traceMap[span.spanContext().traceId];
|
|
98
73
|
if (!traceInfo)
|
|
99
74
|
return;
|
|
100
|
-
traceInfo.lastAccessed = Date.now();
|
|
101
75
|
const spanInfo = traceInfo.spanInfo[span.spanContext().spanId];
|
|
102
76
|
if (!spanInfo)
|
|
103
77
|
return;
|
|
78
|
+
// Decrement span count and cleanup trace if all spans are done
|
|
79
|
+
traceInfo.spanCount--;
|
|
80
|
+
if (traceInfo.spanCount <= 0) {
|
|
81
|
+
delete this.traceMap[span.spanContext().traceId];
|
|
82
|
+
}
|
|
104
83
|
if (spanInfo.isTraceable) {
|
|
105
84
|
super.onEnd(span);
|
|
106
85
|
}
|
|
@@ -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
|
-
|
|
14
|
-
shutdown(): Promise<void>;
|
|
11
|
+
forceFlush(): Promise<void>;
|
|
15
12
|
onStart(span: Span, parentContext: Context): void;
|
|
16
13
|
onEnd(span: ReadableSpan): 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,19 @@ 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
27
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
return super.shutdown();
|
|
28
|
+
async forceFlush() {
|
|
29
|
+
await RunTree.getSharedClient().awaitPendingTraceBatches();
|
|
30
|
+
await super.forceFlush();
|
|
56
31
|
}
|
|
57
32
|
onStart(span, parentContext) {
|
|
58
33
|
if (!this.traceMap[span.spanContext().traceId]) {
|
|
59
34
|
this.traceMap[span.spanContext().traceId] = {
|
|
60
35
|
spanInfo: {},
|
|
61
|
-
|
|
36
|
+
spanCount: 0,
|
|
62
37
|
};
|
|
63
38
|
}
|
|
64
|
-
this.traceMap[span.spanContext().traceId].
|
|
39
|
+
this.traceMap[span.spanContext().traceId].spanCount++;
|
|
65
40
|
const isTraceable = isTraceableSpan(span);
|
|
66
41
|
const parentSpanId = getParentSpanId(span);
|
|
67
42
|
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
@@ -93,10 +68,14 @@ export class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
|
|
|
93
68
|
const traceInfo = this.traceMap[span.spanContext().traceId];
|
|
94
69
|
if (!traceInfo)
|
|
95
70
|
return;
|
|
96
|
-
traceInfo.lastAccessed = Date.now();
|
|
97
71
|
const spanInfo = traceInfo.spanInfo[span.spanContext().spanId];
|
|
98
72
|
if (!spanInfo)
|
|
99
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
|
+
}
|
|
100
79
|
if (spanInfo.isTraceable) {
|
|
101
80
|
super.onEnd(span);
|
|
102
81
|
}
|
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.3";
|
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.3";
|
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.3";
|
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;
|