Skip to content

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

Merged
sentrivana merged 10 commits intomasterfrom
ivana/gevent-metrics
Feb 27, 2024
Merged

fix(metrics): Fix metrics compatibility with greenlet/gevent#2756
sentrivana merged 10 commits intomasterfrom
ivana/gevent-metrics

Conversation

@sentrivana
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

@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
@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