Skip to content

Supabase | Sentry for Next.js

Source URL: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/supabase

Import name: Sentry.supabaseIntegration

The supabaseIntegration adds instrumentation for the Supabase client to capture spans for both authentication and database operations.

You need to have both the Sentry SDK and the Supabase library installed. For Supabase installation instructions, refer to the Supabase JavaScript documentation.

This is the preferred method for most use cases. and follows Sentry’s standard integration pattern.

import { createClient } from "@supabase/supabase-js";
const supabaseClient = createClient(
"YOUR_SUPABASE_URL",
"YOUR_SUPABASE_KEY",
);
Sentry.init({
dsn: "YOUR_DSN",
integrations: [Sentry.supabaseIntegration({ supabaseClient })],
tracesSampleRate: 1.0,
});

The integration provides comprehensive monitoring for both authentication and database operations:

The integration automatically instruments the following auth operations:

  • signInWithPassword
  • signOut
  • signInAnonymously
  • signInWithOAuth
  • signInWithIdToken
  • signInWithOtp
  • signInWithSSO
  • signUp
  • verifyOtp
  • reauthenticate

Admin operations are also instrumented:

  • createUser
  • deleteUser
  • listUsers
  • getUserById
  • updateUserById
  • inviteUserByEmail

These spans are used to populate Sentry’s Query Insights feature, which provides performance metrics and analysis for your database operations. With Query Insights, you can identify slow queries, track query frequency, and optimize your database interactions.

  • db.table: The table being queried
  • db.schema: The database schema
  • db.url: The Supabase instance URL
  • db.sdk: Client information
  • db.system: Set to ‘postgresql’
  • db.query: The query parameters
  • db.body: The request body (for mutations)

Coming soon, the Sentry SDK will also support generating spans for interactions with Supabase queues. For more information, please follow this GitHub issue.

The integration automatically:

  • Captures errors from failed operations
  • Adds breadcrumbs for database operations
  • Includes detailed context about the operation that failed
  • @supabase/supabase-js: >=2.0.0