epomatti / azure-django-rest-metrics

APM with Azure Application Insights & Django + rest framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django Metrics

Implementation of a Django REST API sending telemetry to Azure Application Insights from reference sample.

Implement Cloud_RoleName tags for microservices.

Setup

Infrastructure

Create the infrastructure:

terraform -chdir="azure/terraform" init
terraform -chdir="azure/terraform" apply -auto-approve

Get the Application Insights connection string:

az monitor app-insights component show --app '<appi>' -g '<group>' --query 'connectionString' -o tsv

Application

Create the .env file from the template:

cp samples/sample.env .env

Set the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable with the Azure value.

Run

Install the dependencies:

poetry install
poetry shell

Apply the migrations and start the server to start sending telemetry.

python manage.py makemigrations
python manage.py migrate
python manage.py runserver --noreload

Additional examples here and here.

Test

Call the API to test the tracing:

curl localhost:8000/users/

Example KQL query on table request:

requests
| where timestamp >= ago(1h)

Docker

Tip

Code snippets based from my other project epomatti/benchmarks.

Make sure the .env is configured, and start the application:

docker compose up --build

Test the tracing:

curl localhost:8000/users/

Troubleshooting

Issues with gunicorn may happen, such as this one.

Follow the documentation for troubleshooting various scenarios.

About

APM with Azure Application Insights & Django + rest framework

License:MIT License


Languages

Language:Python 60.5%Language:HCL 28.2%Language:Bicep 5.5%Language:Dockerfile 4.9%Language:Shell 0.9%