Skip to main content

Python Flask uWSGI

Installation

Following are the steps to install the New Relic agent and connect it with CubeAPM. If New Relic agent is already installed, you can jump to step 5.

  1. Install dependencies:

    pip install newrelic
  2. (Optional) From lib/pythonx.xx/site-packages/newrelic, copy newrelic.ini into the root directory of your application.

  3. Configure the agent.

    [newrelic]
    app_name = <app_name>
    license_key = ABC4567890ABC4567890ABC4567890ABC4567890
  4. Add the highlighted lines below to your project's app.py file:

    app.py
    from flask import Flask
    import newrelic.agent
    app = Flask(__name__)
    newrelic.agent.initialize("newrelic.ini")
  5. Tell the agent to connect with CubeAPM instead of New Relic:

    [newrelic]
    app_name = <app_name>
    license_key = ABC4567890ABC4567890ABC4567890ABC4567890
    host = <domain_of_cubeapm_server>
    tip

    See Using CubeAPM with New Relic agents for details on how to set up <domain_of_cubeapm_server>.

Sample App

A working example is available at https://github.com/cubeapm/sample_app_python_flask_uwsgi/tree/newrelic

Troubleshooting

The following can be used for troubleshooting:

[newrelic]
# Print New Relic agent logs on screen
log_file = stdout
# Set New Relic agent log level to debug if needed to see detailed logs
log_level = debug