Implementation of a Django REST API sending telemetry to Azure Application Insights from reference sample.
Implement Cloud_RoleName tags for microservices.
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
Create the .env
file from the template:
cp samples/sample.env .env
Set the APPLICATIONINSIGHTS_CONNECTION_STRING
environment variable with the Azure value.
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.
Call the API to test the tracing:
curl localhost:8000/users/
Example KQL query on table request
:
requests
| where timestamp >= ago(1h)
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/
Issues with gunicorn
may happen, such as this one.
Follow the documentation for troubleshooting various scenarios.