What Sentry Does
- Error Tracking: Capture and group unhandled exceptions with full stack traces
- Performance Monitoring: Trace transactions across services with latency breakdowns
- Session Replay: Replay user sessions to see exactly what happened before an error
- Release Tracking: Track error rates per release, detect regressions automatically
- Source Maps: Unminify JavaScript errors with automatic source map processing
- Alerts: Configurable alert rules for error spikes, new issues, and performance degradation
- Issue Assignment: Auto-assign issues to code owners based on stack trace
- Integrations: GitHub, GitLab, Jira, Slack, PagerDuty, and 50+ integrations
- Breadcrumbs: Automatic event trail leading up to each error (clicks, API calls, console logs)
SDK Examples
JavaScript/Node.js
const Sentry = require("@sentry/node");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
Sentry.init({
dsn: "https://your-dsn@sentry.io/project",
integrations: [nodeProfilingIntegration()],
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
});
// Errors are captured automatically
// Manual capture:
try {
riskyOperation();
} catch (error) {
Sentry.captureException(error);
}
// Add context
Sentry.setUser({ id: "user123", email: "user@example.com" });
Sentry.setTag("feature", "checkout");Python
import sentry_sdk
sentry_sdk.init(
dsn="https://your-dsn@sentry.io/project",
traces_sample_rate=0.1,
)
# Auto-captures unhandled exceptions
# Django, Flask, FastAPI auto-instrumented
# Manual capture
try:
process_payment(order)
except PaymentError as e:
sentry_sdk.capture_exception(e)
sentry_sdk.capture_message("Payment failed for order %s" % order.id)Go
import "github.com/getsentry/sentry-go"
func main() {
sentry.Init(sentry.ClientOptions{
Dsn: "https://your-dsn@sentry.io/project",
TracesSampleRate: 0.1,
})
defer sentry.Flush(2 * time.Second)
}Self-Hosting
Requirements
- Docker 19.03+ and Docker Compose 2.19+
- 8GB RAM minimum (16GB recommended)
- 20GB disk space
Docker Compose
git clone https://github.com/getsentry/self-hosted.git
cd self-hosted
./install.sh # Interactive setup
docker compose up -dComponents deployed:
- Sentry Web (Django)
- Sentry Worker (Celery)
- Sentry Cron
- PostgreSQL
- Redis
- Kafka
- ClickHouse
- Snuba (query engine)
- Symbolicator (source maps)
- Relay (event ingestion)
Key Features
Issue Grouping
Sentry automatically groups similar errors:
Issue: TypeError: Cannot read property 'name' of undefined
├── 1,234 events
├── 56 users affected
├── First seen: 2 days ago
├── Last seen: 5 minutes ago
├── Stack trace with source context
├── Breadcrumbs (30 events before crash)
├── Tags: browser=Chrome, os=Windows, release=v2.1.0
└── Linked commits (suspect commits)Performance Tracing
Transaction: POST /api/checkout (p50: 450ms, p95: 1.2s)
├── HTTP Handler (12ms)
├── Auth Middleware (5ms)
├── Validate Cart (8ms)
├── DB: SELECT products (45ms)
├── Payment API Call (380ms) ← bottleneck
├── DB: INSERT order (15ms)
├── Send Email (async)
└── Response (465ms total)Release Health
Release v2.1.0:
├── Crash-free sessions: 99.2% (↓ from 99.8%)
├── Crash-free users: 98.5%
├── New issues: 3
├── Regressed issues: 1
├── Adoption: 45% of users
└── Suspect commits: abc1234 by @developerSentry vs Alternatives
| Feature | Sentry | Datadog | New Relic | GlitchTip | Bugsnag |
|---|---|---|---|---|---|
| Open Source | Yes | No | No | Yes | No |
| Self-hosted | Yes | No | No | Yes | No |
| Error tracking | Excellent | Good | Good | Basic | Good |
| Performance | APM + Profiling | Full APM | Full APM | No | No |
| Session replay | Yes | Yes | Yes | No | No |
| SDKs | 100+ | 15+ | 15+ | Sentry-compat | 15+ |
| Pricing | Free (self-host) | $15/host | $0.30/GB | Free | $99/mo |
常见问题
Q: 自托管 Sentry 资源需求大吗? A: 是的,完整的 Sentry 包含 Kafka、ClickHouse、PostgreSQL 等多个组件,最低需要 8GB RAM。对于小团队,可以考虑轻量替代 GlitchTip(Sentry 兼容但资源需求小得多)。
Q: 自托管版本和 SaaS 功能一样吗? A: 核心功能(错误追踪、性能监控、告警)完全一样。SaaS 版额外提供 Session Replay、Cron Monitoring 等高级功能,以及更好的扩展性和免维护。
Q: 数据量大了性能会下降吗? A: 自托管版本建议配置事件采样率(tracesSampleRate)来控制数据量。对于高流量应用,0.01-0.1 的采样率即可提供足够的洞察。ClickHouse 后端确保查询性能。
来源与致谢
- GitHub: getsentry/sentry — 43.5K+ ⭐
- 自托管: getsentry/self-hosted
- 官网: sentry.io