Configure Contrast Flask middleware for the Python agent

Flask middleware is a WSGI middleware which operates by wrapping the Flask application instance. The following example shows a sample Flask application wrapped by the Contrast middleware class:

import Flask

# This line imports the Contrast middleware class from the package
from contrast.agent.middlewares.flask_middleware import FlaskMiddleware as ContrastMiddleware

# This is where the example app is declared. Look for something similar in your
# application since this instance needs to be wrapped by Contrast middleware
app = Flask(__name__)

# This line wraps the application instance with the Contrast middleware
app.wsgi_app = ContrastMiddleware(app)

# Everything below this line is part of the example app. It should not be added
@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(...)

See the Flask documentation for more details on using WSGI middleware.