Skip to content

Instantly share code, notes, and snippets.

@carlosalberto
Last active June 18, 2018 16:56
Show Gist options
  • Save carlosalberto/d49fe6ce785d23639d55c2dc004a3f0c to your computer and use it in GitHub Desktop.
Save carlosalberto/d49fe6ce785d23639d55c2dc004a3f0c to your computer and use it in GitHub Desktop.

Notes on Python Instrumentation with OT 2.0 API

As fo now https://github.com/carlosalberto/opentracing-python-instrumentation/tree/ot_scopemanager_integration points out to a basic, initial support for the OT 2.0 API (namely: Scopes integration). Think of it more of a prototype.

The changes consist mainly of:

  • Using a single, global TornadoScopeManager instance for doing the activation of both single-threaded and Tornado based activation (span_in_context() and span_in_stack_context()). This is possible as the mentioned ScopeManager stores the Scope/Span through a StackContext, if any is detected, or else in a TLS field (which is similar to what opentracing-python-instrumentation does at the moment.

  • For doing the span_in_context() part, a simple Scope is returned, which exposes a span property, just as the original RequestContext does.

  • For doing the span_in_stack_context() part, we enter a tracer_stack_context() (used to create a 'storage' for any active Span at the moment), activate the passed Span and return such context (and any further call down the call could ScopeManager's methods, as any TornadoScopeManager instances references any current context).

Notes:

  • Removed ThreadSafeStackContext as it's not used anymore (from here) - did not remove RequestContext nor RequestContextManager as they are still used/checked by the tests. Could be removed afterwards, doing a clean up.

  • We could probably add some stuff for better integration witht the OT 2.0 API (i.e. get_current_span() could take an optional scope_manager parameter to use any manager other than the global-default one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment