AddHttpClientInstrumentation creates span under wrong parent when using async/await #1763
Labels
bug
Something isn't working
comp:instrumentation.http
Things related to OpenTelemetry.Instrumentation.Http
Bug Report
List of all OpenTelemetry NuGet
packages and version that you are
using (e.g.
OpenTelemetry 1.0.2
):Runtime version (e.g.
net462
,net48
,netcoreapp3.1
,net6.0
etc. You canfind this information from the
*.csproj
file):.NET Framework 4.8
Symptom
AddHttpClientInstrumentation doesn't work when multiple tasks are being executed using async. Namely, HttpClient spans are being associated to the wrong parent.
What is the expected behavior?
All HttpClient calls are attached to the correct parent scope.
What is the actual behavior?
Some HttpClient calls are attached to the wrong (random) parent scope.
Reproduce
I created a simple application that calls Postmans "Echo" API three times, each invocation with a unique query string. Before each HttpClient call, it creates a parent scope called "CallPostManEcho-XX". As such, I would expect to see this trace created
CallPostManEcho-10
-->https://postman-echo.com/get?Id=10
CallPostManEcho-20
-->https://postman-echo.com/get?Id=20
CallPostManEcho-30
-->https://postman-echo.com/get?Id=30
Instead, I see this trace. The http call generated under the CallPostManEcho-10 scope is associated to the CallPostManEcho-30
CallPostManEcho-10
-->
CallPostManEcho-20
-->https://postman-echo.com/get?Id=20
CallPostManEcho-30
-->https://postman-echo.com/get?Id=30
-->https://postman-echo.com/get?Id=10
Failing test cases are available at https://github.com/mitchabaza/OpenTelemetryBug
We will close this issue if:
projects, so don't point us to such, please.
Additional Context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: