Skip to content

Conversation

@jy-tan
Copy link
Contributor

@jy-tan jy-tan commented Jan 14, 2026

Summary

Adds instrumentation for urllib3, the low-level HTTP client library that powers requests and other HTTP libraries.

Changes

New instrumentation (drift/instrumentation/urllib3/)

  • Patches PoolManager.urlopen() and HTTPConnectionPool.urlopen() to capture HTTP requests
  • Supports both RECORD and REPLAY modes with mock response generation

Auto-initialization

  • Automatically initializes when urllib3 is imported (via _init_auto_instrumentations)

E2E test suite

  • Docker-based test infrastructure with 19 test cases covering GET, POST, PUT, PATCH, DELETE, chained requests, timeouts, retries, redirects, and more

Notable Implementation Details

  • Streaming response handling: When preload_content=False is used, response body capture is skipped to avoid consuming the stream before the application reads it. A warning is logged to inform users that replay may return an empty body for these requests. See drift/instrumentation/urllib3/notes.md for more details.
  • Double-span prevention: Checks for active spans from RequestsInstrumentation or HttpxInstrumentation to avoid creating duplicate client spans when urllib3 is called internally by those libraries.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 13 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="drift/instrumentation/urllib3/e2e-tests/src/app.py">

<violation number="1" location="drift/instrumentation/urllib3/e2e-tests/src/app.py:228">
P2: Close the HTTPSConnectionPool in a finally block so the connection is released even when the request or JSON decoding raises; otherwise failed calls leak sockets.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@jy-tan jy-tan merged commit 67157dc into main Jan 14, 2026
13 checks passed
@jy-tan jy-tan deleted the urllib3-instrumentation branch January 14, 2026 19:36
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.

3 participants