Haystack bindings for Python OpenTracing API
This is Haystack's client library for Python that implements OpenTracing
Further information can be found on opentracing.io
Using this library
See examples in /examples directory. See opentracing usage for additional information.
It is important to consider the architecture of the application. In order for the tracer to manage spans properly, an appropriate
ScopeManager implementation must be chosen. In most environments, the default
ThreadLocalScopeManager will work just fine. In asynchronous frameworks, the
ContextVarsScopeManager is a better choice.
First initialize the tracer at the application level by supplying a service name and span recorder
import opentracing from haystack import HaystackAgentRecorder from haystack import HaystackTracer tracer = HaystackTracer("a_service", HaystackAgentRecorder()) opentracing.set_global_tracer(tracer)
Starting a span can be done as a managed resource using
with opentracing.tracer.start_active_span("span-name") as scope: do_stuff()
or finish the span on your own terms with
span = opentracing.tracer.start_span("span-name") do_stuff() span.finish()
Note: If there is a Scope, it will act as the parent to any newly started Span unless the programmer passes
start_span()/start_active_span() time or specified parent context explicitly using
Custom propagation headers
If necessary, default propagation headers can be replaced with custom ones by specifying custom propagator options. Register the new propagator with the tracer once configured.
prop_opts = PropagatorOpts("X-Trace-ID", "X-Span-ID", "X-Parent-Span", "X-baggage-") opentracing.tracer.register_propagator(opentracing.Format.HTTP_HEADERS, TextPropagator(prop_opts))
All modules define their logger via
So in order to define specific logging format or level for this library use
getLogger('haystack') or configure the
How to configure build environment
Create a python3 virtual environment, activate it and then
Running the example code
How to Release this library
Create a new release in github specifying a semver compliant tag greater than the current release version.