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
We are excited to announce that Lightrun had partnered with Instana to enrich existing telemetry with real-time, code-level observability data and provide full-cycle Observability. Understanding everything that happens inside a production environment...
Engineering, Product
Our in-process data collectors, also known as "the tracers," collect a lot of span data across our customers' applications and services. And by a lot, we mean it. In September 2021, these...
Developer, Engineering, Product
The OpenTelemetry Collector is the central data collection mechanism for the OpenTelemetry project. We're going to focus on different angles in subsequent articles, but for now let's look at it more generally....

Start your FREE TRIAL today!

Instana, an IBM company, provides an Enterprise Observability Platform with automated application monitoring capabilities to businesses operating complex, modern, cloud-native applications no matter where they reside – on-premises or in public and private clouds, including mobile devices or IBM Z.

Control hybrid modern applications with Instana’s AI-powered discovery of deep contextual dependencies inside hybrid applications. Instana also gives visibility into development pipelines to help enable closed-loop DevOps automation.

This provides actionable feedback needed for clients as they to optimize application performance, enable innovation and mitigate risk, helping Dev+Ops add value and efficiency to software delivery pipelines while meeting their service and business level objectives.

For further information, please visit