temporalio / samples-python

Samples for working with the Temporal Python SDK
MIT License
120 stars 53 forks source link

feat: add example using Sentry V2 SDK #140

Open gregbrowndev opened 4 weeks ago

gregbrowndev commented 4 weeks ago

What was changed

Added a new example to set up Sentry using the V2 SDK.

Why?

After recently trying to set up Sentry, the existing example that uses Sentry's V1 SDK doesn't work for me. The issue seems to be related to the warnings and threading modules that Sentry uses not being appropriately included in the Temporal Workflow's sandbox. This results in the Workflow execution failing to start in the worker that handles the Workflow. I don't see any issues with the Sentry interceptor on other workers that only handle activities, so it seems the problem is related to the Workflow sandbox.

Note: I also tried disabling the worker's sandbox, which seemed to get further. The workflow is able to start and eventually finish, but you get a sporadic error in the workflow's event history.

The solution is to migrate the interceptor to use V2 of Sentry's SDK, where the Hub object is now deprecated in favour of using scopes. Using the scope context manager doesn't seem to have the same issues with the warnings and threading libs (which it still uses).

I've created a new example to keep the V1 example in place, since V2 only works with Python 3.6 or above.

Checklist

  1. Closes

https://temporalio.slack.com/archives/CTT84RS0P/p1725394300914329

  1. How was this tested:

Tested manually in my application using Sentry.io

  1. Any docs updates needed?

Added a new example with a README explaining the reasons/difference between the original example and the v2 example.

CLAassistant commented 4 weeks ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.