Skip to content

Commit

Permalink
fix: Prevent crash with 'gevent' has no attribute 'version_info'
Browse files Browse the repository at this point in the history
If the `gevent` module is not installed,
but there is a directory called `gevent`
or a `gevent.py` file in the current directory,
then that is already importable and the statment
`if sys.modules['gevent'].version_info < (1, 4):`
fails with
`AttributeError: module 'gevent' has no attribute 'version_info'`

This can happen easily since many libraries like `celery`, `grpc`, `opentracing` etc,
deliver their own file called `gevent.py`.

Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
  • Loading branch information
Ferenc- committed Jun 12, 2024
1 parent 022050e commit 9006c03
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/instana/instrumentation/gevent_inst.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ def spawn_callback(new_greenlet):
logger.debug("instrument_gevent: ", exc_info=True)


if 'gevent' in sys.modules:
if sys.modules['gevent'].version_info < (1, 4):
logger.debug("gevent < 1.4 detected. The Instana package supports gevent versions 1.4 and greater.")
else:
instrument_gevent()
else:
if not 'gevent' in sys.modules:
logger.debug("Instrumenting gevent: gevent not detected or loaded. Nothing done.")
elif not hasattr(sys.modules['gevent'], 'version_info'):
logger.debug("gevent module has no 'version_info'. Skipping instrumentation.")
elif sys.modules['gevent'].version_info < (1, 4):
logger.debug("gevent < 1.4 detected. The Instana package supports gevent versions 1.4 and greater.")
else:
instrument_gevent()

0 comments on commit 9006c03

Please sign in to comment.