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

Microsoft.Data.Sqlite: Feature request: tracing, debugging #13832

Open
Tracked by #22949
ghost opened this issue Oct 15, 2017 · 18 comments
Open
Tracked by #22949

Microsoft.Data.Sqlite: Feature request: tracing, debugging #13832

ghost opened this issue Oct 15, 2017 · 18 comments
Assignees
Labels
area-adonet-sqlite customer-reported punted-for-6.0 punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@ghost
Copy link

ghost commented Oct 15, 2017

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.

@ajcvickers
Copy link
Member

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.

@bricelam
Copy link
Contributor

bricelam commented Oct 16, 2017

Workaround

You can easily leverage SQLite's native tracing (via SQLitePCL.raw):

SQLitePCL.raw.sqlite3_trace(
    connection.Handle,
    (_, statement) => Trace.WriteLine(statement, "SQLite"),
    null);

@ghost
Copy link
Author

ghost commented Oct 22, 2017

Thanks for the workaround - that'll help for now.

@ghost
Copy link
Author

ghost commented Mar 31, 2018

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.

@ajcvickers ajcvickers transferred this issue from aspnet/Microsoft.Data.Sqlite Oct 31, 2018
@ajcvickers ajcvickers added consider-for-current-release type-bug help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. area-adonet-sqlite labels Oct 31, 2018
@ajcvickers ajcvickers added this to the Backlog milestone Oct 31, 2018
@ajcvickers ajcvickers changed the title Feature request: tracing, debugging Microsoft.Data.Sqlite: Feature request: tracing, debugging Oct 31, 2018
@divega divega added good first issue This issue should be relatively straightforward to fix. help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. and removed help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. good first issue This issue should be relatively straightforward to fix. labels May 31, 2019
@bricelam bricelam added the good first issue This issue should be relatively straightforward to fix. label May 31, 2019
@ajcvickers ajcvickers removed the help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. label Aug 5, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 5.0.0 Nov 20, 2019
@ajcvickers ajcvickers added punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. and removed propose-punt labels Apr 23, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Apr 23, 2022
@bricelam
Copy link
Contributor

bricelam commented Apr 4, 2023

@roji Which of the dozen logging/telemetry/diagnostics APIs should I use for this?

@roji
Copy link
Member

roji commented Apr 4, 2023

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.

@bgrainger
Copy link
Contributor

A "specification" for using ActivitySource with ADO.NET is here: mysql-net/MySqlConnector#1036. (The net.* tags may be inapplicable for SQLite.)

@bricelam
Copy link
Contributor

I wonder what we'd need to do to get it to show up in the Visual Studio performance profiler database tool...

@roji
Copy link
Member

roji commented Apr 24, 2023

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!

@bricelam
Copy link
Contributor

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.

@roji
Copy link
Member

roji commented Apr 24, 2023

That sounds like a great feature to add to VS, especially since the OpenTelemetry tracing events are (kinda) standardized.

@bricelam
Copy link
Contributor

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 bricelam removed this from the Backlog milestone Jul 25, 2023
@bricelam bricelam added propose-punt and removed good first issue This issue should be relatively straightforward to fix. labels Jul 25, 2023
@ajcvickers ajcvickers added this to the Backlog milestone Jul 26, 2023
@bricelam bricelam removed their assignment Jul 27, 2023
@RassK
Copy link

RassK commented Nov 9, 2023

@bricelam / @roji any news on this? Looking forward to add this into OOTB features of OpenTelemetry .NET Automatic Instrumentation.
If it's going to take another year, we may consider to monkey patch it temporarily.

@bricelam
Copy link
Contributor

bricelam commented Nov 9, 2023

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 new SqliteConnection().

@RassK
Copy link

RassK commented Nov 10, 2023

@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.

@roji
Copy link
Member

roji commented Nov 10, 2023

@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).

@RassK
Copy link

RassK commented Jan 4, 2024

@bricelam @roji

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'm glad to invest some time to this issue and get it done properly for a whole OpenTelemetry Community, instead of going to monkey patching route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-adonet-sqlite customer-reported punted-for-6.0 punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

No branches or pull requests

6 participants