Description
Now tracing signal signatures look like
async def on_request_start(session, trace_config_ctx, method, host, port, headers): ...
async def on_send_connection_queued_start(session, trace_config_ctx): ...
The problem is the approach is has no space for future extensions.
Most likely we will want to add a connection info to on_send_connection_queued_start but it is impossible to do without breaking all existing signal handlers: sending additional connection parameter cannot be accepted.
Sure, we can enforce users to write handlers with mandatory *args and **kwargs like
async def on_send_connection_queued_start(session, trace_config_ctx, *args, **kwargs): ...
but I expect that users will constantly forgot these extra arguments.
As a solution we can change signal signature for all signals to async def on_sig(session, ctx, data): ... where ctx is trace_config_ctx and data is a structure with all signal parameters: url, host, port, headers, connection etc.
It allows to add new param to data in backward compatible manner.
Next question is the data type.
I see several options:
- Plain dict with keys like
hostandconnection. It works but looks too old fashion, everybody prefer attributes to string keys. - SimpleNamespace.
data.urllooks better thandata['url'] - Custom data classes. Honestly it is even better than
SimpleNamespaceat least from documentation perspective: we will need to document every used data structure explicitly. - attrs classes. The library brings extra dependency (I don't care, aiohttp has several deps already) but provides neat helpers. Using data classes from Python 3.7 is even better but we should support Python 3.5/3.6 for long time.
Trace class already has explicit methods for sending every signal, constructing a data class on call is easy and straightforward.
@pfreixes and others, what do you think about?