Python Application Monitoring, Automatic Tracing and OpenTracing

September 3, 2018


Instana’s Python Monitoring includes automatic end-to-end tracing of all user requests. It’s the easiest and fastest way to get the detailed traces necessary to find and fix problems. With that said, though, we recognize that sometimes, developers have a need to use other tracing methods, such as OpenTracing (that’s just one of the reasons that Instana participates as a member of the OpenTracing Specification Council).

Maybe you saw our recent announcement about Application Perspectives and Personalized APM. Along with those leading edge features, we also released support in our Python Monitoring sensor for OpenTracing 2.0. There are quite a few changes with this new version of the OpenTracing API, so you might have to refactor any of your code using the previous versions of the OpenTracing API.

Instana’s Python sensor supports many popular frameworks for entry and exit points – Monitoring Python documentation has the complete list. All supported frameworks are automatically instrumented without requiring any code changes. All you have to do is install the instana package into your virtualenv or container.

$ pip install instana

Alternatively add it to your requirements.txt file (the example below is for Flask).

$ pip install -r requirements.txt
$ python

That’s it!

Instana will now monitor the Python runtime and trace all requests end-to-end. This simple change is easily accommodated into the Dockerfile or startup script of your Python applications.

OpenTracing API 2.0 in Instana’s Python Sensor

With the standard entry and exit points taken care of automatically by Instana’s Python sensor, you may optionally want to shed some light on some critical code between those points, this is where you can use the OpenTracing API. Installing the Instana package as shown above also includes the OpenTracing package. The code snippet below shows how you can easily insert a custom span to provide additional detail.

import opentracing as ot
import opentracing.ext.tags as tags

# This entry point will be automatically instrumented
@app.route(‘/foo’, methods=[‘GET’])
def foo():
# Some regular code
# e.g. requests call

# Start a new span
with ot.tracer.start_active_span(’mystuff’) as scope:
scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KING_RPC_CLIENT)
scope.span.set_tag(tags.COMPONENT, ‘python foo’)
scope.span.set_tag(‘version’, ‘4.2.0’)
‘Txnid’: ‘foobar’

# interesting bit 😉

return ‘OK’

The above code snippet (full example gist) produces a trace in the Instana UI similar to the one below.

python trace

Best of Both Worlds

Instana’s automatic Python tracing takes care of all the mundane instrumentation leaving your developers more time to concentrate on coding core functionality, while also providing the flexibility to dig deeper if required.

Don’t slow down, let the robot do the work.

Play with Instana’s APM Observability Sandbox

Announcement, Developer, Product, Thought Leadership
Instana has previously announced automated tracing of AWS Lambda applications in Node.js and Python. We are extending our best-in-class distributed tracing to include AWS Lambda functions written in Java and Go. The...
Announcement, Developer, Product, Thought Leadership
To be successful in Observability, you must have the ability to observe the behavior of a system and derive its health state from it. But deriving the health state of any given...
Announcement, Conceptual, Product
.NET 5 is finally here, released at .NET Conf 2020. .NET 5 was so highly anticipated that we already have a few Instana users deploying the .NET 5 Preview Releases in production,...

Start your FREE TRIAL today!

As the leading provider of Automatic Application Performance Monitoring (APM) solutions for microservices, Instana has developed the automatic monitoring and AI-based analysis DevOps needs to manage the performance of modern applications. Instana is the only APM solution that automatically discovers, maps and visualizes microservice applications without continuous additional engineering. Customers using Instana achieve operational excellence and deliver better software faster. Visit to learn more.