Giter VIP home page Giter VIP logo

sample-django's Introduction

Preparing Django app

  1. python3 manage.py migrate
  2. python3 manage.py collectstatic
  3. python3 manage.py createsuperuser

Running with SigNoz

  • 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

To run with gunicorn you need to add post_fork hook

  1. Add a file gunicorn.config.py as given in this repo
  2. 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.

If want to run docker image of django app directly

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

If want to use docker image of django app in docker-compose

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

Browsing the app and checking at SigNoz

  1. Visit http://localhost:8000/admin and create a question for poll
  2. Then visit the list of polls at http://localhost:8000/polls/ and explore the polls
  3. The data should be visible now in SigNoz at http://<IP of SigNoz>:3000

sample-django's People

Contributors

ankitnayan avatar masonegger avatar srikanthccv avatar pranay01 avatar prashant-shahi avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.