opencensus-python icon indicating copy to clipboard operation
opencensus-python copied to clipboard

[RFC] Update Flask plugin to allow existing Tracer instance re-use

Open Kami opened this issue 6 years ago • 3 comments

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:

Screenshot from 2019-07-23 23-00-56

Screenshot from 2019-07-23 23-08-03

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:

Screenshot from 2019-07-23 23-00-43

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

  • [x] Update docs
  • [x] Add tests
  • [x] Update code to throw if mutually exclusive arguments are provided

Kami avatar Jul 23 '19 21:07 Kami

This looks like a good solution to me too pending the TODOs in the description.

c24t avatar Jul 24 '19 00:07 c24t

I pushed a change which adds docstring, test cases and throws inside a constructor if mutually exclusive arguments are provided.

I believe the tests / cover target should pass now.

Kami avatar Jul 24 '19 07:07 Kami

@Kami would you help to update the CHANGELOG.md file given this is an interface change? FYI - we plan to release around end of this month.

reyang avatar Jul 24 '19 14:07 reyang