Skip to main content

OpenTracing support for Elasticsearch

Project description

This package enables distributed tracing for the Python elasticsearch-py and elasticsearch-dsl libraries.


Run the following command:

$ pip install elasticsearch_opentracing

Getting started

Please see the examples directory. Overall, usage requires that a tracer gets set, and initialize the Elasticsearch client specifying TracingTransport as tracing class, and optionally set an active span (to be used as parent span when tracing the actual Elasticsearch statements):

import elasticsearch_opentracing

elasticsearch_opentracing.init_tracing(tracer) # An OpenTracing compatible tracer.
es = Elasticsearch(transport_class=elasticsearch_opentracing.TracingTransport)

elasticsearch_opentracing.set_active_span(main_span) # Optional.

es.index(index='test-index', doc_type='tweet', id=99, body={
    'author': 'linus',
    'text': 'Hello there',
res = es.get(index='test-index', doc_type='tweet', id=99)


By default, all Elasticsearch requests are traced. It’s possible to have it set to false when initializing the library, and call enable_tracing and disable_tracing to explicitly trace statements happening within that section:

elasticsearch_opentracing.init_tracing(tracer, trace_all_requests=False)


res1 = es.get(index='test-index', doc_type='tweet', id=99)
res2 = es.get(index='test-index', doc_type='user', id=666)


When using trace_all_requests, any calls made to enable_tracing and disable_tracing are ignored.

In case of an exception happening under this block, an implicit call to disable_tracing will take place, with the request causing the error including error information with it.


Tracing and parent span data is kept as thread local data, which means that applications using many threads (Django, Flask, Pyramid, etc) will work just fine.

Further information

If you’re interested in learning more about the OpenTracing standard, please visit or join the mailing list. If you would like to implement OpenTracing in your project and need help, feel free to send us a note at

Project details

Download files

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

Files for elasticsearch-opentracing, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size elasticsearch_opentracing-0.1.1.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page