-
Notifications
You must be signed in to change notification settings - Fork 250
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
Not compatible with gevent #628
Comments
Thanks for raising the issue @aberres. We've got the same problem with other event-loop-based frameworks. E.g., we'd have to use One problem is that we might have competing threading models: suppose we force If we do want to make using threadlocals a configurable option, one solution may be to let integrations swap out the storage for @reyang may have some insight on the design of the context API here. |
Thanks for sharing the findings @aberres! "Trying to detect if running under gevent and then using Eventually Would love to hear your idea on what the explicit way should look like. Probably some environment variable, or OPENCENSUS global settings? (I'm a bit concerned about swapping context at runtime, as there could be context creation done before the point we start to swap things) |
At least from a gevent POV this should not be a problem. To properly setup gevent one should patch all used libraries before loading/using them for the first time. An example is using the gunicorn gevent worker and doing any needed preparation in a |
@aberres would the following code work?
|
@reyang Yes, this works. I created a pull request to add some lines to the documentation instead of doing any code changes. |
Closed with #636 |
Maybe I will create a new issue but:
With
And a setup like:
it does not seems to trace properly when
|
Depending on the availability of the
contextvars
module either a_ThreadLocalRuntimeContext
or a_AsyncRuntimeContext
is created. The former usesthreading.local
while the latter usescontextvars.ContextVar
to store data.gevent only supports
threading.local
properly. The contexts are not switched whencontextvars.ContextVar
is used. This results in side effects when requests are executed in parallel.An extended writeup can be found in this issue: elastic/apm-agent-python#451
A solution to this problem is to try to detect if running under gevent and then using
_ThreadLocalRuntimeContext
even ifcontextvars
are available. An implementation could be heavily inspired by this one: elastic/apm-agent-python@090b938The text was updated successfully, but these errors were encountered: