Flask Web Application Setup
Install virtualenv, if not already done
Create a virtual environment for the application, if needed
Activate virtual environment
Upgrade pip in virtual environment
Install dependencies listed in requirements.txt
Step
Windows (PowerShell)
Linux / MacOS (bash)
1
pip install virtualenv
2
python -m venv venv
python3 -m venv venv
3
.\venv\Scripts\Activate.ps1
source venv/bin/activate
4
python -m pip install --upgrade pip
python3 -m pip install --upgrade pip
5
pip install -r requirements.txt
To send data to New Relic APM, uncomment the the following lines in webserver.py:
import newrelic .agent
newrelic .agent .initialize ()
Windows (PowerShell)
Linux / MacOS (bash)
$Env:NEW_RELIC_APP_NAME = "Local Python App"
export NEW_RELIC_APP_NAME="Local Python App"
$Env:NEW_RELIC_LICENSE_KEY = "XXXX...NRAL"
export NEW_RELIC_LICENSE_KEY="XXXX...NRAL"
python datacrunch-consulting\webserver.py
python3 datacrunch-consulting/webserver.py
To send telemetry data to New Relic, set the following environment variables
OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net:4317
OTEL_EXPORTER_OTLP_HEADERS=api-key=XXXX...NRAL
OTEL_RESOURCE_ATTRIBUTES=service.name=python-flask.otel,service.instance.id=localhost-pc
Download the following packages to your virtual environment
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-instrumentation-flask
pip install opentelemetry-exporter-otlp-proto-grpc
pip install opentelemetry-distro
No changes to the code is needed, just run the app as usual but with opentelemetry-instrument at the front
opentelemetry-instrument python .\datacrunch-consulting\webserver.py
Build the Docker image with docker build -t python-flask:latest .
Run the app with your INGEST - LICENSE key and give your application a name:
docker run -d -e NEW_RELIC_LICENSE_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXNRAL" -e NEW_RELIC_APP_NAME="python-flask.docker" -p 5000:5000 python-flask:latest`
Access the application with the same endpoints above at http://127.0.0.1:5000