Skip to main content

Haystack Python OpenTracing Implementation

Project description

Build Status License

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 start_active_span()

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 ignore_active_span=True at start_span()/start_active_span() time or specified parent context explicitly using childOf=parent_context

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))

Logging

All modules define their logger via logging.getLogger(__name__)

So in order to define specific logging format or level for this library use getLogger('haystack') or configure the root logger.

How to configure build environment

Create a python3 virtual environment, activate it and then make bootstrap

Running the example code

make example

How to Release this library

Create a new release in github specifying a semver compliant tag greater than the current release version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haystack-client-0.2.4.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

haystack_client-0.2.4-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file haystack-client-0.2.4.tar.gz.

File metadata

  • Download URL: haystack-client-0.2.4.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for haystack-client-0.2.4.tar.gz
Algorithm Hash digest
SHA256 bd58f42ac102957ca2e0f41c2b04654abd7ddb6737a33d0b4b7c59360ade6405
MD5 3ce5b0fd6d9730ceaba7efa1bb543724
BLAKE2b-256 029a9dfbe848b473ba10478c636f76f88a3039f558311adfd029f836a02b39dc

See more details on using hashes here.

File details

Details for the file haystack_client-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: haystack_client-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for haystack_client-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3ac1088c98476ba4f36581374e9c5b66ef2167c7cdf73c409b1dfccba1d4faf3
MD5 7d0ad12dfe454ce40cdd5c0d373c1c36
BLAKE2b-256 076849fed7aee918236199e509080469e5af89992c19ca59c69e2ca5895b330b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page