Docs » µAPM Instrumentation Guide » Python Instrumentation

Python Instrumentation

Important

Before you start instrumenting your applications, review the information in Instrumentation Overview.

The OpenTracing API Contributions community has provided tracing instrumentation utilities and wrappers for a growing number of popular Python web frameworks, web clients, and database drivers. In order to make use of these instrumentations, it’s been the case that you need to replace your core route handler registrations and client initializations with their tracing equivalents throughout your applications. This can become a burdensome task for cross-team deployments, where service owners and instrumentors don’t share memberships, or when legacy components are currently without SMEs. Fortunately, SignalFx provides a helpful library for auto-instrumenting your applications: SignalFx-Tracing for Python.

In many cases, if direct code modification is not easily feasible, the SignalFx Tracing utility for Python provides an application runner that will automatically replace all instrumentable client and application instances with their tracing versions:

$ SIGNALFX_ACCESS_TOKEN=<MyAccessToken> sfx-py-trace my_application.py --app_arg_one --app_arg_two

If application startup logic is modifiable by the instrumenting team, easy OpenTracing-compatible tracer creation and auto-instrumentation are made possible with a series of helper functions:

from signalfx_tracing import auto_instrument, create_tracer, trace

tracer = create_tracer('<MyAccessToken>', service_name='MyTracedApplication')
auto_instrument(tracer)

@trace
def my_function():
    return 'Traced!'

@trace('MyOperationName')
def my_other_function():
    return my_function()

Currently the following libraries are provided with auto-instrumentation:

Library Supported Versions
Django 1.8+
Flask 0.10+
Psycopg 2.7+
PyMongo 3.1+
PyMySQL 0.8+
Redis-Py 2.10
Requests 2.0+
Tornado 4.3+

For detailed, library-specific instrumentation instructions and examples, please see the utility’s documentation.