Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Not compatible with gevent #628

@aberres

Description

@aberres

Depending on the availability of the contextvars module either a _ThreadLocalRuntimeContext or a _AsyncRuntimeContext is created. The former uses threading.local while the latter uses contextvars.ContextVar to store data.

gevent only supports threading.local properly. The contexts are not switched when contextvars.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 if contextvars are available. An implementation could be heavily inspired by this one: elastic/apm-agent-python@090b938

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions