langsmith 0.3.44 → 0.3.45
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/client.d.ts +2 -2
- package/dist/experimental/otel/exporter.cjs +22 -10
- package/dist/experimental/otel/exporter.d.ts +5 -0
- package/dist/experimental/otel/exporter.js +22 -10
- package/dist/experimental/otel/translator.cjs +2 -2
- package/dist/experimental/otel/translator.js +2 -2
- package/dist/experimental/otel/types.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +18 -6
- package/dist/run_trees.d.ts +5 -1
- package/dist/run_trees.js +18 -6
- package/dist/schemas.d.ts +3 -3
- package/dist/traceable.cjs +5 -2
- package/dist/traceable.js +6 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -187,8 +187,8 @@ interface CreateRunParams {
|
|
|
187
187
|
inputs: KVMap;
|
|
188
188
|
run_type: string;
|
|
189
189
|
id?: string;
|
|
190
|
-
start_time?: number;
|
|
191
|
-
end_time?: number;
|
|
190
|
+
start_time?: number | string;
|
|
191
|
+
end_time?: number | string;
|
|
192
192
|
extra?: KVMap;
|
|
193
193
|
error?: string;
|
|
194
194
|
serialized?: object;
|
|
@@ -77,20 +77,20 @@ class LangSmithOTLPTraceExporter extends exporter_trace_otlp_proto_1.OTLPTraceEx
|
|
|
77
77
|
const defaultBaseUrl = defaultLsEndpoint.replace(/\/$/, "");
|
|
78
78
|
const defaultUrl = `${defaultBaseUrl}/otel/v1/traces`;
|
|
79
79
|
// Configure headers with API key and project if available
|
|
80
|
-
let
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
defaultHeaderString += `,Langsmith-Project=${project}`;
|
|
80
|
+
let headers = config?.headers;
|
|
81
|
+
if (headers === undefined) {
|
|
82
|
+
let defaultHeaderString = (0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_HEADERS") ?? "";
|
|
83
|
+
if (!defaultHeaderString) {
|
|
84
|
+
const apiKey = config?.apiKey ?? (0, env_js_2.getLangSmithEnvironmentVariable)("API_KEY");
|
|
85
|
+
if (apiKey) {
|
|
86
|
+
defaultHeaderString = `x-api-key=${apiKey}`;
|
|
87
|
+
}
|
|
89
88
|
}
|
|
89
|
+
headers = parseHeadersString(defaultHeaderString);
|
|
90
90
|
}
|
|
91
91
|
super({
|
|
92
92
|
url: defaultUrl,
|
|
93
|
-
headers
|
|
93
|
+
headers,
|
|
94
94
|
...config,
|
|
95
95
|
});
|
|
96
96
|
Object.defineProperty(this, "transformExportedSpan", {
|
|
@@ -99,7 +99,15 @@ class LangSmithOTLPTraceExporter extends exporter_trace_otlp_proto_1.OTLPTraceEx
|
|
|
99
99
|
writable: true,
|
|
100
100
|
value: void 0
|
|
101
101
|
});
|
|
102
|
+
Object.defineProperty(this, "projectName", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
});
|
|
102
108
|
this.transformExportedSpan = config?.transformExportedSpan;
|
|
109
|
+
this.projectName =
|
|
110
|
+
config?.projectName ?? (0, env_js_2.getLangSmithEnvironmentVariable)("PROJECT");
|
|
103
111
|
}
|
|
104
112
|
export(spans, resultCallback) {
|
|
105
113
|
if (!(0, env_js_1.isTracingEnabled)()) {
|
|
@@ -193,6 +201,10 @@ class LangSmithOTLPTraceExporter extends exporter_trace_otlp_proto_1.OTLPTraceEx
|
|
|
193
201
|
span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
194
202
|
delete span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
195
203
|
}
|
|
204
|
+
if (span.attributes[constants.LANGSMITH_SESSION_NAME] === undefined &&
|
|
205
|
+
this.projectName !== undefined) {
|
|
206
|
+
span.attributes[constants.LANGSMITH_SESSION_NAME] = this.projectName;
|
|
207
|
+
}
|
|
196
208
|
}
|
|
197
209
|
super.export(spans, resultCallback);
|
|
198
210
|
};
|
|
@@ -32,6 +32,10 @@ export type LangSmithOTLPTraceExporterConfig = ConstructorParameters<typeof OTLP
|
|
|
32
32
|
* The name of the project to export traces to.
|
|
33
33
|
*/
|
|
34
34
|
projectName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Default headers to add to exporter requests.
|
|
37
|
+
*/
|
|
38
|
+
headers?: Record<string, string>;
|
|
35
39
|
};
|
|
36
40
|
/**
|
|
37
41
|
* LangSmith OpenTelemetry trace exporter that extends the standard OTLP trace exporter
|
|
@@ -50,6 +54,7 @@ export type LangSmithOTLPTraceExporterConfig = ConstructorParameters<typeof OTLP
|
|
|
50
54
|
*/
|
|
51
55
|
export declare class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
52
56
|
private transformExportedSpan?;
|
|
57
|
+
private projectName?;
|
|
53
58
|
constructor(config?: LangSmithOTLPTraceExporterConfig);
|
|
54
59
|
export(spans: ReadableSpan[], resultCallback: Parameters<OTLPTraceExporter["export"]>[1]): void;
|
|
55
60
|
}
|
|
@@ -41,20 +41,20 @@ export class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
|
41
41
|
const defaultBaseUrl = defaultLsEndpoint.replace(/\/$/, "");
|
|
42
42
|
const defaultUrl = `${defaultBaseUrl}/otel/v1/traces`;
|
|
43
43
|
// Configure headers with API key and project if available
|
|
44
|
-
let
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
defaultHeaderString += `,Langsmith-Project=${project}`;
|
|
44
|
+
let headers = config?.headers;
|
|
45
|
+
if (headers === undefined) {
|
|
46
|
+
let defaultHeaderString = getEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS") ?? "";
|
|
47
|
+
if (!defaultHeaderString) {
|
|
48
|
+
const apiKey = config?.apiKey ?? getLangSmithEnvironmentVariable("API_KEY");
|
|
49
|
+
if (apiKey) {
|
|
50
|
+
defaultHeaderString = `x-api-key=${apiKey}`;
|
|
51
|
+
}
|
|
53
52
|
}
|
|
53
|
+
headers = parseHeadersString(defaultHeaderString);
|
|
54
54
|
}
|
|
55
55
|
super({
|
|
56
56
|
url: defaultUrl,
|
|
57
|
-
headers
|
|
57
|
+
headers,
|
|
58
58
|
...config,
|
|
59
59
|
});
|
|
60
60
|
Object.defineProperty(this, "transformExportedSpan", {
|
|
@@ -63,7 +63,15 @@ export class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
|
63
63
|
writable: true,
|
|
64
64
|
value: void 0
|
|
65
65
|
});
|
|
66
|
+
Object.defineProperty(this, "projectName", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
66
72
|
this.transformExportedSpan = config?.transformExportedSpan;
|
|
73
|
+
this.projectName =
|
|
74
|
+
config?.projectName ?? getLangSmithEnvironmentVariable("PROJECT");
|
|
67
75
|
}
|
|
68
76
|
export(spans, resultCallback) {
|
|
69
77
|
if (!isTracingEnabled()) {
|
|
@@ -157,6 +165,10 @@ export class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
|
157
165
|
span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
158
166
|
delete span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
159
167
|
}
|
|
168
|
+
if (span.attributes[constants.LANGSMITH_SESSION_NAME] === undefined &&
|
|
169
|
+
this.projectName !== undefined) {
|
|
170
|
+
span.attributes[constants.LANGSMITH_SESSION_NAME] = this.projectName;
|
|
171
|
+
}
|
|
160
172
|
}
|
|
161
173
|
super.export(spans, resultCallback);
|
|
162
174
|
};
|
|
@@ -102,7 +102,7 @@ class LangSmithToOTELTranslator {
|
|
|
102
102
|
}
|
|
103
103
|
// End the span if end_time is present
|
|
104
104
|
if (runInfo.end_time) {
|
|
105
|
-
span.end(runInfo.end_time);
|
|
105
|
+
span.end(new Date(runInfo.end_time));
|
|
106
106
|
}
|
|
107
107
|
return span;
|
|
108
108
|
}
|
|
@@ -126,7 +126,7 @@ class LangSmithToOTELTranslator {
|
|
|
126
126
|
// End the span if end_time is present
|
|
127
127
|
const endTime = runInfo.end_time;
|
|
128
128
|
if (endTime) {
|
|
129
|
-
span.end(endTime);
|
|
129
|
+
span.end(new Date(endTime));
|
|
130
130
|
this.spans.delete(op.id);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -66,7 +66,7 @@ export class LangSmithToOTELTranslator {
|
|
|
66
66
|
}
|
|
67
67
|
// End the span if end_time is present
|
|
68
68
|
if (runInfo.end_time) {
|
|
69
|
-
span.end(runInfo.end_time);
|
|
69
|
+
span.end(new Date(runInfo.end_time));
|
|
70
70
|
}
|
|
71
71
|
return span;
|
|
72
72
|
}
|
|
@@ -90,7 +90,7 @@ export class LangSmithToOTELTranslator {
|
|
|
90
90
|
// End the span if end_time is present
|
|
91
91
|
const endTime = runInfo.end_time;
|
|
92
92
|
if (endTime) {
|
|
93
|
-
span.end(endTime);
|
|
93
|
+
span.end(new Date(endTime));
|
|
94
94
|
this.spans.delete(op.id);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -5,7 +5,7 @@ export interface OTELSpan {
|
|
|
5
5
|
message?: string;
|
|
6
6
|
}) => void;
|
|
7
7
|
recordException: (exception: Error | string) => void;
|
|
8
|
-
end: (endTime?: number) => void;
|
|
8
|
+
end: (endTime?: number | Date) => void;
|
|
9
9
|
}
|
|
10
10
|
export interface OTELTracer {
|
|
11
11
|
startSpan: (name: string, options?: any) => OTELSpan;
|
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.
|
|
13
|
+
exports.__version__ = "0.3.45";
|
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.
|
|
6
|
+
export declare const __version__ = "0.3.45";
|
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.
|
|
6
|
+
export const __version__ = "0.3.45";
|
package/dist/run_trees.cjs
CHANGED
|
@@ -53,7 +53,13 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
|
|
|
53
53
|
// Date only has millisecond precision, so we use the microseconds to break
|
|
54
54
|
// possible ties, avoiding incorrect run order
|
|
55
55
|
const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
|
|
56
|
-
|
|
56
|
+
const microsecondPrecisionDatestring = `${new Date(epoch)
|
|
57
|
+
.toISOString()
|
|
58
|
+
.slice(0, -1)}${paddedOrder}Z`;
|
|
59
|
+
return {
|
|
60
|
+
dottedOrder: stripNonAlphanumeric(microsecondPrecisionDatestring) + runId,
|
|
61
|
+
microsecondPrecisionDatestring,
|
|
62
|
+
};
|
|
57
63
|
}
|
|
58
64
|
/**
|
|
59
65
|
* Baggage header information
|
|
@@ -280,6 +286,12 @@ class RunTree {
|
|
|
280
286
|
writable: true,
|
|
281
287
|
value: void 0
|
|
282
288
|
});
|
|
289
|
+
Object.defineProperty(this, "_serialized_start_time", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
configurable: true,
|
|
292
|
+
writable: true,
|
|
293
|
+
value: void 0
|
|
294
|
+
});
|
|
283
295
|
// If you pass in a run tree directly, return a shallow clone
|
|
284
296
|
if (isRunTree(originalConfig)) {
|
|
285
297
|
Object.assign(this, { ...originalConfig });
|
|
@@ -306,14 +318,14 @@ class RunTree {
|
|
|
306
318
|
this.execution_order ??= 1;
|
|
307
319
|
this.child_execution_order ??= 1;
|
|
308
320
|
if (!this.dotted_order) {
|
|
309
|
-
const
|
|
321
|
+
const { dottedOrder, microsecondPrecisionDatestring } = convertToDottedOrderFormat(this.start_time, this.id, this.execution_order);
|
|
310
322
|
if (this.parent_run) {
|
|
311
|
-
this.dotted_order =
|
|
312
|
-
this.parent_run.dotted_order + "." + currentDottedOrder;
|
|
323
|
+
this.dotted_order = this.parent_run.dotted_order + "." + dottedOrder;
|
|
313
324
|
}
|
|
314
325
|
else {
|
|
315
|
-
this.dotted_order =
|
|
326
|
+
this.dotted_order = dottedOrder;
|
|
316
327
|
}
|
|
328
|
+
this._serialized_start_time = microsecondPrecisionDatestring;
|
|
317
329
|
}
|
|
318
330
|
}
|
|
319
331
|
set metadata(metadata) {
|
|
@@ -436,7 +448,7 @@ class RunTree {
|
|
|
436
448
|
return {
|
|
437
449
|
id: run.id,
|
|
438
450
|
name: run.name,
|
|
439
|
-
start_time: run.start_time,
|
|
451
|
+
start_time: run._serialized_start_time ?? run.start_time,
|
|
440
452
|
end_time: run.end_time,
|
|
441
453
|
run_type: run.run_type,
|
|
442
454
|
reference_example_id: run.reference_example_id,
|
package/dist/run_trees.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Client } from "./client.js";
|
|
2
2
|
import { Attachments, BaseRun, KVMap, RunCreate } from "./schemas.js";
|
|
3
|
-
export declare function convertToDottedOrderFormat(epoch: number, runId: string, executionOrder?: number):
|
|
3
|
+
export declare function convertToDottedOrderFormat(epoch: number, runId: string, executionOrder?: number): {
|
|
4
|
+
dottedOrder: string;
|
|
5
|
+
microsecondPrecisionDatestring: string;
|
|
6
|
+
};
|
|
4
7
|
export interface RunTreeConfig {
|
|
5
8
|
name: string;
|
|
6
9
|
run_type?: string;
|
|
@@ -92,6 +95,7 @@ export declare class RunTree implements BaseRun {
|
|
|
92
95
|
* Projects to replicate this run to with optional updates.
|
|
93
96
|
*/
|
|
94
97
|
replicas?: WriteReplica[];
|
|
98
|
+
private _serialized_start_time;
|
|
95
99
|
constructor(originalConfig: RunTreeConfig | RunTree);
|
|
96
100
|
set metadata(metadata: KVMap);
|
|
97
101
|
get metadata(): KVMap;
|
package/dist/run_trees.js
CHANGED
|
@@ -14,7 +14,13 @@ export function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
|
|
|
14
14
|
// Date only has millisecond precision, so we use the microseconds to break
|
|
15
15
|
// possible ties, avoiding incorrect run order
|
|
16
16
|
const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
|
|
17
|
-
|
|
17
|
+
const microsecondPrecisionDatestring = `${new Date(epoch)
|
|
18
|
+
.toISOString()
|
|
19
|
+
.slice(0, -1)}${paddedOrder}Z`;
|
|
20
|
+
return {
|
|
21
|
+
dottedOrder: stripNonAlphanumeric(microsecondPrecisionDatestring) + runId,
|
|
22
|
+
microsecondPrecisionDatestring,
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
25
|
/**
|
|
20
26
|
* Baggage header information
|
|
@@ -241,6 +247,12 @@ export class RunTree {
|
|
|
241
247
|
writable: true,
|
|
242
248
|
value: void 0
|
|
243
249
|
});
|
|
250
|
+
Object.defineProperty(this, "_serialized_start_time", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
configurable: true,
|
|
253
|
+
writable: true,
|
|
254
|
+
value: void 0
|
|
255
|
+
});
|
|
244
256
|
// If you pass in a run tree directly, return a shallow clone
|
|
245
257
|
if (isRunTree(originalConfig)) {
|
|
246
258
|
Object.assign(this, { ...originalConfig });
|
|
@@ -267,14 +279,14 @@ export class RunTree {
|
|
|
267
279
|
this.execution_order ??= 1;
|
|
268
280
|
this.child_execution_order ??= 1;
|
|
269
281
|
if (!this.dotted_order) {
|
|
270
|
-
const
|
|
282
|
+
const { dottedOrder, microsecondPrecisionDatestring } = convertToDottedOrderFormat(this.start_time, this.id, this.execution_order);
|
|
271
283
|
if (this.parent_run) {
|
|
272
|
-
this.dotted_order =
|
|
273
|
-
this.parent_run.dotted_order + "." + currentDottedOrder;
|
|
284
|
+
this.dotted_order = this.parent_run.dotted_order + "." + dottedOrder;
|
|
274
285
|
}
|
|
275
286
|
else {
|
|
276
|
-
this.dotted_order =
|
|
287
|
+
this.dotted_order = dottedOrder;
|
|
277
288
|
}
|
|
289
|
+
this._serialized_start_time = microsecondPrecisionDatestring;
|
|
278
290
|
}
|
|
279
291
|
}
|
|
280
292
|
set metadata(metadata) {
|
|
@@ -397,7 +409,7 @@ export class RunTree {
|
|
|
397
409
|
return {
|
|
398
410
|
id: run.id,
|
|
399
411
|
name: run.name,
|
|
400
|
-
start_time: run.start_time,
|
|
412
|
+
start_time: run._serialized_start_time ?? run.start_time,
|
|
401
413
|
end_time: run.end_time,
|
|
402
414
|
run_type: run.run_type,
|
|
403
415
|
reference_example_id: run.reference_example_id,
|
package/dist/schemas.d.ts
CHANGED
|
@@ -55,11 +55,11 @@ export interface BaseRun {
|
|
|
55
55
|
/** A human-readable name for the run. */
|
|
56
56
|
name: string;
|
|
57
57
|
/** The epoch time at which the run started, if available. */
|
|
58
|
-
start_time?: number;
|
|
58
|
+
start_time?: number | string;
|
|
59
59
|
/** Specifies the type of run (tool, chain, llm, etc.). */
|
|
60
60
|
run_type: string;
|
|
61
61
|
/** The epoch time at which the run ended, if applicable. */
|
|
62
|
-
end_time?: number;
|
|
62
|
+
end_time?: number | string;
|
|
63
63
|
/** Any additional metadata or settings for the run. */
|
|
64
64
|
extra?: KVMap;
|
|
65
65
|
/** Error message, captured if the run faces any issues. */
|
|
@@ -152,7 +152,7 @@ export interface RunCreate extends BaseRun {
|
|
|
152
152
|
}
|
|
153
153
|
export interface RunUpdate {
|
|
154
154
|
id?: string;
|
|
155
|
-
end_time?: number;
|
|
155
|
+
end_time?: number | string;
|
|
156
156
|
extra?: KVMap;
|
|
157
157
|
tags?: string[];
|
|
158
158
|
error?: string;
|
package/dist/traceable.cjs
CHANGED
|
@@ -17,7 +17,7 @@ traceable_js_1.AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new n
|
|
|
17
17
|
/**
|
|
18
18
|
* Create OpenTelemetry context manager from RunTree if OTEL is enabled.
|
|
19
19
|
*/
|
|
20
|
-
function maybeCreateOtelContext(runTree, tracer
|
|
20
|
+
function maybeCreateOtelContext(runTree, projectName, tracer
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
22
|
) {
|
|
23
23
|
if (!runTree || (0, env_js_2.getEnvironmentVariable)("OTEL_ENABLED") !== "true") {
|
|
@@ -34,6 +34,9 @@ function maybeCreateOtelContext(runTree, tracer
|
|
|
34
34
|
attributes[constants_js_2.LANGSMITH_REFERENCE_EXAMPLE_ID] =
|
|
35
35
|
runTree.reference_example_id;
|
|
36
36
|
}
|
|
37
|
+
if (projectName !== undefined) {
|
|
38
|
+
attributes[constants_js_2.LANGSMITH_SESSION_NAME] = projectName;
|
|
39
|
+
}
|
|
37
40
|
const forceOTELRoot = runTree.extra?.ls_otel_root === true;
|
|
38
41
|
return resolvedTracer.startActiveSpan(runTree.name, {
|
|
39
42
|
attributes,
|
|
@@ -439,7 +442,7 @@ function traceable(wrappedFunc, config) {
|
|
|
439
442
|
const currentRunTree = (0, run_trees_js_1.isRunTree)(currentContext)
|
|
440
443
|
? currentContext
|
|
441
444
|
: undefined;
|
|
442
|
-
const otelContextManager = maybeCreateOtelContext(currentRunTree, config?.tracer);
|
|
445
|
+
const otelContextManager = maybeCreateOtelContext(currentRunTree, config?.project_name, config?.tracer);
|
|
443
446
|
const otel_context = (0, otel_js_1.getOTELContext)();
|
|
444
447
|
const runWithContext = () => {
|
|
445
448
|
const postRunPromise = currentRunTree?.postRun();
|
package/dist/traceable.js
CHANGED
|
@@ -8,12 +8,12 @@ import { getEnvironmentVariable } from "./utils/env.js";
|
|
|
8
8
|
import { __version__ } from "./index.js";
|
|
9
9
|
import { getOTELTrace, getOTELContext } from "./singletons/otel.js";
|
|
10
10
|
import { getUuidFromOtelSpanId } from "./experimental/otel/utils.js";
|
|
11
|
-
import { LANGSMITH_REFERENCE_EXAMPLE_ID } from "./experimental/otel/constants.js";
|
|
11
|
+
import { LANGSMITH_REFERENCE_EXAMPLE_ID, LANGSMITH_SESSION_NAME, } from "./experimental/otel/constants.js";
|
|
12
12
|
AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new AsyncLocalStorage());
|
|
13
13
|
/**
|
|
14
14
|
* Create OpenTelemetry context manager from RunTree if OTEL is enabled.
|
|
15
15
|
*/
|
|
16
|
-
function maybeCreateOtelContext(runTree, tracer
|
|
16
|
+
function maybeCreateOtelContext(runTree, projectName, tracer
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
18
|
) {
|
|
19
19
|
if (!runTree || getEnvironmentVariable("OTEL_ENABLED") !== "true") {
|
|
@@ -30,6 +30,9 @@ function maybeCreateOtelContext(runTree, tracer
|
|
|
30
30
|
attributes[LANGSMITH_REFERENCE_EXAMPLE_ID] =
|
|
31
31
|
runTree.reference_example_id;
|
|
32
32
|
}
|
|
33
|
+
if (projectName !== undefined) {
|
|
34
|
+
attributes[LANGSMITH_SESSION_NAME] = projectName;
|
|
35
|
+
}
|
|
33
36
|
const forceOTELRoot = runTree.extra?.ls_otel_root === true;
|
|
34
37
|
return resolvedTracer.startActiveSpan(runTree.name, {
|
|
35
38
|
attributes,
|
|
@@ -435,7 +438,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
435
438
|
const currentRunTree = isRunTree(currentContext)
|
|
436
439
|
? currentContext
|
|
437
440
|
: undefined;
|
|
438
|
-
const otelContextManager = maybeCreateOtelContext(currentRunTree, config?.tracer);
|
|
441
|
+
const otelContextManager = maybeCreateOtelContext(currentRunTree, config?.project_name, config?.tracer);
|
|
439
442
|
const otel_context = getOTELContext();
|
|
440
443
|
const runWithContext = () => {
|
|
441
444
|
const postRunPromise = currentRunTree?.postRun();
|