-
Notifications
You must be signed in to change notification settings - Fork 868
fix(openai): report request attributes in responses API instrumentation #3471
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
Conversation
WalkthroughIntroduced a new helper function Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Wrapper as Wrapper<br/>(sync/async)
participant Helper as prepare_kwargs_for_shared_attributes
participant SetAttrs as _set_request_attributes
participant Span
participant SharedModule as Shared Module
Caller->>Wrapper: Invoke wrapper
Wrapper->>Helper: prepare_kwargs_for_shared_attributes(kwargs)
Helper->>Helper: Clone kwargs,<br/>remap max_output_tokens→max_tokens
Helper-->>Wrapper: Return prepared kwargs
Wrapper->>SetAttrs: _set_request_attributes(span,<br/>prepared_kwargs, instance)
SetAttrs->>SharedModule: Extract model name via<br/>_extract_model_name_from_provider_format
SetAttrs->>Span: Set GEN_AI_RESPONSE_MODEL
SetAttrs->>Span: Set GEN_AI_REQUEST_* attributes<br/>(temperature, max_tokens, top_p)
Wrapper->>Wrapper: Execute OpenAI request
Wrapper->>Span: Set usage metrics<br/>(tokens, reasoning)
Wrapper-->>Caller: Return response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (2)**/cassettes/**/*.{yaml,yml,json}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.py📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧬 Code graph analysis (1)packages/opentelemetry-instrumentation-openai/tests/traces/test_responses.py (2)
🪛 Ruff (0.14.5)packages/opentelemetry-instrumentation-openai/tests/traces/test_responses.py34-34: Unused function argument: (ARG001) ⏰ 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)
🔇 Additional comments (6)
Comment |
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 c739dad in 2 minutes and 3 seconds. Click for details.
- Reviewed
261lines of code in3files - Skipped
0files when reviewing. - Skipped posting
6draft 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/opentelemetry/instrumentation/openai/v1/responses_wrappers.py:189
- Draft comment:
The new function prepare_kwargs_for_shared_attributes maps only 'max_output_tokens' to 'max_tokens'. Consider documenting or expanding this mapping if additional parameters need conversion. - Reason this comment was not posted:
Confidence changes required:50%<= threshold50%None
2. packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py:208
- Draft comment:
The explicit setting of the 'gen_ai.system' (and previously 'gen_ai.request.model') attribute in set_data_attributes has been removed. Ensure that these required attributes are now set via _set_request_attributes in the wrappers to avoid regression. - Reason this comment was not posted:
Comment looked like it was already resolved.
3. packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py:445
- Draft comment:
Multiple wrappers (responses_get_or_create, async_responses_get_or_create, cancel wrappers) call _set_request_attributes with prepare_kwargs_for_shared_attributes. This duplication is acceptable, but consider consolidating the call into a helper if additional shared logic emerges. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
4. packages/opentelemetry-instrumentation-openai/tests/traces/cassettes/test_responses/test_responses_with_request_params.yaml:1
- Draft comment:
New cassette file correctly includes a test case for capturing request parameters. Ensure that any changes in response serialization are kept in sync with expected binary responses. - Reason this comment was not posted:
Confidence changes required:50%<= threshold50%None
5. packages/opentelemetry-instrumentation-openai/tests/traces/test_responses.py:32
- Draft comment:
The test 'test_responses_with_request_params' properly verifies that parameters (temperature, max_tokens, top_p) are reported. Confirm that _set_request_attributes in the shared logic processes these keys as expected. - Reason this comment was not posted:
Confidence changes required:30%<= threshold50%None
6. packages/opentelemetry-instrumentation-openai/tests/traces/test_responses.py:465
- Draft comment:
In test_response_stream_init_with_none_tools, the final assertion allows tools to be an empty list or None. Since the comment suggests tools should default to an empty list, consider enforcing a consistent default instead of allowing None. - Reason this comment was not posted:
Confidence changes required:50%<= threshold50%None
Workflow ID: wflow_ZqsVlCWBWqPPxnkv
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Important
Enhance OpenAI API instrumentation by adding request attribute reporting and tests for capturing request parameters.
_set_request_attributestoresponses_get_or_create_wrapper,async_responses_get_or_create_wrapper, andresponses_cancel_wrapperto report request attributes.prepare_kwargs_for_shared_attributes()to mapmax_output_tokenstomax_tokens._extract_model_name_from_provider_formatand_set_request_attributestoresponses_wrappers.py.test_responses_with_request_paramsintest_responses.pyto verify capturing of request parameters liketemperature,max_tokens, andtop_p.test_responses_with_request_params.yamlcassette for VCR testing.This description was created by
for c739dad. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.