Add httpx to auto-instrumented libraries in configure_azure_monitor()#46284
Add httpx to auto-instrumented libraries in configure_azure_monitor()#46284benke520 wants to merge 2 commits intoAzure:mainfrom
Conversation
The OpenAI Python SDK (used by Azure AI Agent Framework / MAF) uses httpx as its HTTP client. Without httpx instrumentation, outgoing requests to Azure AI Foundry do not carry W3C traceparent headers, breaking distributed tracing between local agent code and the Foundry platform. Changes: - _constants.py: Add 'httpx' to _FULLY_SUPPORTED_INSTRUMENTED_LIBRARIES - setup.py: Add opentelemetry-instrumentation-httpx==0.61b0 dependency
There was a problem hiding this comment.
Pull request overview
This PR extends configure_azure_monitor()’s auto-instrumentation support to include httpx, enabling W3C traceparent propagation for outgoing HTTP calls made via httpx (notably used by the OpenAI Python SDK).
Changes:
- Add
httpxto the allowlist of fully supported auto-instrumented libraries. - Add
opentelemetry-instrumentation-httpx==0.61b0to the package dependencies so the instrumentor is available by default.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
sdk/monitor/azure-monitor-opentelemetry/setup.py |
Bundles the httpx OpenTelemetry instrumentation package so it can be auto-enabled. |
sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py |
Allows httpx to be discovered/enabled by the distro’s instrumentation setup. |
| "django", | ||
| "fastapi", | ||
| "flask", | ||
| "httpx", | ||
| "psycopg2", |
There was a problem hiding this comment.
httpx was added to the supported instrumentation allowlist, but there is no corresponding instrumentation smoke test (there are per-library tests under tests/instrumentation/ for django/fastapi/flask/psycopg2/requests/urllib/urllib3). Add a test_httpx.py (or equivalent) to ensure opentelemetry.instrumentation.httpx can be imported/instrumented in CI and that this new support doesn’t silently regress.
| "flask", | ||
| "httpx", | ||
| "psycopg2", |
There was a problem hiding this comment.
The README’s “Officially supported instrumentations” table currently lists the bundled/supported libraries, but it doesn’t include httpx. Since httpx is now treated as fully supported, the docs should be updated to keep the public supported-instrumentations list in sync with _FULLY_SUPPORTED_INSTRUMENTED_LIBRARIES.
| "django", | ||
| "fastapi", | ||
| "flask", | ||
| "httpx", |
There was a problem hiding this comment.
Adding httpx to _FULLY_SUPPORTED_INSTRUMENTED_LIBRARIES will change the default instrumentation_options produced by _get_configurations(). There are tests that assert an exact instrumentation_options dict (e.g., in tests/utils/test_configurations.py around test_get_configurations_env_vars_rate_limited / test_get_configurations_rate_limited_sampler_param), and they currently don’t include httpx, so this change will break the test suite unless those expected dictionaries are updated accordingly.
| "httpx", |
- Add tests/instrumentation/test_httpx.py smoke test (matches existing pattern for django/flask/requests/etc.) - Add 'httpx' to all instrumentation_options expected dicts in tests/utils/test_configurations.py (13 assertions) - Add httpx row to README 'Officially supported instrumentations' table with link definitions
Description
Fixes #46286
configure_azure_monitor()auto-instruments several HTTP client libraries (requests,urllib,urllib3) so that outgoing HTTP requests inject W3Ctraceparentheaders for distributed tracing. However, httpx is not included in the supported instrumentation list.The OpenAI Python SDK — which is the HTTP transport for Microsoft's own Azure AI Agent Framework (MAF) — uses httpx as its HTTP client, not
requests. This means:configure_azure_monitor()sets up tracing correctly for local spanstraceparentheaderstrace_idsBefore / After
Before (without httpx instrumentation)
Foundry server-side spans (
invoke_agent,chat gpt-5.4) are missing from the trace — they exist in App Insights but under separate, independenttrace_ids. The local trace shows only MAF's local spans with no visibility into what happened on the Foundry platform:After (with httpx instrumentation)
With
traceparentpropagated via httpx, the Foundry server-side spans join the same distributed trace. Each HTTP POST to Foundry now shows the server-sideinvoke_agent→chat gpt-5.4spans as children:Key differences:
POSTspans now appear under eachchatspan — these are the actual HTTP calls to Foundryinvoke_agent+chat gpt-5.4spans are children of the HTTP POST, confirmingtraceparentpropagation worksRoot Cause
In
_constants.py, the allowlist does not includehttpx:Even if a user manually installs
opentelemetry-instrumentation-httpx,_setup_instrumentations()in_configure.pyskips it because"httpx" not in _ALL_SUPPORTED_INSTRUMENTED_LIBRARIES.Changes
_constants.py: Add"httpx"to_FULLY_SUPPORTED_INSTRUMENTED_LIBRARIESsetup.py: Addopentelemetry-instrumentation-httpx==0.61b0as a dependencyCurrent Workaround
Users must manually install and instrument httpx:
Impact
This affects all Python users of:
agent-framework,agent-framework-foundryopenai>=1.0(uses httpx)