python3 manage.py migrate
python3 manage.py collectstatic
python3 manage.py createsuperuser
- Create a virtual environment and activate it
python3 -m venv .venv
source .venv/bin/activate
- Install requirements
pip install -r requirements.txt
- Install instrumentation packages
opentelemetry-bootstrap --action=install
- Add a file
gunicorn.config.py
as given in this repo - Specify that config file when running gunicorn as in below run command
DJANGO_SETTINGS_MODULE=<DJANGO_APP>.settings OTEL_RESOURCE_ATTRIBUTES=service.name=<serviceName> OTEL_EXPORTER_OTLP_ENDPOINT=http://<IP OF SigNoz>:4317 OTEL_EXPORTER_OTLP_PROTOCOL=grpc opentelemetry-instrument gunicorn <DJANGO_APP>.wsgi -c gunicorn.config.py --workers 2 --threads 2
specifying DJANGO_SETTINGS_MODULE is necessary for opentelemetry instrumentation to work
For this example, sample command would look like
DJANGO_SETTINGS_MODULE=mysite.settings OTEL_RESOURCE_ATTRIBUTES=service.name=MainApp OTEL_EXPORTER_OTLP_ENDPOINT=http://<IP Of SigNoz>:4317 OTEL_EXPORTER_OTLP_PROTOCOL=grpc opentelemetry-instrument gunicorn mysite.wsgi -c gunicorn.config.py --workers 2 --threads 2
Note: set OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
and port 4318 in endpoint OTEL_EXPORTER_OTLP_ENDPOINT="http://<IP of SigNoz>:4318"
if you are using OTLP HTTP exporter.
docker run --env \
--env OTEL_SERVICE_NAME=djangoApp \
--env OTEL_EXPORTER_OTLP_ENDPOINT=host.docker.internal:4317 \
--env OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
--env DJANGO_SETTINGS_MODULE=mysite.settings \
-p 8000:8000 \
-t signoz/sample-django:latest opentelemetry-instrument gunicorn mysite.wsgi -c gunicorn.config.py --workers 2 --threads 2 --bind 0.0.0.0:8000
Add below service to your docker-compose
django-app:
image: "signoz/sample-django:latest"
container_name: sample-django
command: opentelemetry-instrument gunicorn mysite.wsgi -c gunicorn.config.py --workers 2 --threads 2 --bind 0.0.0.0:8000
ports:
- "8000:8000"
environment:
- OTEL_SERVICE_NAME=djangoApp
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
- OTEL_EXPORTER_OTLP_PROTOCOL=grpc
- DJANGO_SETTINGS_MODULE=mysite.settings
- Visit
http://localhost:8000/admin
and create a question for poll - Then visit the list of polls at
http://localhost:8000/polls/
and explore the polls - The data should be visible now in SigNoz at
http://<IP of SigNoz>:3000