Registry / observability / sentry-sdk

sentry-sdk

JSON →
library2.68.1pypypi✓ verified 31d ago

Official Sentry error monitoring and performance Python SDK. Current version: 2.56.0 (Mar 2026). v2.0 (Jan 2024) removed the Hub class entirely — all Hub-based patterns are broken. Scope API replaced Hub. Integrations (Django, FastAPI, Celery, etc.) must be explicitly imported and passed. traces_sample_rate must be set to enable performance monitoring — omitting it means zero traces sent. enable_tracing deprecated in favor of traces_sample_rate.

pip install sentry-sdk
INSTALL
IMPORT
SIG · SENTRY-SDK
S
sentry-sdk
observabilitypythonv2.68.1
Install
3.9s avg
Import
462ms
Disk
71MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.68.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 0.473s · 71.9MB
glibc
py 3.10–3.915 runs
installs and imports cleanly · install 3.9s · import 0.450s · 72MB
71MB installed
● package 71MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sentry_sdk
✓ import sentry_sdk
✗ import sentry_sdk

Sentry Python SDK — error capture, context, and performance tracing.

# pip install sentry-sdk import sentry_sdk sentry_sdk.init( dsn='https://KEY@oNNN.ingest.sentry.io/PROJECT_ID', traces_sample_rate=1.0, environment='production', release='1.0.0', before_send=lambda event, hint: event # return None to drop event ) # Automatic exception capture — unhandled exceptions sent automatically # Manual exception capture try: result = 1 / 0 except Exception as e: sentry_sdk.capture_exception(e) # Add user context sentry_sdk.set_user({'id': '42', 'email': 'user@example.com'}) # Add tags sentry_sdk.set_tag('payment_provider', 'razorpay') # Add extra data sentry_sdk.set_extra('order_id', 'ord_123') # Breadcrumbs sentry_sdk.add_breadcrumb( category='auth', message='User logged in', level='info' ) # Performance tracing with sentry_sdk.start_transaction(op='task', name='process_order'): with sentry_sdk.start_span(op='db', description='fetch order'): pass # your DB call here
Debug
Known issues
breakingHub class removed in v2.0.0 (Jan 2024). All Hub-based patterns (Hub.current, configure_scope, push_scope via Hub) raise AttributeError. Massive volume of pre-2024 tutorials use Hub.
fix
Replace Hub.current.configure_scope() with sentry_sdk.new_scope(). Replace Hub.current.capture_exception() with sentry_sdk.capture_exception().
affects: >= 2.0
breakingenable_tracing parameter deprecated. Still works but logs DeprecationWarning. Will be removed in next major version.
fix
Replace enable_tracing=True with traces_sample_rate=1.0
affects: >= 2.0
gotchaOmitting traces_sample_rate means NO performance data (transactions/spans) is sent to Sentry — only errors. Default is 0.0. Many devs wonder why traces are missing.
fix
Add traces_sample_rate=0.1 (10%) for production or traces_sample_rate=1.0 for development.
affects: all
gotchabefore_send returning None silently drops the event. Sentry logs 'before send dropped event' at INFO level — easy to miss if not watching logs.
fix
before_send must return the event dict to send it. Return None only when intentionally filtering.
affects: all
gotchaset_measurement() deprecated in favor of set_data() on spans. Will be removed in next major version.
fix
span.set_data('key', value) instead of span.set_measurement('key', value)
affects: >= 2.0
gotchasentry_sdk.init() must be called before any framework initialization (before app = FastAPI(), before Django setup). Calling it after means some auto-instrumentation is missed.
fix
Call sentry_sdk.init() at the very top of your entry point, before importing framework app objects.
affects: all
gotchaIn async apps (FastAPI, async Django), sentry_sdk.init() should be called inside an async context or at module level before the event loop starts to ensure async instrumentation works correctly.
fix
Initialize at module level before app creation, not inside async startup handlers.
affects: >= 2.0
breakingsentry_sdk.init() fails if the DSN provided is malformed or contains placeholders (e.g., 'PROJECT_ID', 'PUBLIC_KEY', 'HOST') instead of actual values, leading to a sentry_sdk.utils.BadDsn error.
fix
Ensure the DSN string passed to `sentry_sdk.init()` is a complete and valid Sentry DSN, replacing any placeholders with their actual values obtained from your Sentry project settings.
affects: all
breakingsentry_sdk.init() failed because the DSN contains placeholder values (e.g., 'PROJECT_ID', 'KEY', 'oNNN') instead of actual Sentry DSN components.
fix
Replace all DSN placeholders (PROJECT_ID, KEY, oNNN) with the actual values obtained from your Sentry project settings. Ensure the DSN is a valid URL.
affects: all
Upgrade
Version history
2.68.1latest on PyPI · released Aug 24, 2026
Audit
Dependencies
urllib3requiredRequired. Installed automatically.
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
2
Resources
sentry-sdk — pip install sentry-sdk · libregistry