Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/supabase-observability

@0d57af8
Run it yourself

Set up monitoring and observability for Supabase projects using Dashboard reports, CLI inspect commands, pg_stat_statements, log drains, and alerting. Use when implementing monitoring, diagnosing slow queries, forwarding logs, or configuring alerts for Supabase project health. Trigger with phrases like "supabase monitoring", "supabase metrics", "supabase observability", "supabase logs", "supabase alerts", "supabase inspect", "supabase log drain".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/supabase-observability

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescustom-metrics-and-health-checks.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Custom Metrics, Alerting, and Health Checks

Custom Metrics via Edge Functions

Collect bounded observations only from a reviewed existing table and bucket. Keep the deployed function's JWT verification enabled and restrict its invocation to approved monitoring identities; this example also verifies the request's user. It grants no monitoring entitlement by itself. Do not expose admin data or credentials. Storage listing is a root-entry sample, not a recursive object count or quota measurement.

import { createClient } from '@supabase/supabase-js';

Deno.serve(async (request) => {
  const reply = (status: number, body: object) => new Response(JSON.stringify(body), {
    status, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'private, no-store' },
  });
  try {
    const authorization = request.headers.get('authorization');
    if (!authorization?.startsWith('Bearer ')) return reply(401, { error: 'Authentication required' });
    const client = createClient(Deno.env.get('SUPABASE_URL')!, Deno.env.get('SUPABASE_PUBLISHABLE_KEY')!, {
      global: { headers: { Authorization: authorization } },
      auth: { persistSession: false, autoRefreshToken: false },
    });
    const { data: { user }, error: authError } = await client.auth.getUser();
    if (authError || !user) return reply(401, { error: 'User verification failed' });
    const table = Deno.env.get('APPROVED_METRICS_TABLE');
    const bucket = Deno.env.get('APPROVED_METRICS_BUCKET');
    if (!table || !bucket) return reply(503, { error: 'Approved probe configuration required' });
    const { count, error: queryError } = await client.from(table).select('id', { count: 'exact', head: true });
    if (queryError || typeof count !== 'number' || !Number.isSafeInteger(count) || count < 0)
      return reply(503, { error: 'Approved table query failed' });
    const { data: entries, error: storageError } = await client.storage.from(bucket).list('', { limit: 20, offset: 0 });
    if (storageError || !Array.isArray(entries) || entries.length > 20)
      return reply(503, { error: 'Storage sample failed' });
    return reply(200, { status: 'observed', visible_table_rows: count, root_entries_sampled: entries.length, sample_limit: 20 });
  } catch {
    return reply(503, { error: 'Probe failed' });
  }
});

These user-scoped observations are not total users, total stored objects, database size, plan capacity, or overall platform health. No metrics write or undefined RPC is required. Use approved Dashboard/database monitoring for separately authorized capacity measurements.

Schedule through the official Edge Function scheduling workflow:

  1. Deploy and authorize the collector, then enable the required pg_cron and pg_net extensions.
  2. Provision its project URL and appropriate invocation credential in Vault through an approved secret-management path; never commit plaintext credentials.
  3. Create a reviewed cron.schedule job that invokes net.http_post, reading connection values from Vault. Match the function's authentication mode to the documented scheduler flow rather than disabling verification to silence errors.
  4. Verify a synthetic authorized invocation and rejection of unauthorized calls. Inspect cron execution and function logs; scheduling an HTTP request alone does not prove successful metrics collection.

There is no function-level TOML schedule setting in this workflow.

Health Check Endpoint

Use the authenticated bounded collector above as a probe of those specific operations only, with the same private, no-store responses and approved monitoring access. Treat authentication, query, storage, configuration, and thrown errors as failed probes; never report success on a returned error. A successful probe does not establish global service health. Do not invent version or get_database_size RPCs: database functions must be explicitly deployed and authorized before use.

Real-time Connection Monitoring

Track active Realtime connections:

import { createClient } from '@supabase/supabase-js';

const supabase = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL!,
  process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);

// Monitor channel state changes
const channel = supabase.channel('monitoring');

channel
  .on('system', { event: '*' }, (payload) => {
    console.log(`[REALTIME] System event:`, payload);
  })
  .subscribe((status) => {
    console.log(`[REALTIME] Connection status: ${status}`);
    if (status === 'CHANNEL_ERROR') {
      console.error('[REALTIME] Connection lost — will auto-reconnect');
    }
  });

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides monitoring and observability tools for Supabase projects using the official CLI, SQL diagnostics, and log forwarding. It allows users to track database health, analyze query performance, and set up alerts. While the skill follows official practices, it handles external data such as logs and database statistics, which creates a minor surface for indirect instructions to be processed by the agent.

  • Socket2mo

    1 alert: gptAnomaly

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
What it can do
Reads files Edits files Runs commands
version
1.55.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
tags
[
  "saas",
  "supabase",
  "monitoring",
  "observability"
]
All 6 allowed tools
ReadWriteEditBash(npx supabase:*)Bash(supabase:*)Grep
Other metadata
compatibility
Designed for Claude Code

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/supabase-observability