Python OpenTracing


OpenTracing provides "Vendor-neutral APIs and instrumentation for distributed tracing". If you're not familiar with OpenTracing, see the OpenTracing portal for more details.

Existing applications that utilize the OpenTracing API or those who wish to add support can easily integrate with this Python package.

This Python package supports OpenTracing. When using this package, the OpenTracing tracer (opentracing.tracer) is automatically set to the InstanaTracer.

For best results when utilizing OpenTracing, also take note of our best practices outlined in this OpenTracing page.


import opentracing

with opentracing.tracer.start_active_span('asteroid 💫') as pscope:
    pscope.span.set_tag(ext.COMPONENT, "Python simple example app")
    pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER)
    pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
    pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one")
    pscope.span.set_tag(ext.HTTP_METHOD, "GET")
    pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
    pscope.span.log_kv({"foo": "bar"})
    # ... work ...

    with opentracing.tracer.start_active_span('spacedust 🌚', child_of=pscope.span) as cscope:
        cscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT)
        cscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
        cscope.span.set_tag(ext.HTTP_URL, "/python/simple/two")
        cscope.span.set_tag(ext.HTTP_METHOD, "POST")
        cscope.span.set_tag(ext.HTTP_STATUS_CODE, 204)
        cscope.span.set_baggage_item("someBaggage", "someValue")
        # ... work ...

See Also