Tracing Reference¶
New in version 3.0.
A reference for client tracing API.
See also
Client Tracing for tracing usage instructions.
Request life cycle¶
A request goes through the following stages and corresponding fallbacks.
Overview¶

| Name | Description |
|---|---|
| start | on_request_start |
| redirect | on_request_redirect |
| acquire_connection | Connection acquiring |
| headers_received | |
| exception | on_request_exception |
| end | on_request_end |
| headers_sent | |
| chunk_sent | on_request_chunk_sent |
| chunk_received | on_response_chunk_received |
Connection acquiring¶

| Name | Description |
|---|---|
| begin | |
| end | |
| queued_start | on_connection_queued_start |
| create_start | on_connection_create_start |
| reuseconn | on_connection_reuseconn |
| queued_end | on_connection_queued_end |
| create_end | on_connection_create_end |
| exception | Exception raised |
| resolve_dns | DNS resolving |
| sock_connect | Connection establishment |
DNS resolving¶

| Name | Description |
|---|---|
| begin | |
| end | |
| exception | Exception raised |
| resolve_end | on_dns_resolvehost_end |
| resolve_start | on_dns_resolvehost_start |
| cache_hit | on_dns_cache_hit |
| cache_miss | on_dns_cache_miss |
TraceConfig¶
-
class
aiohttp.TraceConfig(trace_config_ctx_factory=SimpleNamespace)¶ Trace config is the configuration object used to trace requests launched by a
ClientSessionobject using different events related to different parts of the request flow.Parameters: trace_config_ctx_factory – factory used to create trace contexts, default class used types.SimpleNamespace-
trace_config_ctx(trace_request_ctx=None)¶ Parameters: trace_request_ctx – Will be used to pass as a kw for the trace_config_ctx_factory.Build a new trace context from the config.
Every signal handler should have the following signature:
async def on_signal(session, context, params): ...
where
sessionisClientSessioninstance,contextis an object returned bytrace_config_ctx()call andparamsis a data class with signal parameters. The type ofparamsdepends on subscribed signal and described below.-
on_request_start¶ Property that gives access to the signals that will be executed when a request starts.
paramsisaiohttp.TraceRequestStartParamsinstance.
-
on_request_chunk_sent¶ Property that gives access to the signals that will be executed when a chunk of request body is sent.
paramsisaiohttp.TraceRequestChunkSentParamsinstance.New in version 3.1.
-
on_response_chunk_received¶ Property that gives access to the signals that will be executed when a chunk of response body is received.
paramsisaiohttp.TraceResponseChunkReceivedParamsinstance.New in version 3.1.
-
on_request_redirect¶ Property that gives access to the signals that will be executed when a redirect happens during a request flow.
paramsisaiohttp.TraceRequestRedirectParamsinstance.
-
on_request_end¶ Property that gives access to the signals that will be executed when a request ends.
paramsisaiohttp.TraceRequestEndParamsinstance.
-
on_request_exception¶ Property that gives access to the signals that will be executed when a request finishes with an exception.
paramsisaiohttp.TraceRequestExceptionParamsinstance.
-
on_connection_queued_start¶ Property that gives access to the signals that will be executed when a request has been queued waiting for an available connection.
paramsisaiohttp.TraceConnectionQueuedStartParamsinstance.
-
on_connection_queued_end¶ Property that gives access to the signals that will be executed when a request that was queued already has an available connection.
paramsisaiohttp.TraceConnectionQueuedEndParamsinstance.
-
on_connection_create_start¶ Property that gives access to the signals that will be executed when a request creates a new connection.
paramsisaiohttp.TraceConnectionCreateStartParamsinstance.
-
on_connection_create_end¶ Property that gives access to the signals that will be executed when a request that created a new connection finishes its creation.
paramsisaiohttp.TraceConnectionCreateEndParamsinstance.
-
on_connection_reuseconn¶ Property that gives access to the signals that will be executed when a request reuses a connection.
paramsisaiohttp.TraceConnectionReuseconnParamsinstance.
-
on_dns_resolvehost_start¶ Property that gives access to the signals that will be executed when a request starts to resolve the domain related with the request.
paramsisaiohttp.TraceDnsResolveHostStartParamsinstance.
-
on_dns_resolvehost_end¶ Property that gives access to the signals that will be executed when a request finishes to resolve the domain related with the request.
paramsisaiohttp.TraceDnsResolveHostEndParamsinstance.
-
on_dns_cache_hit¶ Property that gives access to the signals that will be executed when a request was able to use a cached DNS resolution for the domain related with the request.
paramsisaiohttp.TraceDnsCacheHitParamsinstance.
-
on_dns_cache_miss¶ Property that gives access to the signals that will be executed when a request was not able to use a cached DNS resolution for the domain related with the request.
paramsisaiohttp.TraceDnsCacheMissParamsinstance.
-
TraceRequestStartParams¶
-
class
aiohttp.TraceRequestStartParams¶ See
TraceConfig.on_request_startfor details.-
method¶ Method that will be used to make the request.
-
url¶ URL that will be used for the request.
-
headers¶ Headers that will be used for the request, can be mutated.
-
TraceRequestChunkSentParams¶
-
class
aiohttp.TraceRequestChunkSentParams¶ New in version 3.1.
See
TraceConfig.on_request_chunk_sentfor details.-
chunk¶ Bytes of chunk sent
-
TraceResponseChunkSentParams¶
-
class
aiohttp.TraceResponseChunkSentParams¶ New in version 3.1.
See
TraceConfig.on_response_chunk_receivedfor details.-
chunk¶ Bytes of chunk received
-
TraceRequestEndParams¶
-
class
aiohttp.TraceRequestEndParams¶ See
TraceConfig.on_request_endfor details.-
method¶ Method used to make the request.
-
url¶ URL used for the request.
-
headers¶ Headers used for the request.
-
response¶ Response
ClientResponse.
-
TraceRequestExceptionParams¶
TraceRequestRedirectParams¶
-
class
aiohttp.TraceRequestRedirectParams¶ See
TraceConfig.on_request_redirectfor details.-
method¶ Method used to get this redirect request.
-
url¶ URL used for this redirect request.
-
headers¶ Headers used for this redirect.
-
response¶ Response
ClientResponsegot from the redirect.
-
TraceConnectionQueuedStartParams¶
-
class
aiohttp.TraceConnectionQueuedStartParams¶ See
TraceConfig.on_connection_queued_startfor details.There are no attributes right now.
TraceConnectionQueuedEndParams¶
-
class
aiohttp.TraceConnectionQueuedEndParams¶ See
TraceConfig.on_connection_queued_endfor details.There are no attributes right now.
TraceConnectionCreateStartParams¶
-
class
aiohttp.TraceConnectionCreateStartParams¶ See
TraceConfig.on_connection_create_startfor details.There are no attributes right now.
TraceConnectionCreateEndParams¶
-
class
aiohttp.TraceConnectionCreateEndParams¶ See
TraceConfig.on_connection_create_endfor details.There are no attributes right now.
TraceConnectionReuseconnParams¶
-
class
aiohttp.TraceConnectionReuseconnParams¶ See
TraceConfig.on_connection_reuseconnfor details.There are no attributes right now.
TraceDnsResolveHostStartParams¶
-
class
aiohttp.TraceDnsResolveHostStartParams¶ See
TraceConfig.on_dns_resolvehost_startfor details.-
Host¶ Host that will be resolved.
-
TraceDnsResolveHostEndParams¶
-
class
aiohttp.TraceDnsResolveHostEndParams¶ See
TraceConfig.on_dns_resolvehost_endfor details.-
Host¶ Host that has been resolved.
-
TraceDnsCacheHitParams¶
-
class
aiohttp.TraceDnsCacheHitParams¶ See
TraceConfig.on_dns_cache_hitfor details.-
Host¶ Host found in the cache.
-
TraceDnsCacheMissParams¶
-
class
aiohttp.TraceDnsCacheMissParams¶ See
TraceConfig.on_dns_cache_missfor details.-
Host¶ Host didn’t find the cache.
-