Open virtes opened 1 year ago
Moving to the contrib repo as EF instrumentation is hosted there?
@virtes Do you have more idea on the underlying issue and possible fixes? There isn't a marked owner for EF instrumentation, so if you/others can help investigate and provide fix, that'd be super helpful!
@cijothomas I'm not sure, that the problem is caused by EF instrumentation.
As I understood, the underlying problem is that EntityFrameworkDiagnosticListener and SqlClientDiagnosticListener are called in parallel so stopping the SqlClient activity doesnt reflect actual current activity in EF listener and this causes the EF instrumentation to use obsolete activity. It turns out that the child SqlClient span is used here, but the EF activity is expected here, so the activity doesnt stop and could not be exported
If I misunderstood anything, please correct me
I will take a look at this one! cc @cijothomas
I've just experienced this issue. Any progress been made?
My package versions are:
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="[1.7.0, 2.0.0)" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="[1.7.0, 2.0.0)" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="[1.7.0, 2.0.0)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="[1.7.0, 2.0.0)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.9" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="[1.7.0, 2.0.0)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.6.0-beta.3" />
I did a little investigation. Problem is here: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/2ca95ada73d6e3332bd4f48303b087ec438324f9/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs#L269
Better say problem is sequence of events.
Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted
happens before than Microsoft.Data.SqlClient.WriteCommandAfter
Because of that SQLClient span is still active and because of the condition I mentioned above we are skipping to stop EF activity on Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted
event and that event of course never repeat again.
How EF span is not closed cannot be reported but yes it is still parent of SQL span.
Do we have any practice how to solve such problems? Problem here can be wrong order of events from sources. We have two different libraries so we cannot say who fire event in good moment. It also can be wrong order of processing on OTEL side, which I think is less likely.
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 can find this information from the*.csproj
file):Symptom
Using
AddSqlClientInstrumentation
andAddEntityFrameworkCoreInstrumentation
at the same time leads to miss parent span.What is the expected behavior?
Exports two spans:
What is the actual behavior?
Output from console exporter - I have only SQL Client span, which has ParentSpanId of EF Core span.
We can see both expected spans using Enrich methods (pay attention to
Id
andParentSpanId
), so I guess that both spans are exist and looks like the first one just doesnt stop:Reproduce
Additional Context