honeycombio / beeline-python

Legacy instrumentation for your Python apps with Honeycomb.
Apache License 2.0
33 stars 39 forks source link

`flask.signals` has no attribute `signals_available` #300

Closed sosaedison closed 1 day ago

sosaedison commented 2 months ago

When initializing the HoneyMiddleware in a Flask application, we get the following error:

Traceback (most recent call last):
         |   File "<frozen runpy>", line 198, in _run_module_as_main
         |   File "<frozen runpy>", line 88, in _run_code
         |   File "/opt/venv/lib/python3.11/site-packages/debugpy/__main__.py", line 71, in <module>
         |     cli.main()
         |   File "/opt/venv/lib/python3.11/site-packages/debugpy/server/cli.py", line 501, in main
         |     run()
         |   File "/opt/venv/lib/python3.11/site-packages/debugpy/server/cli.py", line 384, in run_module
         |     run_module_as_main(options.target, alter_argv=True)
         |   File "/opt/venv/lib/python3.11/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 238, in _run_module_as_main
         |     return _run_code(code, main_globals, None,
         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
         |     exec(code, run_globals)
         |   File "/opt/venv/lib/python3.11/site-packages/flask/__main__.py", line 3, in <module>
         |     main()
         |   File "/opt/venv/lib/python3.11/site-packages/flask/cli.py", line 1105, in main
         |     cli.main()
         |   File "/opt/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
         |     rv = self.invoke(ctx)
         |          ^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
         |     return _process_result(sub_ctx.command.invoke(sub_ctx))
         |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
         |     return ctx.invoke(self.callback, **ctx.params)
         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
         |     return __callback(*args, **kwargs)
         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/click/decorators.py", line 92, in new_func
         |     return ctx.invoke(f, obj, *args, **kwargs)
         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
         |     return __callback(*args, **kwargs)
         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/flask/cli.py", line 953, in run_command
         |     raise e from None
         |   File "/opt/venv/lib/python3.11/site-packages/flask/cli.py", line 937, in run_command
         |     app: WSGIApplication = info.load_app()
         |                            ^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/flask/cli.py", line 335, in load_app
         |     app = locate_app(import_name, name)
         |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |   File "/opt/venv/lib/python3.11/site-packages/flask/cli.py", line 245, in locate_app
         |     __import__(module_name)
         |   File "/home/user/app/app.py", line 17, in <module>
         |     app = make_app()
         |           ^^^^^^^^^^
         |   File "/home/user/app/make_app.py", line 54, in make_app
         |     Honeycomb().init_app(app)
         |   File "/home/user/app/monitoring/monitoring.py", line 51, in init_app
         |     HoneyMiddleware(app, db_events=False)
         |   File "/opt/venv/lib/python3.11/site-packages/beeline/middleware/flask/__init__.py", line 18, in __init__
         |     if signals.signals_available:
         |        ^^^^^^^^^^^^^^^^^^^^^^^^^
         | AttributeError: module 'flask.signals' has no attribute 'signals_available'

Versions

Steps to reproduce

  1. Create a requirements.txt file with these packages:

    honeycomb-beeline==3.6.0
    Flask==3.0.3
  2. Install the packages above:

    • python3.11 -m venv .venv
    • source .venv/bin/activate
    • pip install -r requirements.txt
  3. Create app.py file and copy-paste the code below

    
    import os
    import beeline
    from flask import Flask
    from beeline.middleware.flask import HoneyMiddleware
    from dotenv import load_dotenv

load_dotenv()

flask_app = Flask(name)

def beeline_init(flask_app): API_KEY = os.getenv("BEELINE_API_KEY") DATASET = os.getenv("BEELINE_DATASET")

beeline.init(
    writekey=API_KEY,
    dataset=DATASET,
    service_name="Test App",
)
HoneyMiddleware(flask_app, db_events=False)

if name == "main": beeline_init(flask_app) flask_app.run()


4. Run the file with `python3 app.py`
VinozzZ commented 2 months ago

It looks like this attribute is removed since Flask 2.4. Did this error occur after an upgrade of Flask or a newly instrumented application? If this is a new instrumentation, we recommend you to use opentelemetry instead

MikeGoldsmith commented 1 day ago

Closing for now, please re-open if you're still experiencing this issue.