Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add example using Sentry V2 SDK #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gregbrowndev
Copy link

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.

Notes: The V1 example doesn't seem to work for me after recently trying
to set up Sentry. The issue seems to be related to the `warnings` and
`threading` modules that Sentry uses not being included properly into
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 is definitely related to the Workflow sandbox.

Note: I also tried disabling the worker's sandbox and this seemed to work,
even though you get a sporadic error in the Temporal UI.

The solution seems to be to migrate the interceptor to use V2 of Sentry's
SDK, where the Hub object is now deprecated in favour of using scopes.

It seems that using the scope context manager doesn't have the same issues
with the warnings and threading libs (which it does still use).

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

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.

Comment on lines +5 to +7
Note: This is a small modification of the original example [sentry (v1)](../sentry) which seems to have
issues in the Workflow interceptor, as there are modules (`warnings` and `threading`) that Sentry uses that aren't passed through
to Temporal's sandbox properly, causing the Workflows to fail to execute.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Sentry V1 doesn't work anymore, let's replace the sample instead of adding a new one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cretz - I haven't been able to test this, but I suspect now the example didn't work for me because when I installed sentry-sdk, it will have defaulted to the latest version (V2), but the example only works with V1. I imagine if you pin the version to the one in the example, it might work.

It does look like development on the V1 SDK has stopped now (last feature release was in April with a security patch in July).

So, I will let you decide if we should replace the V1 example. I'll update the PR as necessary.

Copy link
Member

@cretz cretz Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmm, assuming the current sentry works, how about we just move the current one to sentry_v1 and make yours just sentry? So change the dirs and the dependency group name and the top-level README and such. Then we can come back and delete sentry_v1 later when they officially EOL it.

issues in the Workflow interceptor, as there are modules (`warnings` and `threading`) that Sentry uses that aren't passed through
to Temporal's sandbox properly, causing the Workflows to fail to execute.

> Sentry V2 only supports Python 3.6 and higher. So if you're on Python 3.5, you may need to refer to the original example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporal Python SDK only supports 3.8 or higher, so this disclaimer is not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants