Open aberres opened 5 years ago
Interestingly the issue only surfaces with the
gunicorn
sync worker but not withguicorn
gevent
workers orflask run
.
I see this exact same behavior: The requests
integration traces correctly when I run my service locally using flask run
, but it does not trace when the deployment is running gunicorn
.
@IamJeffG If you want a quick workaround the following helps after setting up the AsyncTransport
import opencensus.common.runtime_context as runtime_context
runtime_context.RuntimeContext.is_exporter = False
If "fixes" the current thread but does not affect the already forked exporter thread.
I was planning to provide a pull request for this issue but did not yet find the time.
Issue description
I stumbled upon this bug when trying to use the
requests
integration in combination with synchronous gunicorn workers.After a lot of head scratching I noticed that the
call
function insideopencensus.ext.requests.trace.wrap_requests
always runs into this branch:The function thinks uns in the context of ann exporter thread - but it does not.
Further investigation revealed that the appearance of the bug it is related to asynchronous transports. See the following minimal snippet which can be executed as is:
The assertion in the last line always fails when an AsyncTransport is used.
Checking
opencensus.common.transports.async_._Worker.start
reveals thatopencensus.trace.execution_context.set_is_exporter
is called in the main thread, not in the to be started one.I guess the simple solution is to move the call into
opencensus.common.transports.async_._Worker._thread_main
.Additional information
Interestingly the issue only surfaces with the
gunicorn
sync worker but not withguicorn
gevent
workers orflask run
. Does not really make sense to me, but I had no time to further investigate yet.Used versions