fix: complete urllib3 instrumentation (#1059) — address review from #1744#2037
fix: complete urllib3 instrumentation (#1059) — address review from #1744#2037alloevil wants to merge 19 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds urllib3 instrumentation support to Logfire. A new 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
2 issues found across 13 files
Confidence score: 3/5
- In
logfire/_internal/integrations/urllib3.py, the broadexcept ImportError:can catch unrelated import failures, so real dependency breakages may be misclassified as “urllib3 missing” and hide a concrete runtime problem—narrow this toModuleNotFoundErrorand checkexc.namebefore merging. - The same import-handling path in
logfire/_internal/integrations/urllib3.pydrops explicit chaining, which makes stack traces harder to interpret and slows diagnosis if import failures reach users—useraise ... from errto preserve original context and de-risk support/debugging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="logfire/_internal/integrations/urllib3.py">
<violation number="1" location="logfire/_internal/integrations/urllib3.py:11">
P2: Broad `except ImportError:` masks unrelated dependency/import failures; discriminate `ModuleNotFoundError` by `exc.name` instead.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| try: | ||
| from opentelemetry.instrumentation.urllib3 import RequestInfo, URLLib3Instrumentor | ||
| except ImportError: |
There was a problem hiding this comment.
P2: Broad except ImportError: masks unrelated dependency/import failures; discriminate ModuleNotFoundError by exc.name instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At logfire/_internal/integrations/urllib3.py, line 11:
<comment>Broad `except ImportError:` masks unrelated dependency/import failures; discriminate `ModuleNotFoundError` by `exc.name` instead.</comment>
<file context>
@@ -0,0 +1,37 @@
+
+try:
+ from opentelemetry.instrumentation.urllib3 import RequestInfo, URLLib3Instrumentor
+except ImportError:
+ raise RuntimeError(
+ '`logfire.instrument_urllib3()` requires the `opentelemetry-instrumentation-urllib3` package.\n'
</file context>
Add logfire.instrument_urllib3() method following the existing instrument_* pattern, wrapping opentelemetry-instrumentation-urllib3. Fixes pydantic#1059 Closes pydantic#1744
21738c2 to
90e2f45
Compare
Add logfire.instrument_urllib3() method following the existing instrument_* pattern, wrapping opentelemetry-instrumentation-urllib3. Fixes pydantic#1059 Closes pydantic#1744
Address CodeRabbit and Cubic review feedback: - Use 'except ImportError as _err' with 'raise ... from _err' - Preserves original exception context in stack traces
Add the missing dependency to fix CI test failures.
- Fix indentation of instrument_urllib3 in logfire-api __init__.py - Import Callable from collections.abc instead of typing (UP035) - Revert accidental ruff --fix changes to .pyi files
|
Hi! I'm having trouble identifying the lint failure — the CI log just shows "Process completed with exit code 1" without details. Could you help me understand what's failing? I've fixed:
Is there a way to see the detailed pre-commit output, or is there a specific check I'm missing? |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Move urllib3 imports to correct position to match project conventions.
- Remove opentelemetry-instrumentation-urllib3 from dev dependencies (only keep it as optional extra) - Revert uv.lock to upstream (don't manually edit lockfile) - Tests will use importorskip so they gracefully skip when the package is not installed This fixes the pre-commit 'files were modified' failure caused by uv run regenerating the manually-edited uv.lock.
Restore opentelemetry-instrumentation-urllib3 in dev deps. Use upstream uv.lock (not manually edited). Add a CI step to run uv lock before pre-commit.
|
You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment |
- Keep urllib3 only as optional extra (not dev dependency) - Revert uv.lock to upstream (not manually edited) - Tests use pytest.importorskip so they skip gracefully when opentelemetry-instrumentation-urllib3 is not installed - This avoids uv.lock inconsistency that caused pre-commit failure
Remove pyproject.toml and uv.lock changes from this PR. The optional extra and dev dependency should be added by the maintainer after running `uv lock` to regenerate the lockfile. This PR now only contains: - urllib3 integration implementation - Type stubs (.pyi) updates - Test file (with importorskip) - Documentation - mkdocs.yml nav entry - logfire-api __init__ exports
Fetch files directly from upstream main via API to ensure exact byte-for-byte match. This removes all pyproject.toml and uv.lock changes from the PR. Note: Maintainer should add urllib3 optional extra + dev dep and run `uv lock` after merging the integration code.
Use upstream blob SHA directly to ensure exact match. No more manual lockfile editing.
- Add opentelemetry-instrumentation-urllib3 to optional-dependencies and dev group - Move urllib3.connectionpool/response imports to TYPE_CHECKING block in integrations/urllib3.py
| - _Web Frameworks_: FastAPI, Django, Flask, Starlette, AIOHTTP, ASGI, WSGI | ||
| - _Database Clients_: Psycopg, SQLAlchemy, Asyncpg, PyMongo, MySQL, SQLite3, Redis, BigQuery | ||
| - _HTTP Clients_: HTTPX, Requests, AIOHTTP | ||
| - _HTTP Clients_: HTTPX, Requests, urllib3, AIOHTTP |
There was a problem hiding this comment.
🚩 Integrations doc table missing urllib3 row
The bullet list at docs/integrations/index.md:35 was updated to include urllib3, but the detailed integrations table (lines 43–80) was not updated with a corresponding row for urllib3. Every other integration listed in the bullet points has a matching row in the table (e.g., Requests at line 72, HTTPX at line 59). This is a documentation completeness gap rather than a code bug.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Completes the urllib3 instrumentation integration for logfire, addressing review feedback from PR #1744.
Fixes #1059
Changes
Based on PR #1744 by @Br1an67, with the following fixes:
Realistic VCR cassette: Replaced fake
example.org:8080cassette withhttpbin.org— the previous cassette had a fake URL returning 200 OK with an empty body, which didn't represent a real HTTP interaction.Updated test assertions: Test URL, host, port, and path now match the cassette (
httpbin.org:443/getinstead ofexample.org:8080/foo).VCR instead of monkeypatching: The test uses
@pytest.mark.vcr()as requested by @alexmojaki.What's preserved from #1744
logfire/_internal/integrations/urllib3.py— core integration wrappingopentelemetry-instrumentation-urllib3logfire/_internal/main.py—instrument_urllib3method onLogfireclasslogfire/__init__.pyandlogfire-api/— exportspyproject.toml—urllib3optional dependencydocs/integrations/http-clients/urllib3.md— documentationmkdocs.yml— nav entryTesting
The test verifies that:
Closes #1059