-
Notifications
You must be signed in to change notification settings - Fork 762
fix(openai_agents):Added the attributes to the duration histogram #3150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes update the OpenLLMetry instrumentation to add two new span attributes— Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Agent
participant Instrumentation
User->>Agent: Initiate agent run
Agent->>Instrumentation: Run wrapper (_wrap_agent_run/_wrap_agent_run_streamed)
Instrumentation->>Instrumentation: Extract model name
Instrumentation->>Instrumentation: Add LLM_SYSTEM and LLM_RESPONSE_MODEL to span attributes
Instrumentation->>Agent: Execute agent logic
Agent-->>Instrumentation: Return results
Instrumentation->>Instrumentation: Record duration metric with attributes
Instrumentation-->>User: Return agent results
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to fd72cc6 in 48 seconds. Click for details.
- Reviewed
37
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
2
draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/__init__.py:194
- Draft comment:
Added duration histogram attributes for streamed runs. Verify that get_model_name(agent) always returns a valid string (avoid returning null) and consider caching its result for consistency. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
2. packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/__init__.py:285
- Draft comment:
New attributes added to duration histogram in _wrap_agent_run. For readability, consider storing the elapsed time in a variable (like done in the streamed version) and ensure consistent attribute usage. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
Workflow ID: wflow_upiXfdtmlYZz2Ccd
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/__init__.py (1)
189-198
: Guard against non-string orNone
model names & compute once
Callingget_model_name(agent)
can returnNone
(or a non-str
value), which invalidates OTLP attributes and may drop the data point. Compute it once, coerce to a string (or fall back to a sentinel), then reuse:- duration_histogram.record( - duration, - attributes={ - "gen_ai.agent.name": agent_name, - SpanAttributes.LLM_SYSTEM: "openai", - SpanAttributes.LLM_RESPONSE_MODEL: get_model_name(agent), - }, - ) + model_name = get_model_name(agent) + if not isinstance(model_name, str): + model_name = "unknown_model" + duration_histogram.record( + duration, + attributes={ + "gen_ai.agent.name": agent_name, + SpanAttributes.LLM_SYSTEM: "openai", + SpanAttributes.LLM_RESPONSE_MODEL: model_name, + }, + )
- Ensures a single lookup of
get_model_name(agent)
- Falls back to
"unknown_model"
if the result isNone
or not astr
- Satisfies OTLP’s requirement that attribute values be primitive types
🧹 Nitpick comments (2)
packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/__init__.py (1)
286-293
: Apply the samemodel_name
safeguard in the non-streaming pathMirror the
None
-handling and single-lookup pattern here to keep metric attributes consistent.README.md (1)
152-153
: Maintain alphabetical order in the Frameworks listThe list has been alphabetical; inserting “OpenAI Agents” in its sorted position (after LangGraph, before LiteLLM) keeps the section tidy.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
README.md
(1 hunks)packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/__init__.py
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/__init__.py (1)
packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/__init__.py (1)
SpanAttributes
(36-229)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Test Packages (3.10)
- GitHub Check: Test Packages (3.9)
- GitHub Check: Test Packages (3.12)
- GitHub Check: Test Packages (3.11)
- GitHub Check: Build Packages (3.11)
- GitHub Check: Lint
@@ -192,6 +192,8 @@ async def _wrap_agent_run_streamed( | |||
duration, | |||
attributes={ | |||
"gen_ai.agent.name": agent_name, | |||
SpanAttributes.LLM_SYSTEM: "openai", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adharshctr shouldn't this be the vendor (which may not always be OpenAI)?
feat(instrumentation): ...
orfix(instrumentation): ...
.Important
Added attributes to duration histogram in OpenAI Agents instrumentation and updated README to include OpenAI Agents as a supported framework.
gen_ai.agent.name
,SpanAttributes.LLM_SYSTEM
, andSpanAttributes.LLM_RESPONSE_MODEL
toduration_histogram.record()
in_wrap_agent_run_streamed()
and_wrap_agent_run()
.README.md
to include OpenAI Agents as a supported framework.This description was created by
for fd72cc6. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
Documentation
New Features