Trace slow queries and capture SQLite errors with Sentry

Cover image for Trace slow queries and capture SQLite errors with Sentry

Today we're excited to share a new libSQL client integration for TypeScript users that allows you to trace slow queries and capture SQLite errors with Sentry.

Sentry is a powerful error tracking and performance monitoring tool that helps developers identifty, and fix issues in real-time. With Sentry, you can get a deeper view into your application's performance to quickly identify and resolve issues.

This integration is in early preview. We plan to bring this integration to other languages in the future, so be sure to let us know which ones you'd like to see next!

You likely already have a Turso database, if you don't — create one.

#Quickstart

Begin by installing the package using your preferred package manager:

npm install sentry-integration-libsql-client

Now import the Sentry package and the libsqlIntegration function from the sentry-integration-libsql-client package:

import * as Sentry from '@sentry/node';
import { createClient } from '@libsql/client';
import { libsqlIntegration } from 'sentry-integration-libsql-client';

const libsqlClient = createClient({
  url: 'libsql://...',
  authToken: '...',
});

Sentry.init({
  dsn: '...',
  integrations: [libsqlIntegration(libsqlClient, Sentry)],
});

That's it! Now if you perform a query that is invalid, missing arguments, or slow, Sentry will know about it! Let's test out the integration with an invalid SELECT query:

await libsqlClient.execute('SELECT * FRO users');

You'll see in the client that we get the following error:

LibsqlError: SQLITE_ERROR: near "FRO": syntax error

Now if you open your project in the Sentry dashboard, you'll see the error captured there:

If we perform a succesful query, we'll see the tracing results along with the type of transaction (execute, batch, insert, select, ...):

What's even more important is that you can see the individual batch statements (spans) associated with their parent span:

#Configuration

If you'd prefer not to trace, capture breadcrumbs, or capture errors, you can disable these features by passing false to any of the options in the libsqlIntegration function:

Sentry.init({
  dsn: '...',
  integrations: [
    libsqlIntegration(libsqlClient, Sentry, {
      tracing: false,
      breadcrumbs: false,
      errors: false,
    }),
  ],
});

We'll keep the documentation up to date as new features rollout — learn more.

#Feedback wanted

This integration is early days, and we'd love to hear your feedback! There's likely a lot more we can do to make this integration even more useful for multi-db schema projects.

Join us on Discord to chat more.

scarf