Title: Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python · GitHub
Open Graph Title: Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python
X Title: Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python
Description: Is before_send broken? If I add a before_send: def _before_send(event, hint): return event sentry_sdk.init( integrations=[ sentry_sdk.integrations.celery.CeleryIntegration(), sentry_sdk.integrations.pyramid.PyramidIntegration(), ], envir...
Open Graph Description: Is before_send broken? If I add a before_send: def _before_send(event, hint): return event sentry_sdk.init( integrations=[ sentry_sdk.integrations.celery.CeleryIntegration(), sentry_sdk.integration...
X Description: Is before_send broken? If I add a before_send: def _before_send(event, hint): return event sentry_sdk.init( integrations=[ sentry_sdk.integrations.celery.CeleryIntegration(), sentry_sdk.integration...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/237
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment","articleBody":"Is `before_send` broken?\r\n\r\nIf I add a `before_send`:\r\n\r\n```python\r\ndef _before_send(event, hint):\r\n return event\r\n\r\nsentry_sdk.init(\r\n integrations=[\r\n sentry_sdk.integrations.celery.CeleryIntegration(),\r\n sentry_sdk.integrations.pyramid.PyramidIntegration(),\r\n ],\r\n environment=\"dev\",\r\n send_default_pii=True,\r\n before_send=_before_send,\r\n)\r\n```\r\n\r\nthen if my Pyramid application raises an exception, e.g:\r\n\r\n```python\r\nraise RuntimeError(\"Argh\")\r\n```\r\n\r\nthen `sentry_sdk` appears to crash when trying to report the exception to Sentry:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py\", line 257, in toolbar_tween\r\n response = _handler(request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_debugtoolbar/panels/performance.py\", line 58, in resource_timer_handler\r\n result = handler(request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/tweens.py\", line 51, in excview_tween\r\n request_iface=request_iface.combined\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/view.py\", line 547, in _call_view\r\n response = view_callable(context, request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/config/views.py\", line 182, in __call__\r\n return view(context, request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 393, in attr_view\r\n return view(context, request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 371, in predicate_wrapper\r\n return view(context, request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 330, in _authdebug_view\r\n return view(context, request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 442, in rendered_view\r\n result = view(context, request)\r\n File \"/home/seanh/Projects/h/h/views/errors.py\", line 33, in error\r\n handle_exception(request, exception=context)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/tweens.py\", line 22, in excview_tween\r\n response = handler(request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_tm/__init__.py\", line 119, in tm_tween\r\n reraise(*exc_info)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_tm/__init__.py\", line 98, in tm_tween\r\n response = handler(request)\r\n File \"/home/seanh/Projects/h/h/tweens.py\", line 22, in conditional_http_tween\r\n response = handler(request)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/integrations/pyramid.py\", line 53, in sentry_patched_handle_request\r\n _capture_exception(exc_info)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/integrations/pyramid.py\", line 85, in _capture_exception\r\n hub.capture_event(event, hint=hint)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/hub.py\", line 224, in capture_event\r\n rv = client.capture_event(event, hint, scope)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/client.py\", line 190, in capture_event\r\n event = self._prepare_event(event, hint, scope)\r\n File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/client.py\", line 125, in _prepare_event\r\n if new_event is None:\r\nUnboundLocalError: local variable 'new_event' referenced before assignment\r\n```\r\n\r\nHere's the actual code in my app that's producing this crash: https://github.com/hypothesis/h/pull/5497","author":{"url":"https://github.com/seanh","@type":"Person","name":"seanh"},"datePublished":"2019-01-16T18:35:30Z","url":"https://github.com/getsentry/sentry-python/issues/237"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c363a037-25ee-237b-f3c6-a519df60b1ac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A592:358871:39E006:4E9CED:6B00C69C |
| html-safe-nonce | 55a7c3a41fac13751646bac63261bfbf3373ae250ce438b96590b9650db1b64c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTkyOjM1ODg3MTozOUUwMDY6NEU5Q0VEOjZCMDBDNjlDIiwidmlzaXRvcl9pZCI6Ijg1NjI3ODg5NDg3ODU1NDY5MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c39f38343fb8cbf5177bc98d7d2e1ea20fbc483ee1cf9204e55f6500b409a031 |
| hovercard-subject-tag | issue:399941409 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/237/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c90e60c3787c2279d141b8c480973805b3a5d8f0ed9cea7112ced6eed3d5e2cb/getsentry/sentry-python/issues/237 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c90e60c3787c2279d141b8c480973805b3a5d8f0ed9cea7112ced6eed3d5e2cb/getsentry/sentry-python/issues/237 |
| og:image:alt | Is before_send broken? If I add a before_send: def _before_send(event, hint): return event sentry_sdk.init( integrations=[ sentry_sdk.integrations.celery.CeleryIntegration(), sentry_sdk.integration... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | seanh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width