-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add on_response_headers_received signal to TraceConfig #12535
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added on_response_headers_received signal to TraceConfig, allowing users to trace response headers as soon as they are received from the server. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| from typing import TYPE_CHECKING, Any, Generic, Protocol, TypeVar, overload | ||
|
|
||
| from aiosignal import Signal | ||
| from multidict import CIMultiDict | ||
| from multidict import CIMultiDict, CIMultiDictProxy | ||
| from yarl import URL | ||
|
|
||
| from .client_reqrep import ClientResponse | ||
|
|
@@ -30,6 +30,7 @@ | |
| "TraceRequestChunkSentParams", | ||
| "TraceResponseChunkReceivedParams", | ||
| "TraceRequestHeadersSentParams", | ||
| "TraceResponseHeadersReceivedParams", | ||
| ) | ||
|
|
||
| _T = TypeVar("_T", covariant=True) | ||
|
|
@@ -97,6 +98,9 @@ def __init__( | |
| self._on_request_headers_sent: _TracingSignal[ | ||
| _T, TraceRequestHeadersSentParams | ||
| ] = Signal(self) | ||
| self._on_response_headers_received: _TracingSignal[ | ||
| _T, TraceResponseHeadersReceivedParams | ||
| ] = Signal(self) | ||
|
|
||
| self._trace_config_ctx_factory: _Factory[_T] = trace_config_ctx_factory | ||
|
|
||
|
|
@@ -121,6 +125,7 @@ def freeze(self) -> None: | |
| self._on_dns_cache_hit.freeze() | ||
| self._on_dns_cache_miss.freeze() | ||
| self._on_request_headers_sent.freeze() | ||
| self._on_response_headers_received.freeze() | ||
|
|
||
| @property | ||
| def on_request_start(self) -> "_TracingSignal[_T, TraceRequestStartParams]": | ||
|
|
@@ -210,6 +215,12 @@ def on_request_headers_sent( | |
| ) -> "_TracingSignal[_T, TraceRequestHeadersSentParams]": | ||
| return self._on_request_headers_sent | ||
|
|
||
| @property | ||
| def on_response_headers_received( | ||
| self, | ||
| ) -> "_TracingSignal[_T, TraceResponseHeadersReceivedParams]": | ||
| return self._on_response_headers_received | ||
|
|
||
|
|
||
| @frozen_dataclass_decorator | ||
| class TraceRequestStartParams: | ||
|
|
@@ -330,6 +341,15 @@ class TraceRequestHeadersSentParams: | |
| headers: "CIMultiDict[str]" | ||
|
|
||
|
|
||
| @frozen_dataclass_decorator | ||
| class TraceResponseHeadersReceivedParams: | ||
| """Parameters sent by the `on_response_headers_received` signal""" | ||
|
|
||
| method: str | ||
| url: URL | ||
| headers: "CIMultiDictProxy[str]" | ||
|
Member
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. It looks like our other ones currently use CIMultiDict. Considering that tracing is going to be in performance-critical paths, I think it should just use whatever the code uses. Judging by your cast(), I'd assume it's actually CIMultiDict like the others.
Member
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. Alternatively, and probably longer term, we could consider adding a MultiMapping type to multidict that would be compatible with both classes and provide immutability at the typing level. |
||
|
|
||
|
|
||
| class Trace: | ||
| """Internal dependency holder class. | ||
|
|
||
|
|
@@ -466,3 +486,12 @@ async def send_request_headers( | |
| self._trace_config_ctx, | ||
| TraceRequestHeadersSentParams(method, url, headers), | ||
| ) | ||
|
|
||
| async def send_response_headers_received( | ||
| self, method: str, url: URL, headers: "CIMultiDictProxy[str]" | ||
| ) -> None: | ||
| return await self._trace_config.on_response_headers_received.send( | ||
| self._session, | ||
| self._trace_config_ctx, | ||
| TraceResponseHeadersReceivedParams(method, url, headers), | ||
| ) | ||
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.
Why are we casting here?