Documentation forAppOptics

Install the Python Agent

The Python Agent is delivered as a module named appoptics_apm that provides middleware for common frameworks. Download the module, import it into your Python application, and get visibility.

Dependencies

The agent compiles an extension during install, thus you'll need to have the following on the system prior to installing the agent:

  • python header files
  • the gnu compiler
  • the make command

Note that some systems may provide multiple python versions, in which case you would need to specify the versioned header package such as python3-dev that matches the python runtime.

On Debian/Ubuntu:

Copy
$ sudo apt-get install python-dev g++ make

On RHEL/CentOS/Amazon Linux:

Copy
$ sudo yum install python-devel gcc-c++ make

On Alpine:

Copy
$ sudo apk add python-dev g++ make

You can check the support matrix to make sure your system is supported.

The extension is compiled into a binary with system and Python version dependencies, so the installed agent package on one platform cannot just be copied onto a different platform; instead, the agent must be installed specifically on each different platform.

Get the Agent

First, install the package into your application's environment:

Copy
$ pip install appoptics-apm

Now the module appoptics_apm should be available, see below on how to enable it for your application.

Enabling the Agent

The agent requires a service key to connect to your account, and must be either attached as a middleware or through custom instrumentation to your application. Read below to get set up.

Service key

The service key should be defined in the environment your application runs in (see Configuration):

Copy
$ export APPOPTICS_SERVICE_KEY="api-token-here:your-service-name-eg-python"

A service key is composed of an API token with write permisisons and the name of the service you're installing on. Our onboarding flow provides the full service key, or check the API Tokens page to grab a token and fill the service name yourself.

Application Middleware

Instructions are provided for common frameworks below. If you don't find what you need, you can always use custom instrumentation to monitor any Python process.

Django

To instrument your Django application, add appoptics_apm.djangoware to the INSTALLED_APPS tuple in your application's settings module (settings.py)

Copy
#settings.py

INSTALLED_APPS = (
   # ... your Django apps
   'appoptics_apm.djangoware',
)

Tornado

  1. Import AppOptics Tornado instrumentation library:

    Copy
    from appoptics_apm import tornado_oboe
  2. Make your handler function inherit from tornado_oboe.AppOpticsApmBaseHandler:

    Copy
    class MainHandler(tornado_oboe.AppOpticsApmBaseHandler):
        def get(self):
            logging.error("Inside Main Handler %s", appoptics_apm.Context.get\_default())
            self.write("Hello, world from %s:" % appoptics_apm.Context.get\_default())
            self.finish()
    ...

    tornado.options.parse_command_line()

    application = tornado.web.Application([
        (r"/", MainHandler),
        ], **settings)

    application.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()

Flask and Generic WSGI

Many python apps are implemented atop WSGI, which provides a uniform interface through which web frameworks and middleware libraries interoperate. AppOptics offers a WSGI middleware component called AppOpticsApmMiddleware, which wraps your WSGI app to collect performance statistics. Install middleware instrumentation as you would any other middleware by adding it to the file that instantiates your app. But put it at the end of the list, closest to the outside of the middleware stack.

The following code demonstrates the instrumentation of Flask applications. Applications using other frameworks can also wrap the WSGI app with AppOpticsApmMiddleware class to trace the web requests.

Copy
# flask example
from flask import Flask
from appoptics_apm.middleware import AppOpticsApmMiddleware

# the flask app
app = Flask(__name__)

app.wsgi_app = AppOpticsApmMiddleware(app.wsgi_app)

@app.route("/")
def hello():
    return "Hello World!"

Now start your application and make some requests, check your AppOptics dashboard and you will find the trace events reported from your application.

Heroku

Ensure that the AppOptics add-on is attached to your Heroku application, then follow the Python agent steps to install and enable the agent.

Azure App Service

If your Python application platform is Azure App Service on Linux, installing APM is as simple as adding the Python agent as a dependency, enabling it in your application, then redeploying.

To install the agent, add it to the application's requirements.txt file. For example:

Copy
Flask
Jinja2
..
appoptics-apm

Next, enable the agent for your application middleware. Then in the Azure portal for your App Service, use application settings to configure the service key.

Finally, redeploy the application and you should see trace data and metrics shortly.

When the APM Integrated Experience is enabled, AppOptics shares a common navigation and settings with the other integrated experiences' products. How you navigate AppOptics and access its features may vary from these instructions. For more information, go to the APM Integrated Experience documentation.

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.