[RFC] Update Flask plugin to allow existing Tracer instance re-use #726
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.
Background, Details
Right now Flask middleware / plugin creates new Tracer instance for each request.
This it not great when you are using the same tracer singleton instance across the whole application / service and when using other plugins (such as https://github.com/census-instrumentation/opencensus-python/blob/master/contrib/opencensus-ext-google-cloud-clientlibs/) which allow you to specify which tracer instance to use (e.g. using
config_integration.trace_integrations([...], tracer=my_singleton_tracer_instance)
).Because existing singleton tracer instance can't re re-used, this means libraries and code which use singleton tracer instance can't be part of the root span created by the Flask middleware.
Before my change:
As you can see, span created by
opencensus-ext-google-cloud-clientlibs
which uses application / service global Tracer instance is not part of the request span (but I want it to be).After my change:
I pass existing singleton tracer instance to Flask middleware and as such, span is correctly part of the root request span,
Proposed Solution
To solve for that, I propose adding new optional
tracer
argument to the constructor.When this argument is provided, sampler, exporter and propagator arguments are redundant and mutually exclusive (if agreed on this approach, I can update docs and code to throw if mutually exclusive arguments are provided).
TODO