Skip to content

Add logfire.instrument_urllib3() integration#1744

Open
Br1an67 wants to merge 2 commits intopydantic:mainfrom
Br1an67:fix/urllib3-instrumentation
Open

Add logfire.instrument_urllib3() integration#1744
Br1an67 wants to merge 2 commits intopydantic:mainfrom
Br1an67:fix/urllib3-instrumentation

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

Add logfire.instrument_urllib3() method following the existing instrument_* pattern, wrapping the OpenTelemetry urllib3 instrumentation.

Changes

  • New integration module logfire/_internal/integrations/urllib3.py
  • instrument_urllib3() method on Logfire class with excluded_urls, request_hook, response_hook, and url_filter parameters
  • Public API export and logfire-api type stubs
  • Optional dependency: opentelemetry-instrumentation-urllib3
  • Documentation page at docs/integrations/http-clients/urllib3.md
  • mkdocs navigation and integrations index updates
  • Integration tests with mock transport

Closes #1059

devin-ai-integration[bot]

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Br1an67 Br1an67 force-pushed the fix/urllib3-instrumentation branch 2 times, most recently from 1b97bd1 to adb39a4 Compare March 1, 2026 07:38
Add urllib3 instrumentation support following the existing instrument_* pattern:
- New integration module at logfire/_internal/integrations/urllib3.py
- Method on Logfire class with excluded_urls, request_hook, response_hook, url_filter params
- Public API export and logfire-api stubs
- Optional dependency: opentelemetry-instrumentation-urllib3
- Documentation page and mkdocs navigation
- Integration tests with mock transport

Closes pydantic#1059
@Br1an67 Br1an67 force-pushed the fix/urllib3-instrumentation branch from adb39a4 to 3ff62fa Compare March 3, 2026 14:52
@Br1an67
Copy link
Author

Br1an67 commented Mar 3, 2026

Thanks for the review! I've addressed both comments:

  1. RequestInfo type: Updated request_hook parameter to use RequestInfo from opentelemetry.instrumentation.urllib3 instead of Any — in the integration module, main.py, and the type stub.
  2. VCR: Replaced monkeypatch-based HTTP mocking with @pytest.mark.vcr() using pytest-recording, with a cassette file for the test.

All tests pass locally.

@Br1an67 Br1an67 force-pushed the fix/urllib3-instrumentation branch from 3ff62fa to a44a5ed Compare March 3, 2026 15:09
…ch with VCR

- Use RequestInfo from opentelemetry.instrumentation.urllib3 for the
  request_hook parameter type instead of Any
- Replace monkeypatch-based HTTP mocking with pytest-recording (VCR)
  for more realistic test interactions
- Add VCR cassette for urllib3 instrumentation test
@Br1an67 Br1an67 force-pushed the fix/urllib3-instrumentation branch from a44a5ed to 4b30499 Compare March 3, 2026 15:55
User-Agent:
- python-urllib3/2.4.0
method: GET
uri: https://example.org:8080/foo
Copy link
Contributor

Choose a reason for hiding this comment

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

was this cassette written by AI instead of generated automatically by pytest? https://example.org:8080/foo doesn't return 200

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.

Instrumentation with urllib3

2 participants