langsmith 0.6.1 → 0.6.2

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.
@@ -46,6 +46,11 @@ const WELL_KNOWN_OPERATION_NAMES = {
46
46
  function getOperationName(runType) {
47
47
  return WELL_KNOWN_OPERATION_NAMES[runType] || runType;
48
48
  }
49
+ function isPrimitive(value) {
50
+ return (typeof value === "string" ||
51
+ typeof value === "number" ||
52
+ typeof value === "boolean");
53
+ }
49
54
  class LangSmithToOTELTranslator {
50
55
  constructor() {
51
56
  Object.defineProperty(this, "spans", {
@@ -178,6 +183,12 @@ class LangSmithToOTELTranslator {
178
183
  if (modelName) {
179
184
  span.setAttribute(constants.GEN_AI_REQUEST_MODEL, modelName);
180
185
  }
186
+ // Set usage from metadata if available
187
+ // This can be overriden by `run.outputs.usage_metadata` later if present.
188
+ if (runInfo.extra?.metadata?.usage_metadata &&
189
+ typeof runInfo.extra.metadata.usage_metadata === "object") {
190
+ span.setAttribute(constants.LANGSMITH_USAGE_METADATA, JSON.stringify(runInfo.extra.metadata.usage_metadata));
191
+ }
181
192
  // Set token usage information
182
193
  if ("prompt_tokens" in runInfo &&
183
194
  typeof runInfo.prompt_tokens === "number") {
@@ -196,7 +207,7 @@ class LangSmithToOTELTranslator {
196
207
  const metadata = runInfo.extra?.metadata || {};
197
208
  for (const [key, value] of Object.entries(metadata)) {
198
209
  if (value !== null && value !== undefined) {
199
- span.setAttribute(`${constants.LANGSMITH_METADATA}.${key}`, String(value));
210
+ span.setAttribute(`${constants.LANGSMITH_METADATA}.${key}`, isPrimitive(value) ? String(value) : JSON.stringify(value));
200
211
  }
201
212
  }
202
213
  const tags = runInfo.tags;
@@ -365,6 +376,9 @@ class LangSmithToOTELTranslator {
365
376
  if (outputs.usage_metadata &&
366
377
  typeof outputs.usage_metadata === "object") {
367
378
  const usageMetadata = outputs.usage_metadata;
379
+ // Set usage from outputs if available
380
+ // This overrides the usage from metadata if present.
381
+ span.setAttribute(constants.LANGSMITH_USAGE_METADATA, JSON.stringify(usageMetadata));
368
382
  if (usageMetadata.input_token_details) {
369
383
  span.setAttribute(constants.GEN_AI_USAGE_INPUT_TOKEN_DETAILS, JSON.stringify(usageMetadata.input_token_details));
370
384
  }
@@ -10,6 +10,11 @@ const WELL_KNOWN_OPERATION_NAMES = {
10
10
  function getOperationName(runType) {
11
11
  return WELL_KNOWN_OPERATION_NAMES[runType] || runType;
12
12
  }
13
+ function isPrimitive(value) {
14
+ return (typeof value === "string" ||
15
+ typeof value === "number" ||
16
+ typeof value === "boolean");
17
+ }
13
18
  export class LangSmithToOTELTranslator {
14
19
  constructor() {
15
20
  Object.defineProperty(this, "spans", {
@@ -142,6 +147,12 @@ export class LangSmithToOTELTranslator {
142
147
  if (modelName) {
143
148
  span.setAttribute(constants.GEN_AI_REQUEST_MODEL, modelName);
144
149
  }
150
+ // Set usage from metadata if available
151
+ // This can be overriden by `run.outputs.usage_metadata` later if present.
152
+ if (runInfo.extra?.metadata?.usage_metadata &&
153
+ typeof runInfo.extra.metadata.usage_metadata === "object") {
154
+ span.setAttribute(constants.LANGSMITH_USAGE_METADATA, JSON.stringify(runInfo.extra.metadata.usage_metadata));
155
+ }
145
156
  // Set token usage information
146
157
  if ("prompt_tokens" in runInfo &&
147
158
  typeof runInfo.prompt_tokens === "number") {
@@ -160,7 +171,7 @@ export class LangSmithToOTELTranslator {
160
171
  const metadata = runInfo.extra?.metadata || {};
161
172
  for (const [key, value] of Object.entries(metadata)) {
162
173
  if (value !== null && value !== undefined) {
163
- span.setAttribute(`${constants.LANGSMITH_METADATA}.${key}`, String(value));
174
+ span.setAttribute(`${constants.LANGSMITH_METADATA}.${key}`, isPrimitive(value) ? String(value) : JSON.stringify(value));
164
175
  }
165
176
  }
166
177
  const tags = runInfo.tags;
@@ -329,6 +340,9 @@ export class LangSmithToOTELTranslator {
329
340
  if (outputs.usage_metadata &&
330
341
  typeof outputs.usage_metadata === "object") {
331
342
  const usageMetadata = outputs.usage_metadata;
343
+ // Set usage from outputs if available
344
+ // This overrides the usage from metadata if present.
345
+ span.setAttribute(constants.LANGSMITH_USAGE_METADATA, JSON.stringify(usageMetadata));
332
346
  if (usageMetadata.input_token_details) {
333
347
  span.setAttribute(constants.GEN_AI_USAGE_INPUT_TOKEN_DETAILS, JSON.stringify(usageMetadata.input_token_details));
334
348
  }
package/dist/index.cjs CHANGED
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
18
18
  Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
19
19
  Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
20
20
  // Update using pnpm bump-version
21
- exports.__version__ = "0.6.1";
21
+ exports.__version__ = "0.6.2";
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
6
  export { uuid7, uuid7FromTime } from "./uuid.js";
7
7
  export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
8
- export declare const __version__ = "0.6.1";
8
+ export declare const __version__ = "0.6.2";
package/dist/index.js CHANGED
@@ -5,4 +5,4 @@ export { getDefaultProjectName } from "./utils/project.js";
5
5
  export { uuid7, uuid7FromTime } from "./uuid.js";
6
6
  export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
7
7
  // Update using pnpm bump-version
8
- export const __version__ = "0.6.1";
8
+ export const __version__ = "0.6.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "pnpm@10.33.0",
6
6
  "files": [