open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.67k stars 570 forks source link

`BatchSpanProcessor` triggers assertion error in `gevent` #3897

Open davidhewitt opened 2 months ago

davidhewitt commented 2 months ago

I'm getting an AssertionError when running the following code. It seems to be a combination of gevent + opentelemetry. Originally reported in https://github.com/pydantic/logfire/issues/63

Minimal reproduction:

import gevent.monkey

gevent.monkey.patch_all()

from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter

processor = BatchSpanProcessor(SpanExporter(), schedule_delay_millis=500)

# doing this import shows the error
import magic

Output looks like this:

$ python app.py
Traceback (most recent call last):
  File "src/gevent/_abstract_linkable.py", line 287, in gevent._gevent_c_abstract_linkable.AbstractLinkable._notify_links
  File "src/gevent/_abstract_linkable.py", line 333, in gevent._gevent_c_abstract_linkable.AbstractLinkable._notify_links
AssertionError: (None, <callback at 0x7f72a5936040 args=([],)>)
2024-05-01T14:26:07Z <callback at 0x7f72a5936040 args=([],)> failed with AssertionError

Environment:

dependencies:

Deprecated==1.2.14
gevent==24.2.1
greenlet==3.0.3
importlib-metadata==7.0.0
opentelemetry-api==1.24.0
opentelemetry-sdk==1.24.0
opentelemetry-semantic-conventions==0.45b0
python-magic==0.4.27
typing_extensions==4.11.0
wrapt==1.16.0
zipp==3.18.1
zope.event==5.0
zope.interface==6.3