@arizeai/openinference-instrumentation-openai 4.4.1 → 4.4.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/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +16 -1
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/responsesAttributes.d.ts.map +1 -1
- package/dist/esm/responsesAttributes.js +5 -1
- package/dist/esm/responsesAttributes.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esnext/instrumentation.d.ts.map +1 -1
- package/dist/esnext/instrumentation.js +17 -2
- package/dist/esnext/instrumentation.js.map +1 -1
- package/dist/esnext/responsesAttributes.d.ts.map +1 -1
- package/dist/esnext/responsesAttributes.js +5 -1
- package/dist/esnext/responsesAttributes.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.js +17 -2
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/responsesAttributes.d.ts.map +1 -1
- package/dist/src/responsesAttributes.js +5 -1
- package/dist/src/responsesAttributes.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/instrumentation.ts +19 -1
- package/src/responsesAttributes.ts +5 -1
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arizeai/openinference-instrumentation-openai",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.3",
|
|
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.
|
|
32
|
-
"@arizeai/openinference-semantic-conventions": "2.
|
|
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",
|
package/src/instrumentation.ts
CHANGED
|
@@ -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 });
|
|
@@ -555,7 +556,11 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
555
556
|
...getResponsesOutputMessagesAttributes(result),
|
|
556
557
|
...getResponsesUsageAttributes(result),
|
|
557
558
|
});
|
|
558
|
-
span.setStatus(
|
|
559
|
+
span.setStatus(
|
|
560
|
+
result.status === "failed"
|
|
561
|
+
? { code: SpanStatusCode.ERROR, message: result.error?.message }
|
|
562
|
+
: { code: SpanStatusCode.OK },
|
|
563
|
+
);
|
|
559
564
|
span.end();
|
|
560
565
|
};
|
|
561
566
|
if (isResponseCreateResponse(result)) {
|
|
@@ -981,6 +986,19 @@ function getEmbeddingEmbeddingsAttributes(response: CreateEmbeddingResponse): At
|
|
|
981
986
|
}, {});
|
|
982
987
|
}
|
|
983
988
|
|
|
989
|
+
/**
|
|
990
|
+
* Get the token usage of an embedding response
|
|
991
|
+
*/
|
|
992
|
+
function getEmbeddingUsageAttributes(response: CreateEmbeddingResponse): Attributes {
|
|
993
|
+
if (!response.usage) {
|
|
994
|
+
return {};
|
|
995
|
+
}
|
|
996
|
+
return {
|
|
997
|
+
[SemanticConventions.LLM_TOKEN_COUNT_PROMPT]: response.usage.prompt_tokens,
|
|
998
|
+
[SemanticConventions.LLM_TOKEN_COUNT_TOTAL]: response.usage.total_tokens,
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
|
|
984
1002
|
/**
|
|
985
1003
|
* Consumes the stream chunks and adds them to the span
|
|
986
1004
|
*/
|
|
@@ -255,7 +255,11 @@ export async function consumeResponseStreamEvents(
|
|
|
255
255
|
|
|
256
256
|
for await (const event of stream) {
|
|
257
257
|
switch (event.type) {
|
|
258
|
-
|
|
258
|
+
// A stream can end on any of these; the incomplete and failed ones still carry the
|
|
259
|
+
// partial output and the usage.
|
|
260
|
+
case "response.completed":
|
|
261
|
+
case "response.incomplete":
|
|
262
|
+
case "response.failed": {
|
|
259
263
|
response = event.response;
|
|
260
264
|
break;
|
|
261
265
|
}
|
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.
|
|
2
|
+
export const VERSION = "4.4.3";
|