Skip to content

Commit df7ca6e

Browse files
committed
revert unwanted change
1 parent 974ae91 commit df7ca6e

File tree

1 file changed

+30
-0
lines changed
  • packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared

1 file changed

+30
-0
lines changed

packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ async def _handle_request(span, kwargs, instance):
288288
if Config.enable_trace_context_propagation:
289289
propagate_trace_context(span, kwargs)
290290

291+
# Reasoning request attributes
292+
reasoning_effort = kwargs.get("reasoning_effort")
293+
_set_span_attribute(
294+
span,
295+
SpanAttributes.LLM_REQUEST_REASONING_EFFORT,
296+
reasoning_effort or ()
297+
)
298+
291299

292300
@dont_throw
293301
def _handle_response(
@@ -319,6 +327,28 @@ def _handle_response(
319327
# span attributes
320328
_set_response_attributes(span, response_dict)
321329

330+
# Reasoning usage attributes
331+
usage = response_dict.get("usage")
332+
reasoning_tokens = None
333+
if usage:
334+
# Support both dict-style and object-style `usage`
335+
tokens_details = (
336+
usage.get("completion_tokens_details") if isinstance(usage, dict)
337+
else getattr(usage, "completion_tokens_details", None)
338+
)
339+
340+
if tokens_details:
341+
reasoning_tokens = (
342+
tokens_details.get("reasoning_tokens", None) if isinstance(tokens_details, dict)
343+
else getattr(tokens_details, "reasoning_tokens", None)
344+
)
345+
346+
_set_span_attribute(
347+
span,
348+
SpanAttributes.LLM_USAGE_REASONING_TOKENS,
349+
reasoning_tokens or 0,
350+
)
351+
322352
if should_emit_events():
323353
if response.choices is not None:
324354
for choice in response.choices:

0 commit comments

Comments
 (0)