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 9 commits into
base: main
Choose a base branch
from

Conversation

gregbrowndev
Copy link

@gregbrowndev gregbrowndev commented Sep 7, 2024

What was changed

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

Why?

The original Sentry integration only works with Sentry SDK v1, due to issues with the warnings and threading modules that Sentry uses not being appropriately included in the Temporal Workflow's sandbox when SDK v2 is installed. (Presumably, Sentry SDK v2 made some internal changes, so these modules are now causing issues.)

Given that v1 is now deprecated and that v2 will be installed by default if the user runs poetry add sentry-sdk in their own project, this new sample provides the required integration for Sentry SDK v2 to work without sandbox issues.

The necessary changes only required migrating the use of the Hub object (which is now deprecated) to using Sentry scopes.

The original Sentry v1 sample is kept as the SDK still receives security patches and is not yet EOL.

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.

Copy link
Author

Choose a reason for hiding this comment

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

@cretz I renamed sentry -> sentry_v1 and kept sentry_v2 as is, so the commit history doesn't get skewed for the original impl. Let me know if you'd prefer to make sentry_v2 -> sentry.

Copy link
Member

Choose a reason for hiding this comment

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

Does Sentry still support v1? If it is EOL, maybe we should consider it EOL too.

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

Copy link
Author

Choose a reason for hiding this comment

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

@cretz I've removed and reworded both the readme's in the sample.

Btw, you cannot have two different poetry groups containing the same package with different versions. Previously, I added a constraint on Python, so SDK v1 was installed for Python<3.6 and SDK v2 for Python>=3.6. However, since the samples project uses Python 3.10 (and the Temporal SDK only supports 3.8 and higher), I think this hack would confuse users, as it would always install SDK v2 and the original sample wouldn't work as expected.

I've updated the V1 README to require the user to install sentry-sdk==1.11.0 with pip rather than using poetry.

Copy link
Member

Choose a reason for hiding this comment

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

you cannot have two different poetry groups containing the same package with different versions

Ug, that is unfortunate. I do still think we should have the Poetry groups named after the sample they represent, even if it's a dupe for sentry_v1 and sentry_v2 (or there isn't even a sentry_v1 group at all and pip install is manual). This also may give more credence to the approach of making sentry_v2 just sentry.

Copy link
Author

Choose a reason for hiding this comment

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

I've asked on the Sentry's discussion board what the timeline is for v1 support. Will get back once they provide an answer.

One idea would be to just replace the v1 impl. with the new v2 integration, keep the example called sentry, and then add a link in the README to the original v1 commit for posterity?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that would work well. Either way I think we want this to be the primary sentry sample since we have to have the dependency group named that.

- Renamed sentry sample to sentry_v1 until it reaches EOL
- Clarified readme for both samples
@gregbrowndev gregbrowndev requested a review from cretz November 14, 2024 12:56
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Looks great. May need a formatting run to pass CI.

@gregbrowndev gregbrowndev requested a review from cretz November 19, 2024 11:26
@gregbrowndev
Copy link
Author

@cretz just a note on Sentry SDK v1 EOL:

v1 is now only receiving security patches and we will likely EOL it with the release of v3 of the SDK, which is coming in the next few months.
link

@cretz
Copy link
Member

cretz commented Nov 19, 2024

Uh oh, v3 so soon? Ok, I guess we will cross that bridge when we get there. Otherwise, I think this looks good and I'll merge if/when CI passes. The purpose is to serve as a sample, so users can adapt it as they need for their version of tooling.

@gregbrowndev
Copy link
Author

Hey @cretz, do you want me to rebase the PR?

@cretz
Copy link
Member

cretz commented Dec 2, 2024

@gregbrowndev - I just merged main into your branch, no problem. Looks like just the CLA needs to be signed (see link above pointing to https://cla-assistant.io/temporalio/samples-python?pullRequest=140). May need to make a comment here when done so I can get notified to merge this.

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