Skip to content

feat(genai-openai): OpenAI responses extractors#4337

Merged
xrmx merged 23 commits intoopen-telemetry:mainfrom
eternalcuriouslearner:feat/openai-response-extractors
Apr 7, 2026
Merged

feat(genai-openai): OpenAI responses extractors#4337
xrmx merged 23 commits intoopen-telemetry:mainfrom
eternalcuriouslearner:feat/openai-response-extractors

Conversation

@eternalcuriouslearner
Copy link
Copy Markdown
Contributor

@eternalcuriouslearner eternalcuriouslearner commented Mar 17, 2026

Description

This change adds strongly typed Responses API extractors for openai-v2 and reduces dependence on Any, based on feedback we received on the sync Anthropic SDK instrumentation. Pydantic models are used
here to:

  • normalize dict and object inputs
  • avoid Any
  • validate only the fields we care about
  • fail safely by logging and returning empty values instead of breaking telemetry

Dependencies required for this change:

  • pydantic >= 2, < 3

Fixes #3436 partly

Type of change

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

How Has This Been Tested?

Focused extractor tests were added/updated to cover:

  • request validation failures returning empty values and logging
  • response validation failures returning empty values and logging
  • response usage extraction from object and mapping inputs
  • capture_content=True populating output_messages
  • prevalidated response models skipping revalidation
  • Responses API status-to-finish-reason mapping behavior

Reproduce with:

python3 -m pytest --noconftest instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_response_extractors.py

Test result in local environment:

  • Focused test_response_extractors.py passes (14 tests)

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@xrmx
Copy link
Copy Markdown
Contributor

xrmx commented Mar 17, 2026

Question: isn't openai using pydantic itself and so aren't its answer expected to be of the expected shape?

@eternalcuriouslearner
Copy link
Copy Markdown
Contributor Author

Question: isn't openai using pydantic itself and so aren't its answer expected to be of the expected shape?

Howdy Riccardo, yep OpenAI uses pydantic. We’re using Pydantic here to validate and normalize the minimal request/response shapes that the instrumentation depends on. The local models let us avoid Any, handle the supported inputs through one path, and fail closed by logging and returning empty values instead of letting extraction errors break telemetry. In a nutshell I am using pydantic for following reasons:

  • normalize dict and object inputs
  • avoid Any
  • validate only the fields we care about
  • fail safely by logging and returning empty values instead of breaking telemetry

Lmk your thoughts.

CC: @xrmx @aabmass

@eternalcuriouslearner eternalcuriouslearner changed the title feat: OpenAI responses extractors feat(genai-openai): OpenAI responses extractors Mar 22, 2026
@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest Mar 23, 2026
@xrmx xrmx moved this from Reviewed PRs that need fixes to Ready for review in Python PR digest Mar 25, 2026
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks good to me. I've left a suggestion around testing but not blocking.

@xrmx xrmx enabled auto-merge (squash) April 7, 2026 13:08
@xrmx xrmx merged commit 0f92478 into open-telemetry:main Apr 7, 2026
1719 of 1721 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in Python PR digest Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Instrument OpenAI Responses API

4 participants