This repository has been archived by the owner on May 23, 2023. It is now read-only.
Add ability to specify parent span in tracer_span_context in TornadoScopeManager #126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some time ago I faced with problem of tracing fire & forget coroutines in Tornado.
As documentation says, we must run such coroutines in
tracer_stack_context
to prevent breaking of original scope:Based on tornado's
StackContext
, that actually proto-contextvars,tracer_stack_context
make new isolated scope for coroutines and this mechanism works well.But
tracer_stack_context
doesn't provide a way to setup active span in this new scope. If you want to make span propagation for fire & forget coroutines, you have to pass and activate your (current) span explicitly in the couroutine. It can be difficult and complicates code instrumentation.For example, my first (and ugly) iteration of wrapper for fire & forget coroutines that we successfully use in one of our microservice https://github.com/condorcet/tornado-coroutines-opentracing/blob/master/tornado_coroutines_opentracing/__init__.py#L15
The same problem with scheduling callbacks/futures in event loop -- there is no easy way to make auto-propagation of current span to them.
In the PR
tracer_stack_context
has new optional argumentparent_span
that specify span that will be used in new scope prepared by stack context.I think it can make auto-propagation easier for Tornado applications.
For example my second iteration of wrapper based on it: https://github.com/condorcet/tornado-coroutines-opentracing/blob/072a9d65f0e49eaf63fb3aff93b1090f06a4a7b3/tornado_coroutines_opentracing/__init__.py#L33