Blog/devops/Monitoring: Sentry ilə xətaları real vaxtda tutmaq
devops

Monitoring: Sentry ilə xətaları real vaxtda tutmaq

B
Baku Stack AI
·7 mart 2026·5 dəq oxuma·29 baxış
devops.ascii
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ ■ ■ ■ MONITORING ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ → sentry.init({dsn}) ▓
▓ → captureException() ▓
▓ → alert → Slack #dev ▓
▓░░░░░░░░░░░░░░░░░░░░░░▓
▓ ● Errors: ▓▓▓▓▓░ 847 ▓
▓ ● Users: ▓▓▓░░░ 312 ▓
▓ ● Uptime: ▓▓▓▓▓▓ 99% ▓
▓░░░░░░░░░░░░░░░░░░░░░░▓
▓ ✓ Real-time alerts ▓
▓ ✓ Stack trace + ctx ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

Production-da baş verən bug-ları istifadəçidən əvvəl görmək istəyirsən? Sentry ilə real-time error tracking qurmağı addım-addım öyrən.

Monitoring: Sentry ilə xətaları real vaxtda tutmaq

Bir dəfə gecə saat 2-də mənə zəng gəldi. Şirkətin payment sistemi çökmüşdü, istifadəçilər ödəniş edə bilmirdi, müdiriyyət ayaqüstə idi. Ən pisi? Bug artıq 4 saat idi ki, production-da idi — heç kim xəbər tutmamışdı. Əgər o vaxt Sentry qurulmuş olsaydı, ilk xəta baş verən anda Slack-ə notification gələcəkdi və biz 4 saat yox, 4 dəqiqə ərzində problemi həll edəcəkdik.

Bu hekayə tanış gəlirsə, bu məqalə sənin üçündür.

Niyə Monitoring vacibdir?

Bakıda bir çox startupda və orta ölçülü şirkətdə belə bir vəziyyət var: developer kodu yazır, QA yoxlayır, deploy olunur və... hamı dua edir ki, hər şey düz işləsin. console.log ilə debug etmək development-də normaldır, amma production-da bu yanaşma sənin düşmənindi.

Budur real rəqəmlər:

  • Sentry-nin 2025 State of Error Monitoring hesabatına görə, orta bir web application-da hər 1000 session-a 14.7 unhandled error düşür
  • İstifadəçilərin 72%-i xəta ilə qarşılaşanda heç report etmir — sadəcə saytı tərk edir
  • Bir production bug-ın orta həll müddəti monitoring olmadan 12.4 saat, monitoring ilə isə 47 dəqiqədir

Bunu pul ilə ifadə etsək: əgər sənin e-commerce platforman gündə 5000 AZN dövriyyə edirsə, 12 saatlıq downtime sənə 2500 AZN-dən çox itki deməkdir. Sentry-nin pulsuz planı isə ayda 5000 xətaya qədər dəstəkləyir.

Sentry nədir və necə işləyir?

Sentry — open-source error tracking platformasıdır. Sadə dillə desək:

  1. Sən SDK-nı layihənə qoşursan
  2. İstifadəçi xəta ilə qarşılaşanda Sentry bunu avtomatik tutur
  3. Sənə xətanın tam konteksti ilə notification gəlir: stack trace, browser, OS, istifadəçi məlumatı
  4. Sən isə çayını içə-içə bug-ı fix edirsən

Alternativlər var — Bugsnag, Rollbar, Datadog — amma Sentry-ni tövsiyə etməyimin səbəbi:

  • Pulsuz plan kifayət qədər genişdir (5K errors/ay, 1 team member)
  • Self-hosted variantı var (öz serverində qura bilərsən)
  • Azərbaycandakı şirkətlərin çoxu — Kapital Bank-ın fintech komandası, Bravo-nun e-commerce platforması kimi layihələr bənzər tool-lardan istifadə edir
  • Documentation çox güclüdür

Praktiki quraşdırma: Node.js + Express

Gəlin real bir Express.js layihəsində Sentry-ni sıfırdan quraq.

Addım 1: Quraşdırma

