question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SqlClientDiagnosticListener - change how we measure duration

See original GitHub issue

Reported via discuss

  • Currently we use Statistics.ExecutionTime in SqlClientDiagnosticListener to get the duration of the given span for a given sql call.
  • This value seems to be an aggregated value of multiple statements - I don’t fully understand how it’s aggregated yet, but as it seems it’s not a 1-1 mapping to spans we generate. Maybe this part needs to be researched and understood a little bit better.

Suggestion for the fix:

  • Let’s just rely on the internal timing of our Span type. So instead of getting the duration via the diagnostic source listener, we can just measure it as we do for spans by default.

If someone picks this up: please also try to add a test for this.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
bertvancommented, Nov 21, 2022

Ok, I reproduced locally with a query like SELECT getdate();WAITFOR DELAY '00:00:01.000'; which showed the issue nicely. I’ll setup something along those lines, with a shorter delay.

2reactions
bertvancommented, Nov 20, 2022

Hi, I’m having a look at the fix this week.

As to why it’s aggregated: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/provider-statistics-for-sql-server

Returns the cumulative amount of time (in milliseconds) that the provider has spent processing once statistics have been enabled, including the time spent waiting for replies from the server as well as the time spent executing code in the provider itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

entity framework - Logging query duration with EF Core
Ideally I want to keep a total of the duration of all queries performed through a request and have the total in milliseconds...
Read more >
Using the DiagnosticSource in .NET Core: Theory
Thus, we can now measure the execution time of all queries to the database from our application, with virtually no change to the...
Read more >
DiagnosticSource and DiagnosticListener
This walkthrough shows how to create a DiagnosticSource event and instrument code with System.Diagnostics.DiagnosticSource.
Read more >
Modern Web Development with ASP.NET Core 3 Second ...
Spend less time learning and more time coding with practical eBooks and Videos ... modularity in everything: the transparent way by which we...
Read more >
Third Party Software Disclosures
Below is a list of disclosures and disclaimers in connection with our incorporation of certain open-source licensed software into its services. Notwithstanding ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found