Title: Exceptions not logged on sentry.io when using `concurrent.futures.ThreadPoolExecutor` · Issue #1234 · getsentry/sentry-python · GitHub
Open Graph Title: Exceptions not logged on sentry.io when using `concurrent.futures.ThreadPoolExecutor` · Issue #1234 · getsentry/sentry-python
X Title: Exceptions not logged on sentry.io when using `concurrent.futures.ThreadPoolExecutor` · Issue #1234 · getsentry/sentry-python
Description: Environment How do you use Sentry? Sentry SaaS (sentry.io) Which SDK and version? macOS 11.5.2 (big sur) CPython 3.9.6 sentry_sdk 1.4.2 Steps to Reproduce I ran the following block of code from concurrent.futures import ThreadPoolExecuto...
Open Graph Description: Environment How do you use Sentry? Sentry SaaS (sentry.io) Which SDK and version? macOS 11.5.2 (big sur) CPython 3.9.6 sentry_sdk 1.4.2 Steps to Reproduce I ran the following block of code from con...
X Description: Environment How do you use Sentry? Sentry SaaS (sentry.io) Which SDK and version? macOS 11.5.2 (big sur) CPython 3.9.6 sentry_sdk 1.4.2 Steps to Reproduce I ran the following block of code from con...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/1234
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Exceptions not logged on sentry.io when using `concurrent.futures.ThreadPoolExecutor` ","articleBody":"### Environment\r\n\r\nHow do you use Sentry?\r\nSentry SaaS (sentry.io)\r\n\r\nWhich SDK and version?\r\nmacOS 11.5.2 (big sur)\r\nCPython 3.9.6\r\nsentry_sdk 1.4.2\r\n\r\n\r\n### Steps to Reproduce\r\nI ran the following block of code\r\n```python\r\nfrom concurrent.futures import ThreadPoolExecutor\r\nimport sentry_sdk\r\nfrom sentry_sdk.integrations.threading import ThreadingIntegration\r\n\r\ndsn = \"\u003cyour sentry dsn>\"\r\nsentry_sdk.init(\r\n dsn=dsn,\r\n shutdown_timeout=10,\r\n debug=True,\r\n integrations=[ThreadingIntegration(propagate_hub=True)],\r\n)\r\nsentry_sdk.set_tag(\"mydata\", 42)\r\n\r\ndef task(name, item):\r\n # task that is performed in parallel\r\n print(\"task {} {} started\".format(name, item))\r\n sentry_sdk.capture_message(\"going to crash with a 30/0\")\r\n 40/0 # I expect this to log an exception but does NOT log an exception on sentry.io\r\n print(\"task {} {} finished\".format(name, item)) # we never get here because of the crash\r\n\r\ndef task_manager():\r\n THREAD_MAX_WORKERS = 100\r\n thread_executor = ThreadPoolExecutor(max_workers=THREAD_MAX_WORKERS)\r\n for item in range(5):\r\n thread_executor.submit(task, \"test\", item) # create a new job\r\n thread_executor.shutdown() # we will be blocked here until all threads complete\r\n print(\"jobs finished\")\r\n\r\nif __name__ == \"__main__\":\r\n task_manager()\r\n 41/0 # this WILL log an exception on sentry.io\r\n```\r\n\r\n### Expected Result\r\nAs `task_manager()` would create 5x separate `task()` jobs, I expected:\r\n* 5x capture_messages `going to crash with a 30/0` to be logged on sentry.io (line 17)\r\n* 5x exceptions to be logged with `40/0` ZeroDivisionError exception (line 18)\r\n* 1x exception to be logged with `41/0` ZeroDivisionError exception (line 31)\r\n\r\n### Actual Result\r\n\r\nI experienced:\r\n* 5x capture_messages `going to crash with a 30/0` were `SUCCESSFULLY` logged on sentry.io (line 17)\r\n* 5x exceptions with `40/0` ZeroDivisionError exception (line 18) was `NOT SUCCESSFULLY` logged on sentry.io\r\n* 1x exception with `41/0` ZeroDivisionError exception (line 31) was `SUCCESSFULLY` logged on sentry.io\r\n\r\n\r\n```python\r\npython test_thread_mvp.py\r\n [sentry] DEBUG: Setting up integrations (with default = True)\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.django.DjangoIntegration: Django not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.flask.FlaskIntegration: Flask is not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.bottle.BottleIntegration: Bottle not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.falcon.FalconIntegration: Falcon not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.sanic.SanicIntegration: Sanic not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.celery.CeleryIntegration: Celery not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.rq.RqIntegration: RQ not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.aiohttp.AioHttpIntegration: AIOHTTP not installed\r\n [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.tornado.TornadoIntegration: Tornado not installed\r\n [sentry] DEBUG: Setting up previously not enabled integration threading\r\n [sentry] DEBUG: Setting up previously not enabled integration logging\r\n [sentry] DEBUG: Setting up previously not enabled integration stdlib\r\n [sentry] DEBUG: Setting up previously not enabled integration excepthook\r\n [sentry] DEBUG: Setting up previously not enabled integration dedupe\r\n [sentry] DEBUG: Setting up previously not enabled integration atexit\r\n [sentry] DEBUG: Setting up previously not enabled integration modules\r\n [sentry] DEBUG: Setting up previously not enabled integration argv\r\n [sentry] DEBUG: Setting up previously not enabled integration sqlalchemy\r\n [sentry] DEBUG: Setting up previously not enabled integration boto3\r\n [sentry] DEBUG: Enabling integration threading\r\n [sentry] DEBUG: Enabling integration logging\r\n [sentry] DEBUG: Enabling integration stdlib\r\n [sentry] DEBUG: Enabling integration excepthook\r\n [sentry] DEBUG: Enabling integration dedupe\r\n [sentry] DEBUG: Enabling integration atexit\r\n [sentry] DEBUG: Enabling integration modules\r\n [sentry] DEBUG: Enabling integration argv\r\n [sentry] DEBUG: Enabling integration sqlalchemy\r\n [sentry] DEBUG: Enabling integration boto3\r\ntask test 0 started\r\ntask test 1 started\r\ntask test 2 started\r\ntask test 3 started\r\ntask test 4 started\r\njobs finished\r\n [sentry] DEBUG: Sending event, type:null level:info event_id:3d30670b8f134560bf7288091d72ada4 project:7463834 host:o3847193.ingest.sentry.io\r\nTraceback (most recent call last):\r\n File \"/Users/z/test_thread_mvp.py\", line 31, in \u003cmodule>\r\n 41/0 # this WILL log an exception on sentry.io\r\nZeroDivisionError: division by zero\r\n [sentry] DEBUG: atexit: got shutdown signal\r\n [sentry] DEBUG: atexit: shutting down client\r\n [sentry] DEBUG: Flushing HTTP transport\r\n [sentry] DEBUG: background worker got flush request\r\n [sentry] DEBUG: 7 event(s) pending on flush\r\nSentry is attempting to send 7 pending error messages\r\nWaiting up to 10 seconds\r\nPress Ctrl-C to quit\r\n [sentry] DEBUG: [Tracing] Adding `sentry-trace` header 573c7981bb724747a7b6a1c57ac1e9b4-8c262e380834b2b3- to outgoing request to https://o3847193.ingest.sentry.io/api/7463834/store/.\r\n [sentry] DEBUG: Sending event, type:null level:info event_id:97fe1e03626c46e185372dbb78f30cc7 project:7463834 host:o3847193.ingest.sentry.io\r\n [sentry] DEBUG: [Tracing] Adding `sentry-trace` header 93b26a8d501c4837921f9dc45b12269a-917a82ad3ee8be4c- to outgoing request to https://o3847193.ingest.sentry.io/api/7463834/store/.\r\n [sentry] DEBUG: Sending event, type:null level:info event_id:02b389a7eee749d4ad50f873369b06fa project:7463834 host:o3847193.ingest.sentry.io\r\n [sentry] DEBUG: [Tracing] Adding `sentry-trace` header 0ebc6b346b7341088d9d8a3948913e5a-8d4701f59abbd49d- to outgoing request to https://o3847193.ingest.sentry.io/api/7463834/store/.\r\n [sentry] DEBUG: Sending event, type:null level:info event_id:aa39d467ed5b4261a5507402660c8682 project:7463834 host:o3847193.ingest.sentry.io\r\n [sentry] DEBUG: [Tracing] Adding `sentry-trace` header dcdfdc9b20e14ae399b149e9c083a63b-8f0dcbf5cc377c87- to outgoing request to https://o3847193.ingest.sentry.io/api/7463834/store/.\r\n [sentry] DEBUG: Sending event, type:null level:info event_id:fd9c63e42864441c92e301a0147efbcb project:7463834 host:o3847193.ingest.sentry.io\r\n [sentry] DEBUG: [Tracing] Adding `sentry-trace` header a3f4e86d18e54a49b9c3dc7e0d5a2533-b89dd26b2502bec7- to outgoing request to https://o3847193.ingest.sentry.io/api/7463834/store/.\r\n [sentry] DEBUG: Sending event, type:null level:error event_id:436508a757c6410688c28a975e1fd6c5 project:7463834 host:o3847193.ingest.sentry.io\r\n [sentry] DEBUG: [Tracing] Adding `sentry-trace` header 8c2203cb91fd480fb7abae703f271d81-a0dcba3c252e9470- to outgoing request to https://o3847193.ingest.sentry.io/api/7463834/store/.\r\n [sentry] DEBUG: background worker flushed\r\n [sentry] DEBUG: Killing HTTP transport\r\n [sentry] DEBUG: background worker got kill request\r\n```\r\n\r\nNote that:\r\n* removing ThreadingIntegration didn't seem to affect the result\r\n* initialising `sentry_dsk.init` inside `task` doesn't seem to affect the result ","author":{"url":"https://github.com/patunhedged","@type":"Person","name":"patunhedged"},"datePublished":"2021-11-01T01:43:33Z","url":"https://github.com/getsentry/sentry-python/issues/1234"}
| 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:fff40baf-5cc2-418e-4eb5-d5ed7b1f7ac6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80FC:9F275:2E8C6C:4083F0:6B008AF7 |
| html-safe-nonce | 15092e93927953de63c4b7142bb8d128876ca036dae1046d5445be5aadbc73fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEZDOjlGMjc1OjJFOEM2Qzo0MDgzRjA6NkIwMDhBRjciLCJ2aXNpdG9yX2lkIjoiNzY5NTcxNDM2Njg4NDE4Njg3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c573f75ee3c1eeb4029773a1f3bc5566d8f3ded98c4a30875ed190650b9c7918 |
| hovercard-subject-tag | issue:1040666675 |
| 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/1234/issue_layout |
| twitter:image | https://opengraph.githubassets.com/69767a88b719a176234e7a188f6498f8182f0c2bfea28607cd5fe71049588c2d/getsentry/sentry-python/issues/1234 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/69767a88b719a176234e7a188f6498f8182f0c2bfea28607cd5fe71049588c2d/getsentry/sentry-python/issues/1234 |
| og:image:alt | Environment How do you use Sentry? Sentry SaaS (sentry.io) Which SDK and version? macOS 11.5.2 (big sur) CPython 3.9.6 sentry_sdk 1.4.2 Steps to Reproduce I ran the following block of code from con... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | patunhedged |
| hostname | github.com |
| expected-hostname | github.com |
| None | c710a5cb5c47be60abfe6e8410436d409906979dbed614ef09f29c60f5535b08 |
| 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 | be616a2a6ec1c609d6e002896dff5352d5c5f28b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width