bash
npm install @sentry/node @sentry/profiling-node

Addım 2: Sentry-ni initialize et

javascript
// sentry.js const Sentry = require("@sentry/node"); const { nodeProfilingIntegration } = require("@sentry/profiling-node"); Sentry.init({ dsn: "https://your-key@o123456.ingest.sentry.io/project-id", integrations: [ nodeProfilingIntegration(), ], // Production-da 20% sample rate tövsiyə olunur tracesSampleRate: 0.2, profilesSampleRate: 0.2, environment: process.env.NODE_ENV || "development", }); module.exports = Sentry;

Addım 3: Express app-ə inteqrasiya et

javascript
// app.js const express = require("express"); const Sentry = require("./sentry"); const app = express(); // Sentry request handler — ƏN ƏVVƏL qoyulmalıdır Sentry.setupExpressErrorHandler(app); // Sənin route-ların app.get("/api/users/:id", async (req, res) => { const user = await getUserById(req.params.id); if (!user) { throw new Error(`User not found: ${req.params.id}`); } res.json(user); }); // Ödəniş endpoint — real dünya nümunəsi app.post("/api/payment", async (req, res) => { try { const result = await processPayment(req.body); res.json({ success: true, transactionId: result.id }); } catch (error) { // Əlavə kontekst əlavə et Sentry.setContext("payment", { amount: req.body.amount, currency: "AZN", provider: req.body.provider, }); Sentry.setUser({ id: req.body.userId, email: req.body.email, }); Sentry.captureException(error); res.status(500).json({ error: "Payment failed" }); } }); // Custom error handler — Sentry handler-dən SONRA app.use((err, req, res, next) => { res.status(500).json({ error: "Daxili xəta baş verdi", eventId: Sentry.lastEventId(), }); }); app.listen(3000, () => { console.log("Server running on port 3000"); });

Addım 4: Slack inteqrasiyası

Sentry Dashboard-da:

  1. Settings → Integrations → Slack bölməsinə gir
  2. Workspace-ini bağla
  3. Alerts → Create Alert Rule ilə yeni qayda yarat:
    • Condition: An event is seen with level error
    • Action: Send a Slack notification to #production-alerts
    • Frequency: Every 5 minutes (spam olmasın deyə)

İndi hər dəfə production-da xəta olanda komandanın Slack kanalına belə bir mesaj düşəcək:

🔴 Error: Payment failed - Timeout from bank gateway
→ /api/payment | 23 events in last hour
→ Users affected: 12
→ First seen: 5 min ago

Frontend üçün: React nümunəsi

Əgər frontend developer-sənsə, React üçün də çox sadədir:

javascript
// index.js import * as Sentry from "@sentry/react"; Sentry.init({ dsn: "https://your-key@sentry.io/project-id", integrations: [ Sentry.browserTracingIntegration(), Sentry.replayIntegration(), ], replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0, }); // Error Boundary ilə istifadə const App = () => ( <Sentry.ErrorBoundary fallback={<p>Xəta baş verdi</p>}> <MainApp /> </Sentry.ErrorBoundary> );

Sentry.replayIntegration() xüsusən güclüdür — istifadəçinin xətadan əvvəl nə etdiyini video kimi göstərir. Debug üçün əvəzsizdir.

Best Practices: Təcrübədən gələn məsləhətlər

  • Source maps yüklə: Minified kodu debug etmək mümkün deyil. CI/CD pipeline-ına sentry-cli sourcemaps upload əlavə et
  • Release tracking qur: Hər deployment-də release parametrini ver ki, hansı deploy-dan sonra xətanın artdığını görəsən
  • Alert fatigue-dən qaç: Hər xəta üçün notification qurma. Critical və high-priority xətaları filtr et
  • PII (Personal Identifiable Information) diqqətli ol: beforeSend hook-u ilə şəxsi məlumatları təmizlə — bu KVKK/GDPR baxımından vacibdir
  • Performance monitoring-i də aktiv et: tracesSampleRate ilə yavaş endpoint-ləri tap
