getsentry / getsentry/sentry-dotnet
`db.query.compile` is consided as query span, but shouldn't
- Dominant language
- C#
- Stars
- 770
- Forks
- 248
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 49
Description
### Package
Sentry
### .NET Flavor
.NET Core
### .NET Version
9.0.308
### OS
Linux
### OS Version
Linux x64
### Development Environment
Other
### SDK Version
6.0.0
### Self-Hosted Sentry Version
25.11.0
### Workload Versions
n/a
### UseSentry or SentrySdk.Init call
- Project uses EntityFrameworkCore 9.0.6 (from now - EF).
- Project uses MySql database, `Pomelo.EntityFramework.MySql` EF provider.
- Project uses `EntityFrameworkCore.Exceptions.MySQL.Pomelo` for EF exceptions rewrite.
- Traces are collected from EF via OpenTelemetry library (`OpenTelemetry.Instrumentation.EntityFrameworkCore` pre-release version 1.14.0-beta.2)
- Traces are fed to Sentry via `Sentry.OpenTelemetry` 6.0.0
- We do not use `Sentry.EntityFramework` package.
Following Sentry packages installed:
- Sentry 6.0.0
- Sentry.AspNetCore 6.0.0
- Sentry.Extensions.Logging 6.0.0
- Sentry.OpenTelemetry 6.0.0
- Sentry.Profiling 6.0.0 (we are trying it out)
- Sentry.Serilog 6.0.0 (project uses Serilog for logging)
```csharp
public static WebApplicationBuilder ConfigureAppSentry(this WebApplicationBuilder builder)
{
builder.WebHost.UseSentry(s =>
{
s.AdjustStandardEnvironmentNameCasing = false;
s.DisableSentryHttpMessageHandler = true;
s.UseOpenTelemetry();
s.EnableLogs = true;
s.AddProfilingIntegration();
s.SendDefaultPii = true;
// Remove nugets from in-app frames. This way nugets won't be considered "App" frames and will be considered "Library" frames.
Array.ForEach(_excludeNugetsFromSentryAppFrames, s.AddInAppExclude);
});
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddSentry());
builder.Services.AddSingleton();
return builder;
}
public static OpenTelemetryBuilder ConfigureAppOpenTelemetry(this IHostApplicationBuilder builder, string serviceName)
{
OpenTelemetryBuilder openTelemetryBuilder = builder.Services.AddOpenTelemetry()
.ConfigureResource(r =>
{
r.AddService(serviceName);
r.AddAttributes([
new KeyValuePair("environment", builder.Environment.EnvironmentName),
new KeyValuePair("instanceId", _instanceId),
]);
})
.WithLogging(_ => { },
logging =>
{
logging.IncludeScopes = true;
logging.IncludeFormattedMessage = true;
})
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation(aspnetcore => { ... });
tracing.AddHttpClientInstrumentation(httpClient => { ... });
})
.WithMetrics(meter =>
{
meter.AddAspNetCoreInstrumentation();
meter.AddHttpClientInstrumentation();
meter.AddRuntimeInstrumentation();
});
return openTelemetryBuilder;
}
public static IHostApplicationBuilder AddAppDbContext(this IHostApplicationBuilder builder)
{
string? connectionString = builder.Configuration.GetConnectionString("Db");
if (connectionString is null) throw new InvalidOperationException("Db connection string is not set.");
ServerVersion sv = ServerVersion.AutoDetect(connectionString);
builder.Services.AddHttpContextAccessor();
builder.Services.AddDbContextFactory((serviceProvider, c) =>
{
c.UseMySql(connectionString,
sv,
sqlServer =>
{
sqlServer.MigrationsAssembly("[REDACTED]");
sqlServer.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
});
if (builder.Environment.IsDevelopment())
{
c.EnableSensitiveDataLogging();
c.ConfigureWarnings(warnings => { warnings.Ignore(CoreEventId.SensitiveDataLoggingEnabledWarning); });
}
c.UseExceptionProcessor(); // from EntityFrameworkCore.Exceptions.MySQL.Pomelo
});
builder.Services.ConfigureOpenTelemetryTracerProvider(t => t.AddEntityFrameworkCoreInstrumentation());
builder.Services.AddHealthChecks().AddDbContextCheck();
return builder;
}
```
### Steps to Reproduce
1. Create some code that uses EF.
2. Go to sentry and check Insights -> Backend -> Queries page.
3. Find a query that says "%s" and inspect it further.
### Expected Result
No queries that read "%s".
### Actual Result
This "query" makes top-1.
Query "%s", I assume, comes from LINQ transpiler into SQL and has span name "db.query.compile".
This span is possibly unique to EF core (possibly Dapper or other LINQ-to-SQL libraries?)
It is later followed by actual query span:
Contributor guide
Assessment
This issue has not been assessed yet.