-
Notifications
You must be signed in to change notification settings - Fork 172
updated httpx integration, patches #1102 #1109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,10 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, Awaitable, Callable, NamedTuple | ||
|
||
import httpx | ||
from opentelemetry.trace import Span | ||
|
||
# TODO(Marcelo): When https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3098/ gets merged, | ||
# and the next version of `opentelemetry-instrumentation-httpx` is released, we can just do a reimport: | ||
# from opentelemetry.instrumentation.httpx import RequestInfo as RequestInfo | ||
# from opentelemetry.instrumentation.httpx import ResponseInfo as ResponseInfo | ||
# from opentelemetry.instrumentation.httpx import RequestHook as RequestHook | ||
# from opentelemetry.instrumentation.httpx import ResponseHook as ResponseHook | ||
|
||
|
||
class RequestInfo(NamedTuple): | ||
"""Information about an HTTP request. | ||
This is the second parameter passed to the `RequestHook` function. | ||
""" | ||
|
||
method: bytes | ||
url: httpx.URL | ||
headers: httpx.Headers | ||
stream: httpx.SyncByteStream | httpx.AsyncByteStream | None | ||
extensions: dict[str, Any] | None | ||
|
||
|
||
class ResponseInfo(NamedTuple): | ||
"""Information about an HTTP response. | ||
This is the second parameter passed to the `ResponseHook` function. | ||
""" | ||
|
||
status_code: int | ||
headers: httpx.Headers | ||
stream: httpx.SyncByteStream | httpx.AsyncByteStream | None | ||
extensions: dict[str, Any] | None | ||
|
||
|
||
RequestHook = Callable[[Span, RequestInfo], None] | ||
ResponseHook = Callable[[Span, RequestInfo, ResponseInfo], None] | ||
AsyncRequestHook = Callable[[Span, RequestInfo], Awaitable[None]] | ||
AsyncResponseHook = Callable[[Span, RequestInfo, ResponseInfo], Awaitable[None]] | ||
from opentelemetry.instrumentation.httpx import ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests break with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you just put There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood! |
||
AsyncRequestHook as AsyncRequestHook, | ||
AsyncResponseHook as AsyncResponseHook, | ||
RequestHook as RequestHook, | ||
RequestInfo as RequestInfo, | ||
ResponseHook as ResponseHook, | ||
ResponseInfo as ResponseInfo, | ||
) |
There was a problem hiding this comment.
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.