-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Microsoft.Data.Sqlite: Feature request: tracing, debugging #13832
Comments
Putting this on the backlog. This should be done using DiagnosticSource/DiagnosticListener. These are the event APIs that are now being used across all .NET. |
WorkaroundYou can easily leverage SQLite's native tracing (via SQLitePCL.raw): SQLitePCL.raw.sqlite3_trace(
connection.Handle,
(_, statement) => Trace.WriteLine(statement, "SQLite"),
null); |
Thanks for the workaround - that'll help for now. |
Commenting again after hitting another situation where this'd be useful. I can't seem to get the workaround to work in .NET Core - I suspect I'm doing something really silly because I can't get the SQLitePCL type to be found in VS2017. Edit: I was using Microsoft.Data.Sqlite 1.1.1, it worked after upgrading to some preview (!) release in the 2.1.0 series. |
@roji Which of the dozen logging/telemetry/diagnostics APIs should I use for this? |
The shiny new thing is definitely OpenTelemetry. For tracing, that means implementing these experimental specs; it's basically just start/stop activity events on command execution (for now), all pretty straightforward. The Npgsql code implementing this which you can copy is here, here are the Npgsql docs on it. For Npgsql I also did a separate Npgsql.OpenTelemetry nuget just to make the configuration slightly easier (this adds the AddNpgsql extension method over TracerProviderBuilder). I'd say that's the first/high-priority thing to do... Then there's also OpenTelemetry metrics (experimental database specs) which are like the older event counters; I haven't done this for Npgsql (which does event counters for now) - I know @bgrainger is interested in this. |
A "specification" for using ActivitySource with ADO.NET is here: mysql-net/MySqlConnector#1036. (The |
I wonder what we'd need to do to get it to show up in the Visual Studio performance profiler database tool... |
I never quite figured out how that works - there's a chance it's hard-wired to SqlClient's output diagnostics :/ Would be good to know for sure! |
I vaguely remember the creator saying that it was specific to SqlClient at the time of release, but that it would be "easy" to add other providers. We'd have to track down the current owner to figure out what's possible. Maybe they'd be interested in listening for specific OpenTelemetry events. |
That sounds like a great feature to add to VS, especially since the OpenTelemetry tracing events are (kinda) standardized. |
Looks like they currently listen for EF Core's CommandExecuting message and SqlClient's WriteCommandBefore. I'll track down the owner so we can talk to them about OpenTelemetry. |
@bricelam / @roji any news on this? Looking forward to add this into OOTB features of OpenTelemetry .NET Automatic Instrumentation. |
It's gonna be a while. I wrote a bunch of code earlier this year for this, but the way you currently configure OpenTelementry assumes there's an application service provider that you can pull the options from. This is not the case for |
@bricelam maybe it's simpler to do it in 2 parts? The main packages like SqlClient Instrumentation for OpenTelemetry and HttpClient and HttpWebRequest instrumentation for OpenTelemetry are no different. |
@bricelam when you get time to focus on this, let's chat - I can show you what I did in Npgsql. It all seems to work pretty well and isn't dependent on an application service provider (or DI). |
Happy new year! Wondering if you happened to have time to sync? This issue has raised up again in Splunk to match our OpenTelemetry offerings. |
I'd like to be able to get some debug output of what's actually being sent to the database, especially when using an ORM like Dapper. I suspect you could add some strategic Trace.Write calls before calling sqlite3.raw.
The text was updated successfully, but these errors were encountered: