Skip to content

feat(sdk): add httpx instrumentation support#4070

Open
Jwrede wants to merge 1 commit intotraceloop:mainfrom
Jwrede:feat/httpx-instrumentation
Open

feat(sdk): add httpx instrumentation support#4070
Jwrede wants to merge 1 commit intotraceloop:mainfrom
Jwrede:feat/httpx-instrumentation

Conversation

@Jwrede
Copy link
Copy Markdown

@Jwrede Jwrede commented May 2, 2026

Summary

Closes #2283

Adds httpx instrumentation to the traceloop SDK, allowing automatic tracing of outbound HTTP calls made via httpx. This mirrors the existing requests and urllib3 instrumentation already supported by the SDK.

Changes

  • Added HTTPX = "httpx" enum value to Instruments
  • Added init_httpx_instrumentor() function using HTTPXClientInstrumentor with excluded_urls filtering (same as requests/urllib3)
  • Added the elif dispatch branch in the instrumentor initialization loop
  • Added opentelemetry-instrumentation-httpx>=0.59b0 dependency to pyproject.toml

Test plan

  • Verified Python syntax parses correctly
  • CI passes with new dependency
  • Manual verification: import traceloop SDK with httpx installed, confirm HTTPXClientInstrumentor activates

Summary by CodeRabbit

  • New Features
    • Added support for instrumenting the HTTPX HTTP client library, enabling automatic tracing of HTTPX requests within the SDK.

Register opentelemetry-instrumentation-httpx in the traceloop SDK so
that outbound HTTP calls made via httpx are automatically traced,
matching existing requests/urllib3 instrumentation.

Signed-off-by: Jonathan Wrede <wrede.jonathan00@gmail.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 2, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ea35c43-f951-487f-8208-a4efcd6d1c75

📥 Commits

Reviewing files that changed from the base of the PR and between abbcc11 and 1907e37.

📒 Files selected for processing (3)
  • packages/traceloop-sdk/pyproject.toml
  • packages/traceloop-sdk/traceloop/sdk/instruments.py
  • packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py

📝 Walkthrough

Walkthrough

Added HTTPX instrumentation support to the Traceloop SDK by introducing a new HTTPX enum member, adding the opentelemetry-instrumentation-httpx dependency, and implementing an init_httpx_instrumentor() function that conditionally initializes the HTTPXClientInstrumentor with excluded URL filtering.

Changes

HTTPX Instrumentation Support

Layer / File(s) Summary
Enum Definition
packages/traceloop-sdk/traceloop/sdk/instruments.py
Added HTTPX = "httpx" enum member to Instruments for identifying HTTPX as a supported instrumentation target.
Dependency Declaration
packages/traceloop-sdk/pyproject.toml
Added opentelemetry-instrumentation-httpx>=0.59b0 to project dependencies alongside other OpenTelemetry instrumentation packages.
Initialization Logic
packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
Implemented init_httpx_instrumentor() function that detects HTTPX availability, instantiates HTTPXClientInstrumentor, configures it with EXCLUDED_URLS, and handles errors gracefully. Wired into init_instrumentations() method to handle Instruments.HTTPX selection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop, skip, and bound through async land,
HTTPX now in paw, so grand!
No more just requests and urllib's way,
This rabbit traces async all day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(sdk): add httpx instrumentation support' accurately and concisely summarizes the main change of adding HTTPX support to the SDK's instrumentation.
Linked Issues check ✅ Passed The pull request fully implements the requirements from #2283: adding HTTPX to Instruments enum, creating init_httpx_instrumentor() with excluded_urls support, and adding the required dependency.
Out of Scope Changes check ✅ Passed All changes in the pull request are directly scoped to implementing HTTPX instrumentation support as specified in #2283; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

🚀 Feature: Add instruments support for httpx

2 participants