Skip to content

Commit 39438b5

Browse files
capture reasoning effort openai
1 parent ddb1241 commit 39438b5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ATTR_GEN_AI_REQUEST_REASONING_EFFORT = "gen_ai.request.reasoning_effort";

packages/instrumentation-openai/src/instrumentation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { encodingForModel, TiktokenModel, Tiktoken } from "js-tiktoken";
5656
type APIPromiseType<T> = Promise<T> & {
5757
_thenUnwrap: <U>(onFulfilled: (value: T) => U) => APIPromiseType<U>;
5858
};
59+
import { ATTR_GEN_AI_REQUEST_REASONING_EFFORT } from "./attrs";
5960
import {
6061
wrapImageGeneration,
6162
wrapImageEdit,
@@ -333,6 +334,13 @@ export class OpenAIInstrumentation extends InstrumentationBase {
333334
attributes[SpanAttributes.LLM_PRESENCE_PENALTY] =
334335
params.presence_penalty;
335336
}
337+
if ("reasoning_effort" in params) {
338+
if (typeof params.reasoning_effort === "string") {
339+
attributes[ATTR_GEN_AI_REQUEST_REASONING_EFFORT] = params.reasoning_effort;
340+
} else {
341+
attributes[ATTR_GEN_AI_REQUEST_REASONING_EFFORT] = JSON.stringify(params.reasoning_effort);
342+
}
343+
}
336344

337345
if (
338346
params.extraAttributes !== undefined &&

0 commit comments

Comments
 (0)