Skip to content

Instantly share code, notes, and snippets.

@cereme
Created June 25, 2020 06:53
Show Gist options
  • Save cereme/22a2837132ce8852b191de4307da87bb to your computer and use it in GitHub Desktop.
Save cereme/22a2837132ce8852b191de4307da87bb to your computer and use it in GitHub Desktop.
Trace all events on aiohttp with TraceConfig
import aiohttp
def generate_logger(name):
async def logger(session, trace_config_ctx, params):
print(name)
return logger
trace_config = aiohttp.TraceConfig()
handlers = filter(lambda x: x.startswith("on_"), dir(trace_config))
for handler_name in handlers:
getattr(trace_config, handler_name).append(generate_logger(handler_name))
session = aiohttp.ClientSession(json_serialize=ujson.dumps, trace_configs=[trace_config])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment