# Instrumenting Flask with OpenTelemetry

# Prerequisites

  • Python 3.6+

# Introduction

In this tutorial we will instrument a basicopen in new window Flask app using OpenTelemetry instrumentation.

# Instrumenting Flask app

  • Step 1. Let's start by downloading the source code:
git clone https://github.com/uptrace/uptrace-python.git
cd example/flask
  • Step 2. Install the required dependencies:
pip install -r requirements.txt
  • Step 3. Edit main.py to configure OpenTelemetry to export data to Uptrace:
import uptrace

uptrace.configure_opentelemetry(
    # Copy DSN here or use UPTRACE_DSN env var.
    dsn="",
)
  • Step 4. Edit main.py to instrument the Flask app:
from opentelemetry.instrumentation.flask import FlaskInstrumentor

app = Flask(__name__)
FlaskInstrumentor().instrument_app(app)
UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" ./main.py

The full code is available at GitHubopen in new window.

# What is next?

By now, you should have a Flask app with instrumented views. Next, instrumentopen in new window more operations (for example, database queries) or learn about OpenTelemetry API to create your own instrumentations.