Skip to content

Fix server.address extraction for openai 3.x (httpx2) - #4954

Open
ari-abb wants to merge 4 commits into
open-telemetry:mainfrom
ari-abb:fix/openai-v2-server-address
Open

Fix server.address extraction for openai 3.x (httpx2)#4954
ari-abb wants to merge 4 commits into
open-telemetry:mainfrom
ari-abb:fix/openai-v2-server-address

Conversation

@ari-abb

@ari-abb ari-abb commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #4953

Description

get_server_address_and_port decided how to read base_url with
isinstance(base_url, httpx.URL). openai 3.x builds on httpx2, so client._client.base_url is an
httpx2.URL: neither that branch nor the str branch matches, the function returns (None, None), and
server.address and server.port are silently dropped from every span.

This reads the URL structurally instead, which covers httpx.URL, httpx2.URL, any other URL-like
object and plain strings, so extraction no longer depends on which HTTP client the SDK uses internally.

Removing the isinstance check also removes the only use of the httpx import, which matters
separately: this package declares no dependency on httpx, and openai 3.x depends on httpx2
instead, so on a clean install of openai==3.0.0 plus this package httpx can be absent entirely and
the module-scope from httpx import URL made the package unimportable rather than merely degraded.

This looks like a spot missed by the recent httpx2 migration (#4730, #4948) rather than a separate
problem.

Behaviour is preserved on every path that works today:

base_url before after
httpx.URL .host / .port unchanged
plain string urlparse unchanged
explicit :443 port omitted unchanged
missing or falsy (None, None) unchanged
httpx2.URL (None, None) .host / .port
other URL-like (None, None) .host / .port

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

New tests/test_server_address.py covering httpx.URL, httpx2.URL, a plain string, an explicit
:443 (asserting the port is still omitted), a missing base_url, and that the package imports with
httpx uninstalled. The last one is skipped on openai 2.x, which depends on httpx itself, so the
situation cannot arise there.

Verified in two environments:

  • the pinned test environment (openai==2.26.0, httpx==0.27.2): full package suite 193 passed, 28
    skipped
    , no change in behaviour;
  • openai==3.0.0 with httpx genuinely absent: the package imports and the new tests pass. Reverting
    the fix in that environment makes the test module fail at import with
    ModuleNotFoundError: No module named 'httpx', which is the regression this guards.

Worth noting: tests/requirements.latest.txt pins openai==2.26.0, so nothing in CI currently
exercises openai 3.x. Happy to add httpx2 there, or to bump the pin in a separate PR, if you would
like the new cases to run in CI rather than skip.

Does This PR Require a Core Repo Change?

  • Yes.
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Changelog fragment added (.changelog/4954.fixed)
  • Documentation has been updated (not applicable: no user-facing behaviour or API change)

get_server_address_and_port checked isinstance(base_url, httpx.URL), but
openai 3.x builds on httpx2, so base_url is an httpx2.URL. Neither that branch
nor the str branch matched, the function returned (None, None), and
server.address and server.port were dropped from every span with no warning.

Reading the URL structurally with getattr covers httpx.URL, httpx2.URL, any
other URL-like object and plain strings, so the extraction no longer depends on
which HTTP client the SDK uses internally. Existing behaviour is preserved on
every path that worked before, including omitting the default 443 port.

Removing the isinstance check also removes the only use of the httpx import.
That matters on its own: this package declares no dependency on httpx while
openai 3.x depends on httpx2, so on a clean install httpx can be absent and the
module-scope import made the package unimportable rather than merely degraded.

Tests cover httpx.URL, httpx2.URL, a plain string, an explicit :443 (asserting
the port is still omitted), a missing base_url, and that the package imports
with httpx uninstalled.
@ari-abb
ari-abb requested a review from a team as a code owner August 12, 2026 23:54
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 12, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@github-actions github-actions Bot added the gen-ai Related to generative AI label Aug 12, 2026
@aabmass

aabmass commented Aug 13, 2026

Copy link
Copy Markdown
Member

Hi @ari-abb can thanks for the PR, but development on this has moved to https://github.com/open-telemetry/opentelemetry-python-genai (see #4924). The version in this repo will be deleted from this repo once we make a final release with the deprecation notice.

I'm happy to transfer the issue over if you can reopen the PR?

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-08-21 18:24 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Top-level threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Hi @ari-abb — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.

  • Replying is enough to hand it off — answer, explain why no change is needed, or ask a follow-up. The dashboard routes it onward once nothing on the list is waiting on you.
  • To hand it back for any other reason, including the dashboard getting this wrong, comment /dashboard route:reviewers.

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

Labels

gen-ai Related to generative AI

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

openai 3.x: server.address / server.port are never recorded (isinstance check misses httpx2.URL)

3 participants