Edge Functions & Monitoring Supabase Databases
When cloud service providers first started popping up, many developers were “wowed” by being able to spin up and scale all kinds of infrastructure to deploy their web applications on demand. However, big-box cloud service providers are often complex to use, scaling out is expensive and default monitoring solutions are not very insightful. Besides, we are spoiled developers, and expect things to be easy.
Supabase and Sentry help simplify deployment and monitoring. Supabase makes deploying your databases and Edge Functions easy, while the new integration with Sentry makes monitoring your code locally and in the wild simple. The new Supabase and Sentry integration make monitoring the code you deploy through Supabase as straightforward as a few lines of code.. So when your new web services explode in popularity, Sentry will ensure your auth Edge Functions and DB calls are monitored, and alert you of any dumpster fires.
Instrument database integrations
Supabase provides a JavaScript client @supabase/supabase-js to set your application up to interact with a Postgres database running on their platform. With support from the Supabase team, there is now a Sentry integration that can instrument Supabase’s JavaScript SDK to start collecting traces for Performance Monitoring, breadcrumbs, and errors in Sentry.
Setup Supabase Monitoring with Sentry
You know the spiel, copy, paste and let’s go. The following snippets are all that is needed to install and initialize the Sentry SDK with Supabase client and collect all the aforementioned insights.
npm install @supabase/sentry-js-integration
import { SupabaseIntegration } from "@supabase/sentry-js-integration";
import { SupabaseClient } from "@supabase/supabase-js";
Sentry.init({
dsn: "<https://dsn@sentry.io/1337>",
integrations: [
new SupabaseIntegration(SupabaseClient, {
tracing: true,
breadcrumbs: true,
errors: true,
}),
],
});
See the @supabase/sentry-js-integration documentation and repo for more information about setting up your application to ensure your errors and traces are captured in Sentry.
The Supabase clients also allow you to build login and user management functionality, manage large files, and invoke Deno Edge Functions. Sentry can help ensure those are monitored as well, even when your code is running on the Edge . . . out there . . . somewhere.
Edge Function support
In our Launch Week November 2023, I talked about how we work to ensure we provide support to as many developers on as many platforms as possible. Of note, this includes Deno. Deno has been growing in popularity, not just amongst hipster developers, but also by growing platforms like Supabase. Supabase uses Deno as the runtime for its edge functions. Which Sentry supports through our Deno SDK.
While Deno gives you the ability to run your code on their Edge runtimes, Sentry can ensure your code is monitored and you are alerted when there are any errors or performance issues. View configuration details here.
import * as Sentry from 'https://deno.land/x/sentry/index.mjs'
// or from npm
// import * as Sentry from "npm:@sentry/deno";
Sentry.init({
dsn: 'SENTRY_DSN',
integrations: [],
debug: true,
// Performance Monitoring
tracesSampleRate: 1.0,
})
// Set region and execution_id as custom tags
Sentry.setTag('region', Deno.env.get('SB_REGION'))
Sentry.setTag('execution_id', Deno.env.get('SB_EXECUTION_ID'))
console.log("Hello from Functions!")
Deno.serve(async (req) => {
try {
const { name } = await req.json()
const data = {
message: `Hello ${name}!`,
}
return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
} catch (e) {
Sentry.captureException(e)
return new Response(JSON.stringify({ msg: 'error' }), {
status: 500,
headers: { 'Content-Type': 'application/json' },
})
}
})
Get started with Supabase monitoring today
Supabase promises to allow you to build in a weekend and scale to the world. With the Sentry integration, you can be confident in knowing when and why errors and slow DB queries happen. If you are new to Sentry you can create an account, and if there is anything else you would like to see us add to this integration or more please let us know and create a discussion in GitHub.