Skip to content

Conversation

peter-avg
Copy link

References #1102. I deleted the branch by mistake and so I am reopening the pull request.

Context

I was working on #1059 when I came across a TODO in the httpx integration (logfire/integrations/httpx.py) made by @Kludex that was waiting on this merge. The merged happened so I went ahead and made the changes.

How I tested it

I ran uv run pytest -s tests/otel-integrations/test_httpx.py and all tests passed.

Types of Changes

  • Code Improvement
  • Bug fix
  • New feature
  • Documentation

Copy link

codecov bot commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
logfire/_internal/integrations/httpx.py 55.55% 1 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

ResponseHook = Callable[[Span, RequestInfo, ResponseInfo], None]
AsyncRequestHook = Callable[[Span, RequestInfo], Awaitable[None]]
AsyncResponseHook = Callable[[Span, RequestInfo, ResponseInfo], Awaitable[None]]
from opentelemetry.instrumentation.httpx import (
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to be careful that these only get imported when type checking to not break for older versions of the instrumentation library.

Copy link
Author

Choose a reason for hiding this comment

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

tests break with if TYPE_CHECKING:.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you just put if TYPE_CHECKING: here then I expect breakage because another file imports from here. But what if you do the same for that file? Are these types used at runtime?

Copy link
Author

Choose a reason for hiding this comment

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

I believe so. From what I understand they are used at the httpx integration at runtime and they are also used when type checking in main.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, i see now. then I think this isn't actually worth it unless/until the httpx integration doesn't work with older versions of the otel library for other reasons.

Copy link
Author

Choose a reason for hiding this comment

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

Understood!


class LogfireHttpxInfoMixin:
headers: httpx.Headers
headers: httpx.Headers | None
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather make this an empty Headers object than let it be None. Definitely don't raise errors.

@alexmojaki
Copy link
Contributor

Closing since I think we can't actually make this change for a while based on discussion

@alexmojaki alexmojaki closed this Jun 5, 2025
@peter-avg peter-avg deleted the patch-1102 branch July 21, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants