Skip to content

Conversation

@nagkumar91
Copy link
Contributor

Description

This PR improves test coverage for the opentelemetry-instrumentation-openai-agents-v2 package by adding 66 new unit tests.

Coverage Improvements

File Before After Change
__init__.py 82% 99% +17%
span_processor.py 77% 81% +4%
Overall 78% 83% +5%

New Test Coverage

The new tests cover previously untested code paths:

Helper Functions (__init__.py):

  • _resolve_system - System name resolution with enum matching
  • _resolve_bool - Boolean parsing from various input types
  • _resolve_content_mode - Content capture mode resolution

Utilities (span_processor.py):

  • normalize_provider - Provider name normalization
  • validate_tool_type - Tool type validation
  • normalize_output_type - Output type normalization
  • ContentCaptureMode properties (capture_in_span, capture_in_event)
  • _get_span_name for handoff/transcription/speech span types
  • _infer_output_type for function/embeddings/image/audio/json outputs
  • _sanitize_usage_payload for dict and object usage payloads
  • _normalize_messages_to_role_parts edge cases
  • _normalize_to_text_parts content normalization
  • _collect_system_instructions message collection
  • Processor configuration options (metrics disabled, custom system name)

Implementation Notes

  • Uses lazy imports within test functions to avoid module caching conflicts with existing tests
  • All 91 tests pass (25 original + 66 new)
  • No changes to existing test files or production code

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change improves tests
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • Followed the style guidelines of this project
  • Unit tests pass locally with my changes
  • Changes generate no new warnings

Add new test file with 66 additional tests covering:
- _resolve_system, _resolve_bool, _resolve_content_mode helper functions
- normalize_provider, validate_tool_type, normalize_output_type utilities
- ContentCaptureMode properties (capture_in_span, capture_in_event)
- _get_span_name for handoff/transcription/speech cases
- _infer_output_type for function/embeddings/image/audio/json outputs
- _sanitize_usage_payload for dict and object usages
- _normalize_messages_to_role_parts edge cases
- _normalize_to_text_parts content normalization
- _collect_system_instructions message collection
- Processor configuration options

Coverage improvements:
- __init__.py: 82% -> 99%
- span_processor.py: 77% -> 81%
- Overall: 78% -> 83%
@nagkumar91 nagkumar91 requested a review from a team as a code owner January 12, 2026 21:14
@nagkumar91 nagkumar91 changed the title test(openai-agents-v2): improve test coverage from 78% to 83% test(openai-agents-v2): improve test coverage Jan 12, 2026
Copy link
Contributor

@rads-1996 rads-1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants