Optimize Your Prisma Queries with AppSignal and OpenTelemetry

noccor

Connor

Posted on April 25, 2023

Optimize Your Prisma Queries with AppSignal and OpenTelemetry

AppSignal integrates seamlessly with Prisma via OpenTelemetry to give you invaluable insights into how your application is performing.

In this blog post, we'll outline how you can use AppSignal to optimize your application's Prisma integration, mitigate inefficient database queries, spot anomalies, and improve your application's scalability.

Benefits of Monitoring Prisma

If your application handles multiple queries to fulfill a single request, it's important you ensure each query performs optimally (especially if your application has deeply nested object structures).

For example, imagine an authored blog post that also allows comments from other authors. This can lead to complex, inefficient, and slow database queries. As more and more people comment on a post, the query to retrieve the blog post and related objects can become unwieldy, negatively impacting your application's performance. Joins and subqueries can further exacerbate the issue and potentially retrieve redundant information.

Diagram of a blog post's nested object structure

With AppSignal's Event Timeline, you can identify poorly performing Prisma queries and remedy them before they cause bottlenecks or impact your application's availability as it scales.

Metrics That Matter with AppSignal

AppSignal provides the insights you need to help your application scale, not fail.

Find Timeline Anomalies

AppSignal's Event Timeline provides a clear overview of your application's performance on a request level. It shows what actions are executed by a request.

This example shows how our Event Timeline interprets your application's Prisma OpenTelemetry data:

Event timeline

Micro and Macro Metrics

Clicking on a Prisma event in your event log allows you to delve deeper into your database performance. You can view charts depicting your database's response time and throughput (the number of processed events) when an event occurs.

In the below graphs, multiple requests to view our blog post indicate slow database queries.

Event database performance charts

You can also see a handy list of other application actions that involve the same event. Use this list to identify where query optimization is needed, spot potential correlations between incidents, and avoid time-consuming debugging sessions.

Sending Prisma Data to AppSignal

Thanks to OpenTelemetry, it's easy to integrate AppSignal and Prisma. First, ensure your application uses Prisma 4.2 or higher and AppSignal for Node 3.0 or higher.

To automatically instrument Prisma with your AppSignal for Node.js package, enable the tracing preview feature in your Prisma schema, as shown below:

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["tracing"]
}
Enter fullscreen mode Exit fullscreen mode

Once instrumented, the Prisma integration sends AppSignal a child span for each query (including child spans for the database connection and serialization process). Each query span shows the query that was performed and how long it took to complete.

AppSignal 💚 OpenTelemetry

Due to our adoption of OpenTelemetry, AppSignal instruments 16 libraries and frameworks out-of-the-box. Get the data you need to effectively and efficiently monitor and optimize your application.

Supported Libraries and Frameworks
Express
Fastify
fs module
GraphQL (Apollo, Yoga)
HTTP/HTTPs module
Knex (Bookshelf)
Koa.js
MongoDB
Mongoose
MySQL
NestJS
Next.js
PostgreSQL
Prisma
Redis
Restify

Try AppSignal and Get Stroopwafels 🍪

We look forward to introducing you to more open source-powered features and framework support in the future!

In the meantime, if you have any questions about AppSignal, please don't hesitate to get in touch! We offer dev-to-dev support, give free accounts to open-source projects, and if you're new to AppSignal, we'll welcome you onboard with a delicious shipment of stroopwafels 🍪 😋

💖 💪 🙅 🚩
noccor
Connor

Posted on April 25, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related