Created
June 25, 2020 06:53
-
-
Save cereme/22a2837132ce8852b191de4307da87bb to your computer and use it in GitHub Desktop.
Trace all events on aiohttp with TraceConfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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