Pemantauan, Pencatatan, dan Observabilitas
Jaga kesehatan backend Supabase produksi dengan membaca catatan, melacak metrik utama, melakukan instrumentasi pada Edge Functions, dan menyiapkan peringatan sebelum masalah kecil berkembang menjadi gangguan layanan.
Pemantauan, Pencatatan, dan Observabilitas adalah pelajaran Supabase Backend as a Service gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Supabase Backend as a Service, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Supabase Backend as a Service mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
Why Observability Matters
Deploying is only half the job. Once your backend serves real traffic you need to see what it is doing. Observability is the practice of understanding system state from its outputs.
- Logs tell you what happened
- Metrics tell you how much and how fast
- Traces tell you where time was spent
The Supabase Logs Explorer
Supabase exposes logs for every service in the dashboard under Logs: API gateway, Postgres, Auth, Storage, and Edge Functions. Each is queryable with SQL-like syntax.
Filtering by status code and path quickly surfaces failing requests.
Querying Logs
The Logs Explorer accepts SQL over structured log events. Here we count API errors grouped by path over the last hour.
select path, count(*) as errors
from edge_logs
where status_code >= 500
group by path
order by errors desc;Structured Logging in Edge Functions
Inside Edge Functions, prefer structured JSON logs over plain strings. They are far easier to filter and aggregate later.
console.log(JSON.stringify({
level: 'info',
event: 'order_created',
orderId: order.id,
userId: user.id,
durationMs: Date.now() - start
}));Log Levels
Use consistent levels so you can filter noise from signal.
debugfor development detailinfofor normal eventswarnfor recoverable problemserrorfor failures needing attention
In production, avoid logging at debug to control cost and volume.
Key Database Metrics
Watch a handful of Postgres metrics closely:
- Active connections vs the pool limit
- Cache hit ratio (aim above 99%)
- Slow query count
- Disk and CPU usage
Supabase surfaces these on the Reports page.
Finding Slow Queries
Enable pg_stat_statements to see which queries consume the most total time. This is the single most useful tool for performance triage.
select query, calls, mean_exec_time, total_exec_time
from pg_stat_statements
order by total_exec_time desc
limit 10;Never Log Secrets
Logs are persisted and often shared. Never write passwords, tokens, full card numbers, or service-role keys into logs.
- Redact sensitive fields before logging
- Log identifiers, not raw payloads
- Treat log access as a security boundary
Correlating Requests
Attach a request ID to every log line in a function so you can reconstruct a single request's full journey across logs.
const requestId = crypto.randomUUID();
console.log(JSON.stringify({ requestId, event: 'start' }));
// ... work ...
console.log(JSON.stringify({ requestId, event: 'done' }));Alerting
Logs you never look at help no one. Set up alerts for the conditions that matter: error-rate spikes, connection exhaustion, disk nearing capacity.
Forward logs to an external sink (e.g. via webhooks or a log drain) when you need richer alerting than the dashboard provides.
Retention and Cost
Logs cost money and storage. Decide a retention policy deliberately.
- Keep high-value audit logs longer
- Sample or drop chatty debug logs
- Archive to cheap storage before deletion if needed for compliance
Quick Check
Test your observability knowledge.
Recap
You now have a foundation for production observability.
- Use the Logs Explorer and structured JSON logs
- Apply consistent log levels and request IDs
- Track connections, cache hit ratio, and slow queries
- Use
pg_stat_statementsfor performance triage - Never log secrets; set alerts and a retention policy
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Pemantauan, Pencatatan, dan Observabilitas” gratis?
Ya — teks lengkap “Pemantauan, Pencatatan, dan Observabilitas” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Supabase Backend as a Service, upgrade ke CoddyKit PRO. Kursus Supabase Backend as a Service mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Pemantauan, Pencatatan, dan Observabilitas”?
Jaga kesehatan backend Supabase produksi dengan membaca catatan, melacak metrik utama, melakukan instrumentasi pada Edge Functions, dan menyiapkan peringatan sebelum masalah kecil berkembang menjadi… Kamu berlatih Supabase Backend as a Service dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Supabase Backend as a Service?
Tidak diperlukan pengalaman sebelumnya. Supabase Backend as a Service di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.
Berapa lama pelajaran “Pemantauan, Pencatatan, dan Observabilitas” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Supabase Backend as a Service ini?
Ya. Setiap pelajaran Supabase Backend as a Service menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Pengelolaan Lingkungan & CI/CD
- Pencadangan, Pemulihan, dan Pemulihan Bencana
- Audit Keamanan dan Praktik Terbaik
- Pemantauan, Pencatatan, dan Observabilitas