@arizeai/openinference-instrumentation-openai 4.4.1 → 4.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/openinference-instrumentation-openai",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
4
4
  "private": false,
5
5
  "description": "OpenInference instrumentation for OpenAI",
6
6
  "keywords": [],
@@ -28,8 +28,8 @@
28
28
  "@opentelemetry/api": "^1.9.0",
29
29
  "@opentelemetry/core": "^2.8.0",
30
30
  "@opentelemetry/instrumentation": "^0.46.0",
31
- "@arizeai/openinference-core": "2.8.0",
32
- "@arizeai/openinference-semantic-conventions": "2.14.0"
31
+ "@arizeai/openinference-core": "2.8.1",
32
+ "@arizeai/openinference-semantic-conventions": "2.15.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@opentelemetry/exporter-trace-otlp-proto": "^0.50.0",
@@ -485,6 +485,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
485
485
  span.setAttributes({
486
486
  // Do not record the output data as it can be large
487
487
  ...getEmbeddingEmbeddingsAttributes(result),
488
+ ...getEmbeddingUsageAttributes(result),
488
489
  });
489
490
  }
490
491
  span.setStatus({ code: SpanStatusCode.OK });
@@ -981,6 +982,19 @@ function getEmbeddingEmbeddingsAttributes(response: CreateEmbeddingResponse): At
981
982
  }, {});
982
983
  }
983
984
 
985
+ /**
986
+ * Get the token usage of an embedding response
987
+ */
988
+ function getEmbeddingUsageAttributes(response: CreateEmbeddingResponse): Attributes {
989
+ if (!response.usage) {
990
+ return {};
991
+ }
992
+ return {
993
+ [SemanticConventions.LLM_TOKEN_COUNT_PROMPT]: response.usage.prompt_tokens,
994
+ [SemanticConventions.LLM_TOKEN_COUNT_TOTAL]: response.usage.total_tokens,
995
+ };
996
+ }
997
+
984
998
  /**
985
999
  * Consumes the stream chunks and adds them to the span
986
1000
  */
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // this is an auto-generated file. see js/scripts/version-update.js
2
- export const VERSION = "4.4.1";
2
+ export const VERSION = "4.4.2";