javascript
// PII filtrləmə nümunəsi Sentry.init({ dsn: "...", beforeSend(event) { if (event.user) { delete event.user.email; delete event.user.ip_address; } return event; }, });

Qiymətləndirmə: Nə qədər xərcləyəcəksən?

PlanQiymətXətalarKomanda
DeveloperPulsuz5K/ay1 nəfər
Team~$26/ay50K/ayLimitsiz
Business~$80/ay100K/ayLimitsiz

Əksər Bakı startupları üçün pulsuz plan kifayətdir. Şirkətin böyüdükcə Team planına keç — bu, bir developer-in bir günlük maaşından azdır, amma sənə ayda onlarla saatlıq debug vaxtı qənaət etdirəcək.

Nəticə

Monitoring luxury deyil, zərurətdir. Production-da nə baş verdiyini bilməmək — gözübağlı maşın sürmək kimidir. Sentry-ni quraşdırmaq 15 dəqiqə çəkir, amma ilk real bug-ı tutanda özünə deyəcəksən: "Bunu niyə əvvəl etmədim?"

Bu gün bir şey et: layihənin birinə Sentry əlavə et. Pulsuz plandır, risk yoxdur. Sabah production-da bir xəta baş verəndə, sən artıq hazır olacaqsan.

Növbəti məqalədə: Sentry + Grafana + Prometheus üçlüsü ilə tam monitoring stack qurmağı əhatə edəcəyik. Stay tuned.


Sualın var? GitHub-da repo-nu fork et, Sentry-ni qur və nəticəni bizimlə bölüş. Baku Stack community-si sənin arxandadır. 🚀

Teqlər

Paylaş:𝕏 Twitter✈ Telegram
Bəyəndim

Oxşar məqalələr

devops.ascii
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ ■ ■ ■ CI/CD PIPELINE ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ git push → trigger ▓
▓ ↓ ▓
▓ ● checkout ✓ ▓
▓ ● npm ci ✓ ▓
▓ ● npm test ✓ ▓
▓ ● npm build ✓ ▓
▓ ● deploy ✓ ▓
▓ ↓ ▓
▓ PROGRESS ▓▓▓▓▓▓▓▓ 100%▓
▓ → SAYT CANLIDIR! ░░░ ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

GitHub Actions ilə Avtomatik Deploy — Pulsuz Hosting, Sıfır Stress

Hər git push əmrindən sonra saytın avtomatik deploy olsun, həm də pulsuz? GitHub Actions + GitHub Pages ilə bunu 10 dəqiqəyə qurursan.

devops.ascii
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ ■ ■ ■ DEVOPS ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ $ docker build . ▓
▓ → deps ▓▓▓▓░░ 60% ▓
▓ → build ▓▓▓▓▓░ 80% ▓
▓ → runner ▓▓▓▓▓▓ ✓ ▓
▓ ● Image: 130 MB ▓
▓ ● Port: 3000 ▓
▓ ● User: nextjs ▓
▓ ──────────────────── ▓
▓ $ docker run -p 3000 ▓
▓ ✓ Ready on :3000 ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

Docker ilə Next.js App Deployment — Addım-Addım Bələdçi

Next.js layihəni Docker ilə containerləşdirib production-a çıxarmağın ən sadə və düzgün yolu — real kod nümunələri ilə.

devops.ascii
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ ■ ■ ■ DEVOPS ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ $ minikube start ▓
▓ ✓ cluster ready ▓
▓ ▓
▓ PODs: ●●●●●○○○ ▓
▓ NODES: ●●● ▓
▓ CPU: ▓▓▓▓▓░░░ 65% ▓
▓ MEM: ▓▓▓▓░░░░ 48% ▓
▓ ▓
▓ → scaling: 2 → 20 ▓
▓ → downtime: 0 sec ▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

Kubernetes başlanğıcı — nə vaxt lazım olur, nə vaxt yox?

Hər layihəyə Kubernetes lazım deyil. Gəl birlikdə baxaq: K8s nə vaxt həqiqətən işə yarayır, nə vaxt isə vaxt itkisidir.

← Bloqa qayıt