langsmith 0.3.36 → 0.3.37
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/exporter.cjs +80 -62
- package/dist/experimental/otel/exporter.d.ts +27 -1
- package/dist/experimental/otel/exporter.js +80 -62
- package/dist/experimental/otel/setup.cjs +3 -2
- package/dist/experimental/otel/setup.d.ts +21 -5
- package/dist/experimental/otel/setup.js +4 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -70,10 +70,10 @@ function parseHeadersString(headersStr) {
|
|
|
70
70
|
*/
|
|
71
71
|
class LangSmithOTLPTraceExporter extends exporter_trace_otlp_proto_1.OTLPTraceExporter {
|
|
72
72
|
constructor(config) {
|
|
73
|
-
const
|
|
73
|
+
const defaultLsEndpoint = (0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_ENDPOINT") ||
|
|
74
74
|
(0, env_js_2.getLangSmithEnvironmentVariable)("ENDPOINT") ||
|
|
75
75
|
"https://api.smith.langchain.com";
|
|
76
|
-
const defaultBaseUrl =
|
|
76
|
+
const defaultBaseUrl = defaultLsEndpoint.replace(/\/$/, "");
|
|
77
77
|
const defaultUrl = `${defaultBaseUrl}/otel/v1/traces`;
|
|
78
78
|
// Configure headers with API key and project if available
|
|
79
79
|
let defaultHeaderString = (0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_HEADERS") ?? "";
|
|
@@ -92,82 +92,100 @@ class LangSmithOTLPTraceExporter extends exporter_trace_otlp_proto_1.OTLPTraceEx
|
|
|
92
92
|
headers: parseHeadersString(defaultHeaderString),
|
|
93
93
|
...config,
|
|
94
94
|
});
|
|
95
|
+
Object.defineProperty(this, "transformExportedSpan", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
this.transformExportedSpan = config?.transformExportedSpan;
|
|
95
102
|
}
|
|
96
103
|
export(spans, resultCallback) {
|
|
97
104
|
if (!(0, env_js_1.isTracingEnabled)()) {
|
|
98
105
|
return resultCallback({ code: 0 });
|
|
99
106
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
span
|
|
104
|
-
span.attributes["ai.prompt"];
|
|
107
|
+
const runExport = async () => {
|
|
108
|
+
for (let span of spans) {
|
|
109
|
+
if (this.transformExportedSpan) {
|
|
110
|
+
span = await this.transformExportedSpan(span);
|
|
105
111
|
}
|
|
106
|
-
if (span.attributes[
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
messages = JSON.parse(span.attributes["ai.prompt.messages"]);
|
|
112
|
+
if (!span.attributes[constants.GENAI_PROMPT]) {
|
|
113
|
+
if (span.attributes["ai.prompt"]) {
|
|
114
|
+
span.attributes[constants.GENAI_PROMPT] =
|
|
115
|
+
span.attributes["ai.prompt"];
|
|
111
116
|
}
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
if (span.attributes["ai.prompt.messages"] &&
|
|
118
|
+
typeof span.attributes["ai.prompt.messages"] === "string") {
|
|
119
|
+
let messages;
|
|
120
|
+
try {
|
|
121
|
+
messages = JSON.parse(span.attributes["ai.prompt.messages"]);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
console.error("Failed to parse ai.prompt.messages", e);
|
|
125
|
+
}
|
|
126
|
+
if (messages && Array.isArray(messages)) {
|
|
127
|
+
span.attributes[constants.GENAI_PROMPT] = JSON.stringify({
|
|
128
|
+
input: messages,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
114
131
|
}
|
|
115
|
-
if (
|
|
116
|
-
span.attributes[constants.GENAI_PROMPT] =
|
|
117
|
-
|
|
118
|
-
});
|
|
132
|
+
if (span.attributes["ai.toolCall.args"]) {
|
|
133
|
+
span.attributes[constants.GENAI_PROMPT] =
|
|
134
|
+
span.attributes["ai.toolCall.args"];
|
|
119
135
|
}
|
|
120
136
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const metadataKey = key.replace("ai.telemetry.metadata.", "");
|
|
130
|
-
span.attributes[`${constants.LANGSMITH_METADATA}.${metadataKey}`] =
|
|
131
|
-
value;
|
|
132
|
-
delete span.attributes[key];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (!span.attributes[constants.GENAI_COMPLETION]) {
|
|
136
|
-
if (span.attributes["ai.response.text"]) {
|
|
137
|
-
span.attributes[constants.GENAI_COMPLETION] =
|
|
138
|
-
span.attributes["ai.response.text"];
|
|
139
|
-
}
|
|
140
|
-
if (span.attributes["ai.response.choices"]) {
|
|
141
|
-
span.attributes[constants.GENAI_COMPLETION] =
|
|
142
|
-
span.attributes["ai.response.choices"];
|
|
137
|
+
// Iterate over all attributes starting with "ai.telemetry.metadata"
|
|
138
|
+
for (const [key, value] of Object.entries(span.attributes)) {
|
|
139
|
+
if (key.startsWith("ai.telemetry.metadata.")) {
|
|
140
|
+
const metadataKey = key.replace("ai.telemetry.metadata.", "");
|
|
141
|
+
span.attributes[`${constants.LANGSMITH_METADATA}.${metadataKey}`] =
|
|
142
|
+
value;
|
|
143
|
+
delete span.attributes[key];
|
|
144
|
+
}
|
|
143
145
|
}
|
|
144
|
-
if (span.attributes[
|
|
145
|
-
span.attributes[
|
|
146
|
-
span.attributes[
|
|
146
|
+
if (!span.attributes[constants.GENAI_COMPLETION]) {
|
|
147
|
+
if (span.attributes["ai.response.text"]) {
|
|
148
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
149
|
+
span.attributes["ai.response.text"];
|
|
150
|
+
}
|
|
151
|
+
if (span.attributes["ai.response.choices"]) {
|
|
152
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
153
|
+
span.attributes["ai.response.choices"];
|
|
154
|
+
}
|
|
155
|
+
if (span.attributes["ai.response.object"]) {
|
|
156
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
157
|
+
span.attributes["ai.response.object"];
|
|
158
|
+
}
|
|
159
|
+
if (span.attributes["ai.response.toolCalls"]) {
|
|
160
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
161
|
+
span.attributes["ai.response.toolCalls"];
|
|
162
|
+
}
|
|
163
|
+
if (span.attributes["ai.toolCall.result"]) {
|
|
164
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
165
|
+
span.attributes["ai.toolCall.result"];
|
|
166
|
+
}
|
|
147
167
|
}
|
|
148
|
-
if (span.attributes["ai.
|
|
149
|
-
span.attributes[
|
|
150
|
-
|
|
168
|
+
if (typeof span.attributes["ai.operationId"] === "string" &&
|
|
169
|
+
constants.AI_SDK_LLM_OPERATIONS.includes(span.attributes["ai.operationId"])) {
|
|
170
|
+
span.attributes[constants.LANGSMITH_RUN_TYPE] = "llm";
|
|
151
171
|
}
|
|
152
|
-
if (span.attributes["ai.
|
|
153
|
-
span.attributes[
|
|
154
|
-
|
|
172
|
+
else if (typeof span.attributes["ai.operationId"] === "string" &&
|
|
173
|
+
constants.AI_SDK_TOOL_OPERATIONS.includes(span.attributes["ai.operationId"])) {
|
|
174
|
+
span.attributes[constants.LANGSMITH_RUN_TYPE] = "tool";
|
|
175
|
+
if (span.attributes["ai.toolCall.name"]) {
|
|
176
|
+
span.attributes[constants.LANGSMITH_NAME] =
|
|
177
|
+
span.attributes["ai.toolCall.name"];
|
|
178
|
+
}
|
|
155
179
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
else if (typeof span.attributes["ai.operationId"] === "string" &&
|
|
162
|
-
constants.AI_SDK_TOOL_OPERATIONS.includes(span.attributes["ai.operationId"])) {
|
|
163
|
-
span.attributes[constants.LANGSMITH_RUN_TYPE] = "tool";
|
|
164
|
-
if (span.attributes["ai.toolCall.name"]) {
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
166
|
-
span.name = span.attributes["ai.toolCall.name"];
|
|
180
|
+
if (span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`]) {
|
|
181
|
+
span.attributes[constants.LANGSMITH_NAME] =
|
|
182
|
+
span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
183
|
+
delete span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
167
184
|
}
|
|
168
185
|
}
|
|
169
|
-
|
|
170
|
-
|
|
186
|
+
super.export(spans, resultCallback);
|
|
187
|
+
};
|
|
188
|
+
void runExport();
|
|
171
189
|
}
|
|
172
190
|
}
|
|
173
191
|
exports.LangSmithOTLPTraceExporter = LangSmithOTLPTraceExporter;
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
2
2
|
import { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
export type LangSmithOTLPTraceExporterConfig = ConstructorParameters<typeof OTLPTraceExporter>[0] & {
|
|
4
|
+
/**
|
|
5
|
+
* A function that takes an exported span and returns a transformed version of it.
|
|
6
|
+
* May be used to add or remove attributes from the span.
|
|
7
|
+
*
|
|
8
|
+
* For example, to add a custom attribute to the span, you can do:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { LangSmithOTLPTraceExporter } from "langsmith/experimental/otel/exporter";
|
|
12
|
+
*
|
|
13
|
+
* const exporter = new LangSmithOTLPTraceExporter({
|
|
14
|
+
* transformExportedSpan: (span) => {
|
|
15
|
+
* if (span.name === "foo") {
|
|
16
|
+
* span.attributes["langsmith.metadata.bar"] = "baz";
|
|
17
|
+
* }
|
|
18
|
+
* return span;
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param span - The span to transform.
|
|
24
|
+
* @returns A transformed version of the span.
|
|
25
|
+
*/
|
|
26
|
+
transformExportedSpan?: (span: ReadableSpan) => ReadableSpan | Promise<ReadableSpan>;
|
|
27
|
+
};
|
|
3
28
|
/**
|
|
4
29
|
* LangSmith OpenTelemetry trace exporter that extends the standard OTLP trace exporter
|
|
5
30
|
* with LangSmith-specific configuration and span attribute transformations.
|
|
@@ -16,6 +41,7 @@ import { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
|
16
41
|
* Any provided config will override these defaults.
|
|
17
42
|
*/
|
|
18
43
|
export declare class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
19
|
-
|
|
44
|
+
private transformExportedSpan?;
|
|
45
|
+
constructor(config?: LangSmithOTLPTraceExporterConfig);
|
|
20
46
|
export(spans: ReadableSpan[], resultCallback: Parameters<OTLPTraceExporter["export"]>[1]): void;
|
|
21
47
|
}
|
|
@@ -34,10 +34,10 @@ function parseHeadersString(headersStr) {
|
|
|
34
34
|
*/
|
|
35
35
|
export class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
36
36
|
constructor(config) {
|
|
37
|
-
const
|
|
37
|
+
const defaultLsEndpoint = getEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT") ||
|
|
38
38
|
getLangSmithEnvironmentVariable("ENDPOINT") ||
|
|
39
39
|
"https://api.smith.langchain.com";
|
|
40
|
-
const defaultBaseUrl =
|
|
40
|
+
const defaultBaseUrl = defaultLsEndpoint.replace(/\/$/, "");
|
|
41
41
|
const defaultUrl = `${defaultBaseUrl}/otel/v1/traces`;
|
|
42
42
|
// Configure headers with API key and project if available
|
|
43
43
|
let defaultHeaderString = getEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS") ?? "";
|
|
@@ -56,81 +56,99 @@ export class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
|
|
|
56
56
|
headers: parseHeadersString(defaultHeaderString),
|
|
57
57
|
...config,
|
|
58
58
|
});
|
|
59
|
+
Object.defineProperty(this, "transformExportedSpan", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
this.transformExportedSpan = config?.transformExportedSpan;
|
|
59
66
|
}
|
|
60
67
|
export(spans, resultCallback) {
|
|
61
68
|
if (!isTracingEnabled()) {
|
|
62
69
|
return resultCallback({ code: 0 });
|
|
63
70
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
span
|
|
68
|
-
span.attributes["ai.prompt"];
|
|
71
|
+
const runExport = async () => {
|
|
72
|
+
for (let span of spans) {
|
|
73
|
+
if (this.transformExportedSpan) {
|
|
74
|
+
span = await this.transformExportedSpan(span);
|
|
69
75
|
}
|
|
70
|
-
if (span.attributes[
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
messages = JSON.parse(span.attributes["ai.prompt.messages"]);
|
|
76
|
+
if (!span.attributes[constants.GENAI_PROMPT]) {
|
|
77
|
+
if (span.attributes["ai.prompt"]) {
|
|
78
|
+
span.attributes[constants.GENAI_PROMPT] =
|
|
79
|
+
span.attributes["ai.prompt"];
|
|
75
80
|
}
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
if (span.attributes["ai.prompt.messages"] &&
|
|
82
|
+
typeof span.attributes["ai.prompt.messages"] === "string") {
|
|
83
|
+
let messages;
|
|
84
|
+
try {
|
|
85
|
+
messages = JSON.parse(span.attributes["ai.prompt.messages"]);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error("Failed to parse ai.prompt.messages", e);
|
|
89
|
+
}
|
|
90
|
+
if (messages && Array.isArray(messages)) {
|
|
91
|
+
span.attributes[constants.GENAI_PROMPT] = JSON.stringify({
|
|
92
|
+
input: messages,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
78
95
|
}
|
|
79
|
-
if (
|
|
80
|
-
span.attributes[constants.GENAI_PROMPT] =
|
|
81
|
-
|
|
82
|
-
});
|
|
96
|
+
if (span.attributes["ai.toolCall.args"]) {
|
|
97
|
+
span.attributes[constants.GENAI_PROMPT] =
|
|
98
|
+
span.attributes["ai.toolCall.args"];
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const metadataKey = key.replace("ai.telemetry.metadata.", "");
|
|
94
|
-
span.attributes[`${constants.LANGSMITH_METADATA}.${metadataKey}`] =
|
|
95
|
-
value;
|
|
96
|
-
delete span.attributes[key];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (!span.attributes[constants.GENAI_COMPLETION]) {
|
|
100
|
-
if (span.attributes["ai.response.text"]) {
|
|
101
|
-
span.attributes[constants.GENAI_COMPLETION] =
|
|
102
|
-
span.attributes["ai.response.text"];
|
|
103
|
-
}
|
|
104
|
-
if (span.attributes["ai.response.choices"]) {
|
|
105
|
-
span.attributes[constants.GENAI_COMPLETION] =
|
|
106
|
-
span.attributes["ai.response.choices"];
|
|
101
|
+
// Iterate over all attributes starting with "ai.telemetry.metadata"
|
|
102
|
+
for (const [key, value] of Object.entries(span.attributes)) {
|
|
103
|
+
if (key.startsWith("ai.telemetry.metadata.")) {
|
|
104
|
+
const metadataKey = key.replace("ai.telemetry.metadata.", "");
|
|
105
|
+
span.attributes[`${constants.LANGSMITH_METADATA}.${metadataKey}`] =
|
|
106
|
+
value;
|
|
107
|
+
delete span.attributes[key];
|
|
108
|
+
}
|
|
107
109
|
}
|
|
108
|
-
if (span.attributes[
|
|
109
|
-
span.attributes[
|
|
110
|
-
span.attributes[
|
|
110
|
+
if (!span.attributes[constants.GENAI_COMPLETION]) {
|
|
111
|
+
if (span.attributes["ai.response.text"]) {
|
|
112
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
113
|
+
span.attributes["ai.response.text"];
|
|
114
|
+
}
|
|
115
|
+
if (span.attributes["ai.response.choices"]) {
|
|
116
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
117
|
+
span.attributes["ai.response.choices"];
|
|
118
|
+
}
|
|
119
|
+
if (span.attributes["ai.response.object"]) {
|
|
120
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
121
|
+
span.attributes["ai.response.object"];
|
|
122
|
+
}
|
|
123
|
+
if (span.attributes["ai.response.toolCalls"]) {
|
|
124
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
125
|
+
span.attributes["ai.response.toolCalls"];
|
|
126
|
+
}
|
|
127
|
+
if (span.attributes["ai.toolCall.result"]) {
|
|
128
|
+
span.attributes[constants.GENAI_COMPLETION] =
|
|
129
|
+
span.attributes["ai.toolCall.result"];
|
|
130
|
+
}
|
|
111
131
|
}
|
|
112
|
-
if (span.attributes["ai.
|
|
113
|
-
span.attributes[
|
|
114
|
-
|
|
132
|
+
if (typeof span.attributes["ai.operationId"] === "string" &&
|
|
133
|
+
constants.AI_SDK_LLM_OPERATIONS.includes(span.attributes["ai.operationId"])) {
|
|
134
|
+
span.attributes[constants.LANGSMITH_RUN_TYPE] = "llm";
|
|
115
135
|
}
|
|
116
|
-
if (span.attributes["ai.
|
|
117
|
-
span.attributes[
|
|
118
|
-
|
|
136
|
+
else if (typeof span.attributes["ai.operationId"] === "string" &&
|
|
137
|
+
constants.AI_SDK_TOOL_OPERATIONS.includes(span.attributes["ai.operationId"])) {
|
|
138
|
+
span.attributes[constants.LANGSMITH_RUN_TYPE] = "tool";
|
|
139
|
+
if (span.attributes["ai.toolCall.name"]) {
|
|
140
|
+
span.attributes[constants.LANGSMITH_NAME] =
|
|
141
|
+
span.attributes["ai.toolCall.name"];
|
|
142
|
+
}
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
else if (typeof span.attributes["ai.operationId"] === "string" &&
|
|
126
|
-
constants.AI_SDK_TOOL_OPERATIONS.includes(span.attributes["ai.operationId"])) {
|
|
127
|
-
span.attributes[constants.LANGSMITH_RUN_TYPE] = "tool";
|
|
128
|
-
if (span.attributes["ai.toolCall.name"]) {
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
-
span.name = span.attributes["ai.toolCall.name"];
|
|
144
|
+
if (span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`]) {
|
|
145
|
+
span.attributes[constants.LANGSMITH_NAME] =
|
|
146
|
+
span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
147
|
+
delete span.attributes[`${constants.LANGSMITH_METADATA}.ls_run_name`];
|
|
131
148
|
}
|
|
132
149
|
}
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
super.export(spans, resultCallback);
|
|
151
|
+
};
|
|
152
|
+
void runExport();
|
|
135
153
|
}
|
|
136
154
|
}
|
|
@@ -40,7 +40,8 @@ const otel_js_1 = require("../../singletons/otel.cjs");
|
|
|
40
40
|
* initializeOTEL({ globalTracerProvider: customProvider });
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
const initializeOTEL = (
|
|
43
|
+
const initializeOTEL = (config = {}) => {
|
|
44
|
+
const { globalTracerProvider, globalContextManager, exporterConfig } = config;
|
|
44
45
|
const otel = {
|
|
45
46
|
trace: api_1.trace,
|
|
46
47
|
context: api_1.context,
|
|
@@ -51,7 +52,7 @@ const initializeOTEL = ({ globalTracerProvider, globalContextManager, } = {}) =>
|
|
|
51
52
|
contextManager.enable();
|
|
52
53
|
api_1.context.setGlobalContextManager(contextManager);
|
|
53
54
|
}
|
|
54
|
-
const DEFAULT_LANGSMITH_SPAN_EXPORTER = new exporter_js_1.LangSmithOTLPTraceExporter(
|
|
55
|
+
const DEFAULT_LANGSMITH_SPAN_EXPORTER = new exporter_js_1.LangSmithOTLPTraceExporter(exporterConfig);
|
|
55
56
|
const DEFAULT_LANGSMITH_SPAN_PROCESSOR = new sdk_trace_base_1.BatchSpanProcessor(DEFAULT_LANGSMITH_SPAN_EXPORTER);
|
|
56
57
|
if (!globalTracerProvider) {
|
|
57
58
|
const DEFAULT_LANGSMITH_TRACER_PROVIDER = new sdk_trace_base_1.BasicTracerProvider({
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { type TracerProvider, type ContextManager } from "@opentelemetry/api";
|
|
2
2
|
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
-
import { LangSmithOTLPTraceExporter } from "./exporter.js";
|
|
3
|
+
import { LangSmithOTLPTraceExporter, LangSmithOTLPTraceExporterConfig } from "./exporter.js";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for initializing OpenTelemetry with LangSmith.
|
|
6
|
+
*/
|
|
7
|
+
export type InitializeOTELConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* Optional custom OTEL TracerProvider to use instead of
|
|
10
|
+
* creating and globally setting a new one.
|
|
11
|
+
*/
|
|
12
|
+
globalTracerProvider?: TracerProvider;
|
|
13
|
+
/**
|
|
14
|
+
* Optional custom OTEL ContextManager to use instead of
|
|
15
|
+
* creating and globally setting a new one with AsyncHooksContextManager.
|
|
16
|
+
*/
|
|
17
|
+
globalContextManager?: ContextManager;
|
|
18
|
+
/**
|
|
19
|
+
* Optional configuration passed to the default LangSmith OTLP trace exporter.
|
|
20
|
+
*/
|
|
21
|
+
exporterConfig?: LangSmithOTLPTraceExporterConfig;
|
|
22
|
+
};
|
|
4
23
|
/**
|
|
5
24
|
* Initializes OpenTelemetry with LangSmith-specific configuration for tracing.
|
|
6
25
|
*
|
|
@@ -32,10 +51,7 @@ import { LangSmithOTLPTraceExporter } from "./exporter.js";
|
|
|
32
51
|
* initializeOTEL({ globalTracerProvider: customProvider });
|
|
33
52
|
* ```
|
|
34
53
|
*/
|
|
35
|
-
export declare const initializeOTEL: (
|
|
36
|
-
globalTracerProvider?: TracerProvider;
|
|
37
|
-
globalContextManager?: ContextManager;
|
|
38
|
-
}) => {
|
|
54
|
+
export declare const initializeOTEL: (config?: InitializeOTELConfig) => {
|
|
39
55
|
DEFAULT_LANGSMITH_TRACER_PROVIDER: TracerProvider;
|
|
40
56
|
DEFAULT_LANGSMITH_SPAN_PROCESSOR: BatchSpanProcessor;
|
|
41
57
|
DEFAULT_LANGSMITH_SPAN_EXPORTER: LangSmithOTLPTraceExporter;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { AsyncHooksContextManager } from "@opentelemetry/context-async-hooks";
|
|
5
5
|
import { trace as otel_trace, context as otel_context, } from "@opentelemetry/api";
|
|
6
6
|
import { BatchSpanProcessor, BasicTracerProvider, } from "@opentelemetry/sdk-trace-base";
|
|
7
|
-
import { LangSmithOTLPTraceExporter } from "./exporter.js";
|
|
7
|
+
import { LangSmithOTLPTraceExporter, } from "./exporter.js";
|
|
8
8
|
import { setDefaultOTLPTracerComponents, setOTELInstances, } from "../../singletons/otel.js";
|
|
9
9
|
/**
|
|
10
10
|
* Initializes OpenTelemetry with LangSmith-specific configuration for tracing.
|
|
@@ -37,7 +37,8 @@ import { setDefaultOTLPTracerComponents, setOTELInstances, } from "../../singlet
|
|
|
37
37
|
* initializeOTEL({ globalTracerProvider: customProvider });
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export const initializeOTEL = (
|
|
40
|
+
export const initializeOTEL = (config = {}) => {
|
|
41
|
+
const { globalTracerProvider, globalContextManager, exporterConfig } = config;
|
|
41
42
|
const otel = {
|
|
42
43
|
trace: otel_trace,
|
|
43
44
|
context: otel_context,
|
|
@@ -48,7 +49,7 @@ export const initializeOTEL = ({ globalTracerProvider, globalContextManager, } =
|
|
|
48
49
|
contextManager.enable();
|
|
49
50
|
otel_context.setGlobalContextManager(contextManager);
|
|
50
51
|
}
|
|
51
|
-
const DEFAULT_LANGSMITH_SPAN_EXPORTER = new LangSmithOTLPTraceExporter(
|
|
52
|
+
const DEFAULT_LANGSMITH_SPAN_EXPORTER = new LangSmithOTLPTraceExporter(exporterConfig);
|
|
52
53
|
const DEFAULT_LANGSMITH_SPAN_PROCESSOR = new BatchSpanProcessor(DEFAULT_LANGSMITH_SPAN_EXPORTER);
|
|
53
54
|
if (!globalTracerProvider) {
|
|
54
55
|
const DEFAULT_LANGSMITH_TRACER_PROVIDER = new BasicTracerProvider({
|
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.37";
|
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.37";
|
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.37";
|