Skip to content

Commit

Permalink
🐳 Alter docker setup to use Open Telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Apr 8, 2022
1 parent b331e89 commit 06674be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \

COPY --from=build /usr/local/lib/python3.7 /usr/local/lib/python3.7
COPY --from=build /usr/local/bin/uwsgi /usr/local/bin/uwsgi
COPY --from=build /usr/local/bin/opentelemetry-instrument /usr/local/bin/opentelemetry-instrument

# Stage 3.2 - Copy source code
WORKDIR /app
Expand Down
4 changes: 2 additions & 2 deletions bin/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ fi

# Start server
>&2 echo "Starting server"
uwsgi \
cd src/
opentelemetry-instrument uwsgi \
--http :$uwsgi_port \
--http-keepalive \
--manage-script-name \
--mount $mountpoint=objects.wsgi:application \
--static-map /static=/app/static \
--static-map /media=/app/media \
--chdir src \
--enable-threads \
--processes $uwsgi_processes \
--threads $uwsgi_threads \
Expand Down
5 changes: 5 additions & 0 deletions src/manage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env python
import sys

from opentelemetry.instrumentation.django import DjangoInstrumentor

from objects.setup import setup_env

if __name__ == "__main__":
setup_env()

# This call is what makes the Django application be instrumented
DjangoInstrumentor().instrument()

try:
from django.core.management import execute_from_command_line
except ImportError:
Expand Down
13 changes: 13 additions & 0 deletions src/objects/utils/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,18 @@ class UtilsConfig(AppConfig):
name = "objects.utils"

def ready(self):
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
ConsoleSpanExporter,
)

from . import checks # noqa
from . import oas_extensions # noqa

trace.set_tracer_provider(TracerProvider())

trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(ConsoleSpanExporter())
)

0 comments on commit 06674be

Please sign in to comment.