backend / observability / 01_sentry.md

What is Sentry?

3 interview angles 4 min read source

What is Sentry?

Definition

Sentry is an open-source error tracking and performance monitoring platform that helps developers identify, debug, and resolve issues in their applications in real-time. It automatically captures exceptions, errors, and performance issues across various programming languages and frameworks.

Key Features

Core Capabilities

  1. Error Tracking: Automatically captures and reports errors
  2. Performance Monitoring: Tracks application performance metrics
  3. Release Tracking: Associates errors with code releases
  4. User Context: Provides user information when errors occur
  5. Breadcrumbs: Shows events leading up to an error
  6. Issue Grouping: Groups similar errors together
  7. Alerting: Notifies teams of critical issues

How It Works

Application → Sentry SDK → Sentry Server → Dashboard
     ↓              ↓            ↓
  Error      Captures      Stores &
  Occurs     Exception     Analyzes

Basic Setup

Python Example

import sentry_sdk

# Initialize Sentry
sentry_sdk.init(
    dsn="https://your-key@sentry.io/project-id",
    traces_sample_rate=1.0,
    environment="production"
)

# Automatic error capture
def divide(a, b):
    return a / b  # Sentry automatically captures ZeroDivisionError

# Manual error capture
try:
    risky_operation()
except Exception as e:
    sentry_sdk.capture_exception(e)

JavaScript Example

import * as Sentry from "@sentry/browser";

Sentry.init({
  dsn: "https://your-key@sentry.io/project-id",
  environment: "production",
  tracesSampleRate: 1.0,
});

// Automatic error capture
// Sentry automatically captures unhandled errors

// Manual capture
try {
  riskyOperation();
} catch (error) {
  Sentry.captureException(error);
}

Common Use Cases

  1. Error Monitoring: Track exceptions in production
  2. Performance Monitoring: Monitor API response times
  3. Release Tracking: Track errors by version
  4. User Impact: See which users are affected
  5. Issue Prioritization: Focus on most critical errors

Key Concepts

Issues

  • Grouped errors with similar stack traces
  • Shows frequency, affected users, first/last seen
  • Can be assigned, resolved, or ignored

Events

  • Individual error occurrences
  • Contains full context (stack trace, breadcrumbs, user info)
  • Linked to issues

Releases

  • Code deployments
  • Track which release introduced errors
  • Performance regression detection
  • Events leading up to an error
  • User actions, API calls, console logs
  • Helps understand error context

Common Interview Questions

Q1: What is Sentry and why use it?

Sentry is an error tracking and performance monitoring platform. Use it to:

  • Catch Errors: Automatically capture exceptions in production
  • Debug Faster: Get full context (stack trace, user info, breadcrumbs)
  • Monitor Performance: Track slow API calls and transactions
  • Improve Quality: Identify and fix issues before users report them

Q2: How does Sentry track errors?

Sentry uses SDKs that:

  1. Capture Exceptions: Automatically catch unhandled exceptions
  2. Send to Server: Transmit error data to Sentry server
  3. Group Issues: Similar errors grouped together
  4. Store Context: Stack traces, user info, breadcrumbs, environment

Q3: What is the difference between Sentry and logging?

Aspect Sentry Logging
Purpose Error tracking General logging
Focus Exceptions and errors All events
Grouping Groups similar errors Linear log stream
Context Rich context automatically Manual context
Alerts Built-in alerting Manual alert setup
UI Web dashboard Log files/aggregators

Use Both: Sentry for errors, logging for general events.

Q4: How do you integrate Sentry with Django?

# settings.py
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn="https://your-key@sentry.io/project-id",
    integrations=[DjangoIntegration()],
    traces_sample_rate=1.0,
    send_default_pii=True,
    environment=os.getenv("ENVIRONMENT", "development"),
)

Q5: What is performance monitoring in Sentry?

Sentry tracks:

  • Transaction Duration: Time for operations
  • Slow Queries: Database query performance
  • API Performance: Endpoint response times
  • Frontend Performance: Page load times, render performance

Example:

import sentry_sdk

# Track transaction
with sentry_sdk.start_transaction(op="task", name="process_data"):
    process_data()  # Sentry tracks duration

Best Practices

  1. Set Up Environments: Separate dev, staging, production
  2. Configure Sampling: Don’t send all events (cost control)
  3. Add Context: Include user info, tags, extra data
  4. Use Releases: Track errors by version
  5. Set Up Alerts: Get notified of critical issues
  6. Filter Noise: Ignore non-critical errors
  7. Monitor Performance: Track slow operations
  8. Review Regularly: Triage and fix issues

Summary

Sentry is:

  • Error Tracking Platform: Captures and reports exceptions
  • Performance Monitor: Tracks application performance
  • Developer Tool: Helps debug production issues
  • Real-time Alerts: Notifies teams of problems

Key benefits:

  • Automatic error capture
  • Rich context (stack traces, breadcrumbs, user info)
  • Issue grouping and prioritization
  • Performance monitoring
  • Release tracking

Use Sentry to:

  • Monitor production errors
  • Debug issues faster
  • Track performance
  • Improve application quality

Interview angle

  • “What is Sentry for, and what isn’t it?” - error tracking: aggregating exceptions with stack traces, request context and release information so you can prioritise by impact. It’s not a metrics or logging platform, though it now overlaps with tracing.
  • “Why does grouping matter?” - it turns thousands of events into a handful of issues ranked by frequency and users affected. Bad grouping - usually from dynamic values in the message - produces noise nobody triages.
  • “How do you avoid leaking PII?” - scrub sensitive fields before send, disable default PII capture, and be deliberate about request bodies and headers. Error trackers accumulate personal data quickly if left on defaults.