Legacy Python client for Sentry error monitoring service with framework integration and exception tracking capabilities.
npx @tessl/cli install tessl/pypi-raven@6.10.0Raven is the official legacy Python client for Sentry, providing comprehensive error tracking and exception monitoring for Python applications. It automatically captures and reports unhandled exceptions, supports extensive framework integrations, and provides detailed diagnostic information for debugging and monitoring production applications.
pip install ravenfrom raven import ClientCommon imports for specific integrations:
from raven.conf import setup_logging
from raven.handlers.logging import SentryHandler
from raven.contrib.django.client import DjangoClient
from raven.contrib.flask import Sentryfrom raven import Client
# Initialize client with your Sentry DSN
client = Client('https://public_key:secret_key@sentry.io/project_id')
# Capture an exception
try:
1/0
except ZeroDivisionError:
client.captureException()
# Capture a message
client.captureMessage('Something went wrong!')
# Add context information
client.user_context({'id': 123, 'email': 'user@example.com'})
client.tags_context({'version': '1.0', 'environment': 'production'})
client.extra_context({'request_id': 'abc123'})
# Capture with context
try:
process_payment()
except Exception:
client.captureException()Raven uses a modular architecture with several key components:
The main Client class provides the primary interface for capturing and sending events to Sentry, with comprehensive configuration options and context management.
class Client:
def __init__(self, dsn=None, raise_send_errors=False, transport=None,
install_sys_hook=True, install_logging_hook=True,
hook_libraries=None, enable_breadcrumbs=True,
_random_seed=None, **options): ...
def captureException(self, exc_info=None, **kwargs): ...
def captureMessage(self, message, **kwargs): ...
def captureQuery(self, query, params=(), engine=None, **kwargs): ...
def captureBreadcrumb(self, **kwargs): ...Comprehensive integrations with popular Python web frameworks including Django, Flask, Bottle, Celery, and others, providing automatic error capture and framework-specific context.
# Django
class DjangoClient(Client): ...
# Flask
class Sentry:
def __init__(self, app=None, **kwargs): ...
def init_app(self, app, **kwargs): ...Native Python logging integration with configurable handlers that automatically capture log records as Sentry events, supporting filtering and custom formatting.
class SentryHandler(logging.Handler):
def __init__(self, client=None, **kwargs): ...
def emit(self, record): ...
def setup_logging(handler, exclude=None): ...Multiple transport implementations for different environments and performance requirements, including synchronous, threaded, and async framework-specific transports.
class HTTPTransport: ...
class ThreadedHTTPTransport: ...
class RequestsHTTPTransport: ...
class ThreadedRequestsHTTPTransport: ...
class GeventedHTTPTransport: ...
class TwistedHTTPTransport: ...
class TornadoHTTPTransport: ...
class EventletHTTPTransport: ...Customizable data processors for sanitizing sensitive information, transforming data structures, and controlling what information is sent to Sentry.
class SanitizePasswordsProcessor: ...
class SanitizeKeysProcessor: ...
class RemovePostDataProcessor: ...
class RemoveStackLocalsProcessor: ...Thread-local context management for maintaining user information, tags, extra data, and breadcrumbs throughout the application lifecycle.
class Context:
def activate(self, sticky=False): ...
def merge(self, data, activate=True): ...
def clear(self, deactivate=None): ...Automatic and manual breadcrumb collection for tracking user actions and application state leading up to errors, with customizable recording and filtering.
class BreadcrumbBuffer:
def record(self, timestamp=None, level=None, message=None, **kwargs): ...
def clear(self): ...
def record(**kwargs): ...
def install_logging_hook(): ...class ClientState:
ONLINE = 1
ERROR = 0
def should_try(self): ...
class DummyClient(Client):
"""No-op client that discards all messages"""
def send(self, **kwargs): ...