Skip to content

Exceptions not logged on sentry.io when using concurrent.futures.ThreadPoolExecutor #1234

Description

@patunhedged

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

fromconcurrent.futuresimportThreadPoolExecutorimportsentry_sdkfromsentry_sdk.integrations.threadingimportThreadingIntegrationdsn="<your sentry dsn>"sentry_sdk.init(
dsn=dsn,
shutdown_timeout=10,
debug=True,
integrations=[ThreadingIntegration(propagate_hub=True)],
)
sentry_sdk.set_tag("mydata", 42)
deftask(name, item):
# task that is performed in parallelprint("task {} {} started".format(name, item))
sentry_sdk.capture_message("going to crash with a 30/0")
40/0# I expect this to log an exception but does NOT log an exception on sentry.ioprint("task {} {} finished".format(name, item)) # we never get here because of the crashdeftask_manager():
THREAD_MAX_WORKERS=100thread_executor=ThreadPoolExecutor(max_workers=THREAD_MAX_WORKERS)
foriteminrange(5):
thread_executor.submit(task, "test", item) # create a new jobthread_executor.shutdown() # we will be blocked here until all threads completeprint("jobs finished")
if__name__=="__main__":
task_manager()
41/0# this WILL log an exception on sentry.io

Expected Result

As task_manager() would create 5x separate task() jobs, I expected:

  • 5x capture_messages going to crash with a 30/0 to be logged on sentry.io (line 17)
  • 5x exceptions to be logged with 40/0 ZeroDivisionError exception (line 18)
  • 1x exception to be logged with 41/0 ZeroDivisionError exception (line 31)

Actual Result

I experienced:

  • 5x capture_messages going to crash with a 30/0 were SUCCESSFULLY logged on sentry.io (line 17)
  • 5x exceptions with 40/0 ZeroDivisionError exception (line 18) was NOT SUCCESSFULLY logged on sentry.io
  • 1x exception with 41/0 ZeroDivisionError exception (line 31) was SUCCESSFULLY logged on sentry.io
pythontest_thread_mvp.py
[sentry] DEBUG: Settingupintegrations (withdefault=True)
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.django.DjangoIntegration: Djangonotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.flask.FlaskIntegration: Flaskisnotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.bottle.BottleIntegration: Bottlenotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.falcon.FalconIntegration: Falconnotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.sanic.SanicIntegration: Sanicnotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.celery.CeleryIntegration: Celerynotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.rq.RqIntegration: RQnotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.aiohttp.AioHttpIntegration: AIOHTTPnotinstalled
[sentry] DEBUG: Didnotimportdefaultintegrationsentry_sdk.integrations.tornado.TornadoIntegration: Tornadonotinstalled
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationthreading
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationlogging
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationstdlib
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationexcepthook
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationdedupe
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationatexit
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationmodules
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationargv
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationsqlalchemy
[sentry] DEBUG: Settinguppreviouslynotenabledintegrationboto3
[sentry] DEBUG: Enablingintegrationthreading
[sentry] DEBUG: Enablingintegrationlogging
[sentry] DEBUG: Enablingintegrationstdlib
[sentry] DEBUG: Enablingintegrationexcepthook
[sentry] DEBUG: Enablingintegrationdedupe
[sentry] DEBUG: Enablingintegrationatexit
[sentry] DEBUG: Enablingintegrationmodules
[sentry] DEBUG: Enablingintegrationargv
[sentry] DEBUG: Enablingintegrationsqlalchemy
[sentry] DEBUG: Enablingintegrationboto3tasktest0startedtasktest1startedtasktest2startedtasktest3startedtasktest4startedjobsfinished
[sentry] DEBUG: Sendingevent, type:nulllevel:infoevent_id:3d30670b8f134560bf7288091d72ada4project:7463834host:o3847193.ingest.sentry.ioTraceback (mostrecentcalllast):
File"/Users/z/test_thread_mvp.py", line31, in<module>41/0# this WILL log an exception on sentry.ioZeroDivisionError: divisionbyzero
[sentry] DEBUG: atexit: gotshutdownsignal
[sentry] DEBUG: atexit: shuttingdownclient
[sentry] DEBUG: FlushingHTTPtransport
[sentry] DEBUG: backgroundworkergotflushrequest
[sentry] DEBUG: 7event(s) pendingonflushSentryisattemptingtosend7pendingerrormessagesWaitingupto10secondsPressCtrl-Ctoquit
[sentry] DEBUG: [Tracing] Adding`sentry-trace`header573c7981bb724747a7b6a1c57ac1e9b4-8c262e380834b2b3-tooutgoingrequesttohttps://o3847193.ingest.sentry.io/api/7463834/store/.
[sentry] DEBUG: Sendingevent, type:nulllevel:infoevent_id:97fe1e03626c46e185372dbb78f30cc7project:7463834host:o3847193.ingest.sentry.io
[sentry] DEBUG: [Tracing] Adding`sentry-trace`header93b26a8d501c4837921f9dc45b12269a-917a82ad3ee8be4c-tooutgoingrequesttohttps://o3847193.ingest.sentry.io/api/7463834/store/.
[sentry] DEBUG: Sendingevent, type:nulllevel:infoevent_id:02b389a7eee749d4ad50f873369b06faproject:7463834host:o3847193.ingest.sentry.io
[sentry] DEBUG: [Tracing] Adding`sentry-trace`header0ebc6b346b7341088d9d8a3948913e5a-8d4701f59abbd49d-tooutgoingrequesttohttps://o3847193.ingest.sentry.io/api/7463834/store/.
[sentry] DEBUG: Sendingevent, type:nulllevel:infoevent_id:aa39d467ed5b4261a5507402660c8682project:7463834host:o3847193.ingest.sentry.io
[sentry] DEBUG: [Tracing] Adding`sentry-trace`headerdcdfdc9b20e14ae399b149e9c083a63b-8f0dcbf5cc377c87-tooutgoingrequesttohttps://o3847193.ingest.sentry.io/api/7463834/store/.
[sentry] DEBUG: Sendingevent, type:nulllevel:infoevent_id:fd9c63e42864441c92e301a0147efbcbproject:7463834host:o3847193.ingest.sentry.io
[sentry] DEBUG: [Tracing] Adding`sentry-trace`headera3f4e86d18e54a49b9c3dc7e0d5a2533-b89dd26b2502bec7-tooutgoingrequesttohttps://o3847193.ingest.sentry.io/api/7463834/store/.
[sentry] DEBUG: Sendingevent, type:nulllevel:errorevent_id:436508a757c6410688c28a975e1fd6c5project:7463834host:o3847193.ingest.sentry.io
[sentry] DEBUG: [Tracing] Adding`sentry-trace`header8c2203cb91fd480fb7abae703f271d81-a0dcba3c252e9470-tooutgoingrequesttohttps://o3847193.ingest.sentry.io/api/7463834/store/.
[sentry] DEBUG: backgroundworkerflushed
[sentry] DEBUG: KillingHTTPtransport
[sentry] DEBUG: backgroundworkergotkillrequest

Note that:

  • removing ThreadingIntegration didn't seem to affect the result
  • initialising sentry_dsk.init inside task doesn't seem to affect the result

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions