{"id":190,"library":"sentry-sdk","title":"Sentry Python SDK","description":"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.","status":"active","version":"2.56.0","language":"python","source_language":"en","source_url":"https://github.com/getsentry/sentry-python","tags":["sentry","monitoring","observability","python","error-tracking","apm"],"install":[{"cmd":"pip install sentry-sdk","lang":"bash","label":"Python (base)"},{"cmd":"pip install 'sentry-sdk[fastapi]'","lang":"bash","label":"With FastAPI integration"},{"cmd":"pip install 'sentry-sdk[django]'","lang":"bash","label":"With Django integration"}],"dependencies":[{"reason":"Required. Installed automatically.","package":"urllib3","optional":false}],"imports":[{"wrong":"import sentry_sdk","symbol":"sentry_sdk","correct":"import sentry_sdk"}],"quickstart":{"code":"# pip install sentry-sdk\nimport sentry_sdk\n\nsentry_sdk.init(\n    dsn='https://KEY@oNNN.ingest.sentry.io/PROJECT_ID',\n    traces_sample_rate=1.0,\n    environment='production',\n    release='1.0.0',\n    before_send=lambda event, hint: event  # return None to drop event\n)\n\n# Automatic exception capture — unhandled exceptions sent automatically\n\n# Manual exception capture\ntry:\n    result = 1 / 0\nexcept Exception as e:\n    sentry_sdk.capture_exception(e)\n\n# Add user context\nsentry_sdk.set_user({'id': '42', 'email': 'user@example.com'})\n\n# Add tags\nsentry_sdk.set_tag('payment_provider', 'razorpay')\n\n# Add extra data\nsentry_sdk.set_extra('order_id', 'ord_123')\n\n# Breadcrumbs\nsentry_sdk.add_breadcrumb(\n    category='auth',\n    message='User logged in',\n    level='info'\n)\n\n# Performance tracing\nwith sentry_sdk.start_transaction(op='task', name='process_order'):\n    with sentry_sdk.start_span(op='db', description='fetch order'):\n        pass  # your DB call here","lang":"python","description":"Sentry Python SDK — error capture, context, and performance tracing."},"warnings":[{"fix":"Replace Hub.current.configure_scope() with sentry_sdk.new_scope(). Replace Hub.current.capture_exception() with sentry_sdk.capture_exception().","message":"Hub 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.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"Replace enable_tracing=True with traces_sample_rate=1.0","message":"enable_tracing parameter deprecated. Still works but logs DeprecationWarning. Will be removed in next major version.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"Add traces_sample_rate=0.1 (10%) for production or traces_sample_rate=1.0 for development.","message":"Omitting 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.","severity":"gotcha","affected_versions":"all"},{"fix":"before_send must return the event dict to send it. Return None only when intentionally filtering.","message":"before_send returning None silently drops the event. Sentry logs 'before send dropped event' at INFO level — easy to miss if not watching logs.","severity":"gotcha","affected_versions":"all"},{"fix":"span.set_data('key', value) instead of span.set_measurement('key', value)","message":"set_measurement() deprecated in favor of set_data() on spans. Will be removed in next major version.","severity":"gotcha","affected_versions":">= 2.0"},{"fix":"Call sentry_sdk.init() at the very top of your entry point, before importing framework app objects.","message":"sentry_sdk.init() must be called before any framework initialization (before app = FastAPI(), before Django setup). Calling it after means some auto-instrumentation is missed.","severity":"gotcha","affected_versions":"all"},{"fix":"Initialize at module level before app creation, not inside async startup handlers.","message":"In 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.","severity":"gotcha","affected_versions":">= 2.0"},{"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.","message":"sentry_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.","severity":"breaking","affected_versions":"all"},{"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.","message":"sentry_sdk.init() failed because the DSN contains placeholder values (e.g., 'PROJECT_ID', 'KEY', 'oNNN') instead of actual Sentry DSN components.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"search_vec":"'2.56.0':14 '2024':19 '2026':16 'api':33 'apm':79 'base':28 'broken':31 'celeri':39 'class':23 'current':12 'deprec':65 'django':37 'enabl':54,63 'entir':24 'error':6,77 'error-track':76 'etc':40 'explicit':43 'fastapi':38 'favor':67 'hub':22,27,35 'hub-bas':26 'import':44 'integr':36 'jan':18 'mar':15 'mean':59 'monitor':7,56,73 'must':41,50 'observ':74 'offici':4 'omit':57 'pass':46 'pattern':29 'perform':9,55 'python':2,10,75 'rate':49,71 'remov':20 'replac':34 'sampl':48,70 'scope':32 'sdk':3,11 'sent':62 'sentri':1,5,72 'set':52 'trace':47,61,64,69 'track':78 'v2.0':17 'version':13 'zero':60","created_at":"2026-03-25T16:25:45.525273+00:00","updated_at":"2026-04-16T21:35:48.549032+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"2.68.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://sentry.io","github":"https://github.com/getsentry/sentry-python","docs":"https://docs.sentry.io/platforms/python/","changelog":"https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md","pypi":"https://pypi.org/project/sentry-sdk/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-08-26","next_check":"2026-07-30","install_tag":"verified"}}