10BC0 Add httpx instrumentation support by kxbnb · Pull Request #3632 · traceloop/openllmetry · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@kxbnb
Copy link
@kxbnb kxbnb commented Jan 25, 2026

Summary

  • Adds Instruments.HTTPX enum value
  • Adds init_httpx_instrumentor() function using opentelemetry-instrumentation-httpx from otel-contrib
  • Adds dependency on opentelemetry-instrumentation-httpx>=0.59b0

This lets users enable httpx tracing the same way they use requests/urllib3:

from traceloop.sdk import Traceloop
from traceloop.sdk.instruments import Instruments

Traceloop.init(instruments={Instruments.HTTPX})

Behaves like the existing REQUESTS instrumentation - uses excluded_urls to avoid tracing internal otel exporter calls.

Test plan

  • Verified enum value added in alphabetical order
  • Verified init function follows existing pattern (check package installed, import instrumentor, check not already instrumented, instrument)
  • Dependency uses same version constraint as other otel-contrib packages

Fixes #2283

🤖 Generated with Claude Code


Important

Add HTTPX instrumentation support using OpenTelemetry in the Traceloop SDK.

  • Behavior:
    • Adds Instruments.HTTPX enum value in instruments.py.
    • Adds init_httpx_instrumentor() function in tracing.py to initialize HTTPX instrumentation using opentelemetry-instrumentation-httpx.
    • Uses excluded_urls to avoid tracing internal otel exporter calls, similar to REQUESTS instrumentation.
  • Dependencies:
    • Adds opentelemetry-instrumentation-httpx>=0.59b0 to pyproject.toml dependencies.
  • Misc:
    • Verified enum value added in alphabetical order in instruments.py.
    • Verified init_httpx_instrumentor() follows existing pattern for initialization in tracing.py.

This description was created by Ellipsis for a1732f3. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features
    • Added HTTPX client instrumentation so applications using HTTPX gain automatic tracing of HTTP requests and responses for improved observability and debugging.
    • Integration initializes safely with error handling to avoid affecting application stability if instrumentation cannot be applied.

✏️ Tip: You can customize this high-level summary in your review settings.

Adds HTTPX as a supported instrument, using the existing
opentelemetry-instrumentation-httpx package from otel-contrib.

- Add HTTPX enum value to Instruments
- Add init_httpx_instrumentor() function
- Add opentelemetry-instrumentation-httpx dependency

Behaves like REQUESTS/URLLIB3 instrumentation - uses excluded_urls
to avoid tracing internal otel exporter calls.

Fixes traceloop#2283

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
coderabbitai bot commented Jan 25, 2026
📝 Walkthrough

Walkthrough

Adds HTTPX instrumentation support: dependency for OpenTelemetry HTTPX instrumentor, a new Instruments.HTTPX enum member, and initialization logic that detects HTTPX and instruments HTTPXClientInstrumentor during SDK instrumentation setup.

Changes

Cohort / File(s) Summary
Dependency Management
packages/traceloop-sdk/pyproject.toml
Added opentelemetry-instrumentation-httpx>=0.59b0 to [project.dependencies].
Instrument Enumeration
packages/traceloop-sdk/traceloop/sdk/instruments.py
Added enum member HTTPX = "httpx" to Instruments.
Instrumentation Logic
packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
Added init_httpx_instrumentor() and integrated it into init_instrumentations() to detect/install HTTPXClientInstrumentor, with error handling and instrumentation-state checks.

Sequence Diagram(s)

sequenceDiagram
    participant SDK as traceloop-sdk
    participant Init as init_instrumentations()
    participant HTTPXCheck as httpx installed?
    participant OTEL as opentelemetry.instrumentation.httpx
    participant HTTPXInstr as HTTPXClientInstrumentor

    SDK->>Init: request instrumentation for Instruments.HTTPX
    Init->>HTTPXCheck: verify httpx availability
    HTTPXCheck-->>Init: httpx present
    Init->>OTEL: import HTTPXClientInstrumentor
    OTEL-->>Init: class HTTPXClientInstrumentor
    Init->>HTTPXInstr: create instrumentor instance
    HTTPXInstr-->>Init: instance
    Init->>HTTPXInstr: instrument() (if not already instrumented)
    HTTPXInstr-->>Init: success / exception
    Init-->>SDK: return success status
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 I hopped in code, light on my feet,
Added HTTPX so async calls meet.
A client, an instrumentor, a tiny new tune—
Traces now dance under a crescent moon. ✨

🚥 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 'Add httpx instrumentation support' clearly and concisely summarizes the main change: adding httpx instrumentation to the SDK.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #2283: adds Instruments.HTTPX enum, implements init_httpx_instrumentor() following existing patterns, adds the dependency, and supports both sync/async httpx.
Out of Scope Changes check ✅ Passed All changes are in scope and directly related to issue #2283: dependency addition, enum member, and instrumentor initialization function follow the established patterns for similar instruments.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

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

Copy link
Contributor
@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to a1732f3 in 45 seconds. Click for details.
  • Reviewed 59 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/traceloop-sdk/pyproject.toml:18
  • Draft comment:
    Dependency 'opentelemetry-instrumentation-httpx>=0.59b0' is added correctly and matches the versions used for other instrumentors.
  • Reason this comment was not posted:
    7440 Confidence changes required: 0% <= threshold 50% None
2. packages/traceloop-sdk/traceloop/sdk/instruments.py:16
  • Draft comment:
    The HTTPX enum value is added in the correct alphabetical order.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py:507
  • Draft comment:
    The HTTPX branch in init_instrumentations follows the pattern used for other instrumentors.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py:741
  • Draft comment:
    The init_httpx_instrumentor function is implemented consistently with other instrumentors. Consider verifying that the multi-line EXCLUDED_URLS string is correctly handled by HTTPXClientInstrumentor.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_hNkK27eB4hVeybzc

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py`:
- Around line 741-752: The init_httpx_instrumentor function currently calls
HTTPXClientInstrumentor.instrument(excluded_urls=EXCLUDED_URLS) which will raise
a TypeError because HTTPXClientInstrumentor.instrument does not accept an
excluded_urls parameter; update the call in init_httpx_instrumentor to simply
instrumentor.instrument() and remove the excluded_urls argument (leave
EXCLUDED_URLS unused here and, if URL exclusion is required for httpx, configure
it via the OTEL_PYTHON_HTTPX_EXCLUDED_URLS or OTEL_PYTHON_EXCLUDED_URLS
environment variables).

HTTPXClientInstrumentor.instrument() doesn't accept excluded_urls
as a parameter - it reads from OTEL_PYTHON_HTTPX_EXCLUDED_URLS
environment variable instead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kxbnb
Copy link
Author
kxbnb commented Jan 26, 2026

The init_httpx_instrumentor function already handles this correctly - it calls instrumentor.instrument() without the excluded_urls parameter, with a comment directing users to the OTEL_PYTHON_HTTPX_EXCLUDED_URLS env var. No changes needed here.

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

1 participant

0