Skip to content

instrumentation-aiohttp-client: Number of created spans per request increases by 1 with every new request #1207

@mariojonke

Description

@mariojonke

Latest release 0.32b0 introduced a bug where an additional span is created every time a new aiohttp ClientSession is created. This leads to 1 span per request when the first session is created, 2 spans when the second session gets created, ... and so on.

When AioHttpClientInstrumentor.instrument() the instrumentor intercepts the ClientSession.__init__ call and injects a TraceConfig instance into the parameters that are passed to the ClientSession. With the latest release an additional parameter trace_configs was added to the AioHttpClientInstrumentor.instrument() method.
The problem is that the trace_configs argument is now injected into every newly created ClientSession but it is also shared between all ClientSessions.
Every time a new ClientSession is created the instrumented __init__ call now adds one additional trace_config to the shared trace_configs argument (associated code can be found here). Since one trace_config defines the hooks to create and end one span, every added trace_config will produce an additional span per request.

Steps to reproduce
Instrument the aiohttp-client with AioHttpClientInstrumentor.instrument(). Create at least two ClientSessions and make one HTTP request to some arbitrary URL. The produced spans increase with every new ClientSession that is created.

Describe exactly how to reproduce the error. Include a code sample if applicable.

What is the expected behavior?
One span per HTTP request independent of the number of ClientSessions that are created.

What is the actual behavior?
Number of created spans increase with each newly created ClientSession.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions