A real-time query profiler for .NET applications using PostgreSQL. Hooks into Entity Framework Core's interceptor pipeline to capture, fingerprint, and aggregate query performance metrics.
Built as a companion tool for fga-dotnet , a Zanzibar-inspired fine-grained authorization system that works with any EF Core + PostgreSQL application.
-
Intercepts every query EF Core sends to PostgreSQL
-
Normalizes SQL into fingerprints so identical query patterns are grouped together
-
Computes p50 / p95 / p99 latency percentiles per query pattern
-
Exposes aggregated stats via a
/metrics/snapshotendpoint -
Designed as a drop-in plugin i.e one line to add to any existing app
1. Reference the project
dotnet add reference ../query-profiler/QueryProfiler.Core/QueryProfiler.Core.csproj
2. Register the services
builder.Services.AddQueryProfiler();3. Hook the interceptor into your DbContext
services.AddDbContext<YourDbContext>((sp, options) =>
{
options.UseNpgsql(connectionString);
options.AddInterceptors(sp.GetRequiredService<QueryProfilingInterceptor>());
});4. Expose the endpoint
app.MapGet("/metrics/snapshot", (IQueryMetricsStore store) =>
Results.Ok(store.GetSnapshot()));This profiler is demonstrated against fga-dotnet — a PostgreSQL-backed authorization system where permission checks run on every API call, making query performance critical.
-
Prometheus
/metricsendpoint -
Slow query EXPLAIN ANALYZE capture
-
Grafana dashboard