sentry-dotnet icon indicating copy to clipboard operation
sentry-dotnet copied to clipboard

My postgresql queries are not showing by default, maybe i haven't configured something?

Open phinett opened this issue 1 year ago • 2 comments

Package

Sentry

.NET Flavor

.NET

.NET Version

6.0.0

OS

macOS

SDK Version

6.0.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

Default configuration with debug and tracing enabled.

My app uses a framework called MartenDB, however this just uses npgsql under the hood.

Should sentry detect these queries by default, or do i need to do something else?

Can't find any docs / info about this.

Expected Result

queries to show

Actual Result

no querties shown

phinett avatar Jan 29 '24 12:01 phinett

Hi @phinett,

Out of the box, Sentry integrates with Microsoft.EntityFrameworkCore and System.Data.SqlClient. In both cases this is done by listening for events that get sent via System.Diagnostics.DiagnosticSource:

I'm guessing MartenDB isn't using either of those.

It looks there's an IDocumentSessionListener for diagnostics, which might be one way to instrument it. Alternatively it might be done via logging... if you're interested in maybe making a pull request?

jamescrosswell avatar Jan 29 '24 22:01 jamescrosswell

Since Npgsql has an integration with Open Telemetry this could be something we pick up through there?

bitsandfoxes avatar Feb 29 '24 12:02 bitsandfoxes

I'm also interested in this. What would be the recommended approach to getting tracing to include npgsql connections. I'm using Dapper for my ORM, so getting instrumentation configured on the npgsql level feels like the right way to go to handle multiple ORM's.

I do see that I could instrument my application with OpenTelemetry rather, and then push that to Sentry, would that be a recommended approach here, or does that come with some other disadvantages compared to using the native Sentry instrumentation?

andy-g avatar Aug 23 '24 07:08 andy-g

Marten support OpenTelemetry for spans and metrics, so that might be the easiest way to get this going. Their code samples is:

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing =>
    {
        tracing.AddSource("Marten");
    });

So the source to listen for is "Marten". A small modification to the Sentry.Samples.OpenTelemetry.Console application then, initialisation would look something like this:

SentrySdk.Init(options =>
{
    // *** All the other options here ***
    options.TracesSampleRate = 1.0;
    options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information
});

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource("Marten") // <-- Add the "Marten" telemetry source to ensure those spans get captured as traces
    .AddHttpClientInstrumentation()
    .AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry
    .Build();

jamescrosswell avatar Aug 24 '24 03:08 jamescrosswell