Sentry
Monitoring Platform
Sentry
Overview
Sentry is a platform specialized in real-time error tracking and application performance monitoring. It supports application quality improvement through detailed error aggregation and analysis, boasting top-class accuracy and detail in the error monitoring field. It gains high developer support with features directly linked to development team productivity improvement.
Details
Sentry is designed as a specialized platform for error tracking and performance monitoring, following the philosophy of "doing one thing extremely well" with precision and depth.
Key Features
- Real-time Error Tracking: Detailed stack traces and contextual information
- Performance Monitoring: Transaction tracking and performance analysis
- Release Monitoring: Deployment tracking and release quality analysis
- Issue Alerting: Smart alerting with noise reduction
- Source Map Support: Detailed JavaScript error analysis
- Integrations: Rich integrations with Slack, GitHub, Jira, and more
- Team Collaboration: Error assignment and resolution workflows
Technical Features
- Multi-language Support: Support for 30+ programming languages and frameworks
- Session Replay: Complete reproduction of user sessions
- Real-time Notifications: Immediate alerts when errors occur
- Detailed Context: Collection of user, device, and environment information
- High-precision Filtering: Meaningful alerts with minimal noise
Pros and Cons
Pros
- Industry-leading accuracy and detail in error monitoring
- Developer-friendly intuitive interface
- Comprehensive free tier suitable for small projects
- Very easy setup process
- Rich language and framework support
- Powerful debugging features and contextual information
- Open source version available
Cons
- Limited infrastructure monitoring capabilities
- Weaker log management compared to comprehensive platforms
- Cost escalation in large-scale environments
- Requires separate tools for non-error metrics collection
- Limited custom dashboard functionality
References
Setup and Monitoring Examples
Basic Setup
// Sentry initialization in JavaScript/Node.js
import * as Sentry from "@sentry/node";
Sentry.init({
dsn: "YOUR_DSN_HERE",
tracesSampleRate: 1.0, // Performance monitoring
profilesSampleRate: 1.0, // Profiling
});
Metrics Collection
# Sentry error tracking in Python
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
sentry_sdk.init(
dsn="YOUR_DSN_HERE",
integrations=[DjangoIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
)
# Send custom errors
try:
risky_operation()
except Exception as e:
sentry_sdk.capture_exception(e)
# Send custom messages
sentry_sdk.capture_message("Something went wrong", level="error")
Alerting Configuration
// Add detailed context when errors occur
Sentry.configureScope((scope) => {
scope.setUser({
id: "12345",
email: "[email protected]",
username: "user123"
});
scope.setContext("payment", {
amount: 100.0,
currency: "USD",
payment_method: "credit_card"
});
scope.setTag("environment", "production");
scope.setLevel("error");
});
Dashboard Creation
// Performance monitoring setup
Sentry.startSpan({
op: "http.request",
name: "API Call"
}, () => {
// API call
return fetch('/api/data')
.then(response => response.json())
.catch(error => {
Sentry.captureException(error);
throw error;
});
});
// Manual transaction creation
const transaction = Sentry.startTransaction({
name: "User Checkout Process",
op: "transaction",
});
Sentry.getCurrentHub().configureScope(scope => scope.setSpan(transaction));
try {
await processCheckout();
transaction.setStatus("ok");
} catch (error) {
transaction.setStatus("internal_error");
Sentry.captureException(error);
} finally {
transaction.finish();
}
Log Analysis
# Sentry integration with Django
# settings.py
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
# Logging integration setup
sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture INFO and above
event_level=logging.ERROR # Send ERROR as events
)
sentry_sdk.init(
dsn="YOUR_DSN_HERE",
integrations=[
DjangoIntegration(),
sentry_logging,
],
traces_sample_rate=1.0,
)
Integration Setup
// Sentry setup for React applications
import React from "react";
import * as Sentry from "@sentry/react";
import { BrowserRouter } from "react-router-dom";
Sentry.init({
dsn: "YOUR_DSN_HERE",
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.reactRouterV6Instrumentation(
React.useEffect,
useLocation,
useNavigationType,
createRoutesFromChildren,
matchRoutes,
),
}),
],
tracesSampleRate: 1.0,
});
// Sentry-wrapped component
const SentryRoutes = Sentry.withSentryRouting(Routes);
function App() {
return (
<BrowserRouter>
<SentryRoutes>
{/* Route definitions */}
</SentryRoutes>
</BrowserRouter>
);
}
Error Analysis
// Detailed error analysis and filtering
Sentry.init({
dsn: "YOUR_DSN_HERE",
beforeSend(event, hint) {
// Don't send errors from development environment
if (event.environment === 'development') {
return null;
}
// Filter specific errors
if (event.exception) {
const error = hint.originalException;
if (error && error.message.includes('Script error')) {
return null;
}
}
return event;
},
// Exclude uptime bot errors
beforeSend(event) {
const userAgent = event.request?.headers?.["user-agent"];
if (userAgent && userAgent.includes("SentryUptimeBot")) {
return null;
}
return event;
}
});