Runtime context fails to detach token
See original GitHub issueDescribe your environment python 3.7 ujson sanic==20.9.1 opentelemetry-api==1.9.1 opentelemetry-sdk==1.9.1 opentelemetry-propagator-jaeger==1.9.1 opentelemetry-exporter-jaeger-thrift==1.9.1 opentelemetry-instrumentation==0.28b1 opentelemetry-exporter-otlp-proto-http==1.10.0
Steps to reproduce
i have used the opentelemetry-instrumentation to create a middleware for sanic web framework, this middleware allows to trace a request, all seems good but sometimes the error Failed to detach context comes randomly for some request.
What is the expected behavior?
instead of Failed to detach context error , original exception should be logged as exception so that the actual issue can be debugged with proper stacktrace etc.
opentelemetry-python/opentelemetry-api/src/opentelemetry/context/init.py line
here instead of
except Exception: # pylint: disable=broad-except
logger.error("Failed to detach context")
it should be
except Exception as e: # pylint: disable=broad-except
logger.error(e)
What is the actual behavior?
getting Failed to detach context error message instead of original message.
Additional context
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:19 (9 by maintainers)
Top Related StackOverflow Question
I have the same request. Maybe the code could also be changed to
Is a PR possible?
server: FastAPI (uvicorn with uvloop) database: Postgres (peewee + psycopg2)
Chiming in with yet another observed instance of this behavior. We’re instrumenting a FastAPI app and first started seeing this
Failed to detach contextexception when we tweaked our database connection generator from using thestart_as_current_span()decorator approach to instrumenting the method’s logic with awithblock (+ events). FWIW, this exception being raised does NOT appear to prevent spans from being delivered to our OTEL endpoint 🤷original method (does NOT cause the exception):
tweaked method (DOES cause the exception):
The original motivation for the instrumentation change was when we noticed that we weren’t getting full spans using the decorator approach, and we wanted to add some events around the method’s
yieldto help us understand database connection timing.Since trying out the tweaked method and observing this exception, we’ve tried a few different things: