Find slow database queries with Query Insights

By admin

September 28,
DATE

2023

There’s only so much you can control when it comes to your app’s performance. But you control what is arguably most important – the code. Sentry Performance gets you the code-level insights you need to resolve performance bottlenecks.


Query Insights
PERSON

is the

first
ORDINAL

of many new performance-centered workflows we plan to roll out over

the coming months
DATE

to help you understand where time is being spent in your application, how it’s hurting your user’s experience, and give you the context you need to fix the right performance issue – not all long-running queries are bad, just the ones associated with heaps of support tickets. Join the GitHub Discussion – we’re posting regular updates on what we’re building and are always looking for feedback.

Find (and fix) that slow query quickly

Users logging in, searching, signing up, filtering, sorting, and even sending a notification – any time a record is updated, added, or deleted in some form or fashion your users are hitting one of your many databases. Your users can’t tell/don’t know/don’t care that searching for “beige fall hoodies” is actually really hard – not because beige anything is questionable, but because you have to somehow have the guardrails in place to automatically craft the perfect query that returns results as fast as possible. As we all know… slow is the new down… err latency is the new outage. You get the picture.

Say you do work for an online retailer, as a backend developer, you’re probably tasked with making sure product search is fast. While poor performance could be due to a caching issue, overloaded servers,

API
ORG

errors, or more – which shamelessly, some which

Sentry
ORG

can help you with too, but for the purpose of this post and to give you an idea on how to use

Query Insights
ORG

, let’s chalk it up to terrible SQL.

To see if a database query is behind the performance issue, click on the Queries from the left navigation menu under

Performance
WORK_OF_ART

. Here you can see if and when there’s been a recent change in frequency and average duration across all database queries. The data we serve in

Query Insights
ORG

is metrics-based – meaning it’s based on

100%
PERCENT

of the events you send to

Sentry
ORG

, not just sample events. This gives you a more complete, accurate, and actionable data set to work off of so you can figure out exactly when a performance regression happened.

As expected, you see a database query that could be related to the search experience taking longer than it should. When you select the query in question, you’ll land on the Query Summary tab where you can see the exact query with syntax highlighting. But is this the query influencing the

API
ORG

endpoint related to search? The graphs and tables below have the answer.

Impacted API endpoints

Just like on the

Queries
ORG

tab, you’ll see duration and throughput summary graphs showing when the query’s performance started to degrade. The table below contains a list of

API
ORG

endpoints in which the query was run. Bingo – the query you selected is impacting the

API
ORG

endpoint related to the search experience. In this case, it’s pulling user reviews to display alongside the products.