You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe your environment
python 3.11
Flask==3.0.3
opentelemetry-distro==0.45b0
Steps to reproduce
import unittest
from flask import Flask
from app import app as flask_app # Replace 'your_flask_app' with the actual name of your flask app file
Implement the simple opentelemetry getting started Flask app:
fromrandomimportrandintfromflaskimportFlask, requestimportloggingapp=Flask(__name__)
logging.basicConfig(level=logging.INFO)
logger=logging.getLogger(__name__)
@app.route("/rolldice")defroll_dice():
player=request.args.get('player', default=None, type=str)
result=str(roll())
ifplayer:
logger.warning("%s is rolling the dice: %s", player, result)
else:
logger.warning("Anonymous player is rolling the dice: %s", result)
returnresultdefroll():
returnrandint(1, 6)
What is the expected behavior?
I expected the test to pass without any exception logging to the console. Even though it might not be typical to use opentelemetry when running unit tests, I'd still expect it to work without noisy error messages.
What is the actual behavior?
The test does pass, but it outputs noisy error messages.
ERROR:opentelemetry.context:Failed to detach context
Traceback (most recent call last):
File "/Users/brianmcdonnell/src/otel-getting-started/venv/lib/python3.11/site-packages/opentelemetry/context/__init__.py", line 163, in detach
_RUNTIME_CONTEXT.detach(token) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/brianmcdonnell/src/otel-getting-started/venv/lib/python3.11/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
self._current_context.reset(token) # type: egnore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: <Token used var=<ContextVar name='current_context' default={} at 0x106b1b830> at 0x107b8e980> has already been used once
Additional context
This only happens when calling the test client from inside a with block. When the with block exits it tears down the context and logs this error. It appears that the opentelemetry Flask integration has already detached its context immediately after the request completed.
The text was updated successfully, but these errors were encountered:
Describe your environment
python 3.11
Flask==3.0.3
opentelemetry-distro==0.45b0
Steps to reproduce
import unittest
from flask import Flask
from app import app as flask_app # Replace 'your_flask_app' with the actual name of your flask app file
Implement the simple opentelemetry getting started Flask app:
Write a test for it, and run the test.
What is the expected behavior?
I expected the test to pass without any exception logging to the console. Even though it might not be typical to use opentelemetry when running unit tests, I'd still expect it to work without noisy error messages.
What is the actual behavior?
The test does pass, but it outputs noisy error messages.
Additional context
This only happens when calling the test client from inside a
with
block. When thewith
block exits it tears down the context and logs this error. It appears that the opentelemetry Flask integration has already detached its context immediately after the request completed.The text was updated successfully, but these errors were encountered: