Sentry - Error Tracking Tool
🚀 Sentry
🧠 1. Sentry আসলে কি?
Sentry হলো একটি:
✅ Error Tracking
✅ Exception Monitoring
✅ Performance Monitoring
✅ Logging + Alerting System
সহজ ভাষায়:
👉 Production এ code crash করলে developer কে instantly জানায়
Example (Real Office Scenario)
ধরো তোমার backend API:
POST /payment/send-money
Production এ user request দিলো → server crash করলো।
User দেখবে:
500 Internal Server Error
কিন্তু developer জানবে না কেন crash হলো ❌
👉 এখানে Sentry কাজ করে।
Sentry automatically collect করে:
error message
stack trace
user info
request data
environment
server info
release version
✅ Developer dashboard এ দেখে:
ZeroDivisionError
payment_service.py line 45
User ID: 8912
API: /send-money
🔥 Production debugging becomes EASY.
🏗️ 2. Modern Production Architecture (Reality)
Production system normally:
User
↓
Frontend (React / Android)
↓
API Gateway
↓
Backend (Node/Python/Go)
↓
Database
Sentry বসে:
Every Layer
✅ Frontend Error
✅ Backend Exception
✅ Background Job Failure
✅ Cron Job Error
✅ Queue Worker Crash
সব track করে।
⚡ 3. Why Companies Use Sentry
Real reasons:
✅ 1. Production Error Visibility
Log file খুলে server এ ঢুকতে হয় না।
✅ 2. Instant Alert
Slack / Email notification।
✅ 3. Debug Without Reproducing Bug
User device লাগবে না।
✅ 4. Release Monitoring
কোন deploy bug introduce করলো বুঝা যায়।
🧱 4. Core Concepts
এগুলো না বুঝলে Sentry বোঝা যাবে না।
🔹 Issue
একই error বারবার হলে → Sentry group করে।
Example:
KeyError: user_id
১০০০ বার ঘটলেও = ১টা Issue।
🔹 Event
প্রতিবার error ঘটলে → Event।
Issue
├── Event 1
├── Event 2
└── Event 3
🔹 Stack Trace
Error কোথায় ঘটেছে।
payment.py → line 34 → divide()
🔹 Breadcrumbs ⭐ (Very Powerful)
Error হওয়ার আগে কী কী ঘটেছে।
Example:
User login
Clicked pay
Selected card
API called
ERROR
🔥 Debugging gold mine।
🔹 Environment
development
staging
production
Production আলাদা track করা হয়।
🔹 Release
কোন version এ bug এসেছে।
v1.2.0 → working
v1.3.0 → broken
🧑💻 5. Professional Setup Flow
Experienced engineer যেভাবে setup করে:
Step 1 — Account & Project
👉 Sentry এ account খুলবে।
Create:
Organization
→ Project
Select platform:
Python
Node.js
React
Django
Flask
FastAPI
Express
Step 2 — SDK Install
Example (Python Backend)
pip install sentry-sdk
Step 3 — Initialize (MOST IMPORTANT)
import sentry_sdk
sentry_sdk.init(
dsn="YOUR_DSN",
traces_sample_rate=1.0,
)
👉 DSN = project connection key
✅ Done.
এখন production error auto capture হবে।
🔥 6. Automatic Error Capture
Example:
def divide(a,b):
return a/b
divide(10,0)
Result:
ZeroDivisionError
Sentry automatically receive করবে।
🧩 7. Manual Error Capture
Professional engineers manual logging করে।
Capture Exception
import sentry_sdk
try:
payment()
except Exception as e:
sentry_sdk.capture_exception(e)
Capture Custom Message
sentry_sdk.capture_message("Payment API slow")
Use Case
✅ business warning
✅ suspicious activity
✅ payment delay
👤 8. User Context (VERY IMPORTANT)
Production debugging এর secret weapon।
sentry_sdk.set_user({
"id": 101,
"email": "user@gmail.com"
})
Now error shows:
Affected User → 101
🔥 Support team happy.
🏷️ 9. Tags (Production Level Practice)
Tag দিয়ে filtering করা হয়।
sentry_sdk.set_tag("service", "payment")
sentry_sdk.set_tag("region", "bd")
Dashboard filtering:
payment errors only
🧭 10. Breadcrumb Logging
sentry_sdk.add_breadcrumb(
message="User clicked payment",
category="action",
level="info",
)
⚡ 11. Performance Monitoring
Sentry শুধু error না।
এটা track করে:
✅ slow API
✅ database latency
✅ external API delay
Enable:
sentry_sdk.init(
dsn="...",
traces_sample_rate=1.0
)
Dashboard দেখাবে:
/payment API → 4.2s ❌
🚨 12. Alerts (Production Must)
Office এ mandatory।
Configure:
Error → Slack
Critical → Email
High Rate → PagerDuty
Result:
👉 bug হলে instantly team জানবে।
13. Real Production Best Practices
Experienced engineers always:
✅ Environment Separation
dev
staging
production
Never mix.
✅ Release Tracking
Deploy করলে:
release = git commit hash
✅ Ignore Noise Errors
সব error দরকার নাই।
ignore_errors=[KeyboardInterrupt]
✅ Sensitive Data Mask
Never send:
password
token
card number
✅ Sampling
High traffic system:
traces_sample_rate=0.2
Cost save + performance.
🔥 14. Where Sentry Used in Real Company
Used in:
Banking Apps
Fintech
SaaS
E-commerce
Microservices
Mobile Apps
Example:
Your Sure Pay / bKash clone project:
Sentry track করবে:
✅ money transfer failure
✅ recharge crash
✅ DB timeout
✅ agent transaction error