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

fix(metrics): Fix metrics compatibility with greenlet/gevent #2756

Merged
merged 10 commits into from Feb 27, 2024

Conversation

sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Feb 22, 2024

Make metrics work with gevent (again) and play nicely with the rest of the SDK.

  • use the gevent-patched threading.Event instead of the original unpatched one to avoid greenlets waiting on the event blocking execution
  • use a greenlet (a patched threading.Thread) instead of a native thread for the flusher
  • don't support metrics on Python 3.6 and lower if gevent is used due to broken context vars

Mixing thread-based and greenlet-based primitives might lead to deadlocks in apps running in gevent mode.

Likely fixes #2748


General Notes

Thank you for contributing to sentry-python!

Please add tests to validate your changes, and lint your code using tox -e linters.

Running the test suite on your PR might require maintainer approval. Some tests (AWS Lambda) additionally require a maintainer to add a special label to run and will fail if the label is not present.

For maintainers

Sensitive test suites require maintainer review to ensure that tests do not compromise our secrets. This review must be repeated after any code revisions.

Before running sensitive test suites, please carefully check the PR. Then, apply the Trigger: tests using secrets label. The label will be removed after any code changes to enforce our policy requiring maintainers to review all code revisions before running sensitive tests.

@sentrivana sentrivana changed the title [WIP] Metrics & gevent [WIP] fix(metrics): Fix metrics compatibility with greenlet/gevent Feb 22, 2024
Comment on lines -250 to -255
# See http://www.gevent.org/install.html#older-versions-of-python
# for justification of the versions pinned below
py3.5-gevent: gevent==20.9.0
# See https://stackoverflow.com/questions/51496550/runtime-warning-greenlet-greenlet-size-changed
# for justification why greenlet is pinned here
py3.5-gevent: greenlet==0.4.17
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't actually run py3.5-gevent so we don't need this

@sentrivana sentrivana changed the title [WIP] fix(metrics): Fix metrics compatibility with greenlet/gevent fix(metrics): Fix metrics compatibility with greenlet/gevent Feb 26, 2024
@sentrivana sentrivana marked this pull request as ready for review February 26, 2024 10:50
Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

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

nice, way cleaner now! :shipit:

@sentrivana sentrivana merged commit fbc97ab into master Feb 27, 2024
123 checks passed
@sentrivana sentrivana deleted the ivana/gevent-metrics branch February 27, 2024 10:23
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.

Python metrics cause transaction duration changes
2 participants