Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mariojonke opened this issue Jul 29, 2022 · 3 comments · Fixed by #1246
Labels
bug Something isn't working

Comments

@mariojonke
Copy link
Contributor

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.

@mariojonke mariojonke added the bug Something isn't working label Jul 29, 2022
@mariojonke
Copy link
Contributor Author

Thinking about it some more i don't quite see the purpose of the newly added trace_configs parameter in AioHttpClientInstrumentor.instrument().
A TraceConfig is the mechanism that aiohttp provides to trace requests by registering callbacks for all kind of events (start, end, exception, ...). This is what the instrumentor already uses to create and end spans accordingly. From an OpenTelemetry point of view adding further TraceConfigs would just mean creating more spans. So imo the trace_configs parameter to externally add additional TraceConfigs doesn't make much sense.

@n0nvme
Copy link

n0nvme commented Aug 12, 2022

Same problem with 0.33b0 release

@srikanthccv
Copy link
Member

@mariojonke if the last change is not necessary feel free to send a pull request with fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants