Integrate open telemetry

This allows us to export to anyone that takes OTLP, which is most of the
major players, I think! Nifty!

Kinda like the S3 config but for tracing, you can slot in any provider
that supports it via environment variables

This uses the Django instrumentation, which gets us a bunch of nifty
stuff right out of the box.
This commit is contained in:
Joel Bradshaw 2021-12-31 03:46:21 -08:00
parent 1c48605418
commit 8b4f93dd4e
2 changed files with 14 additions and 0 deletions

View file

@ -10,9 +10,19 @@ https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
import os
from environs import Env
from django.core.wsgi import get_wsgi_application
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
Env.read_env()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookwyrm.settings")
DjangoInstrumentor().instrument()
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(OTLPSpanExporter())
)
application = get_wsgi_application()

View file

@ -18,3 +18,7 @@ django-rename-app==0.1.2
pytz>=2021.1
boto3==1.17.88
django-storages==1.11.1
opentelemetry-api
opentelemetry-sdk
opentelemetry-exporter-otlp-proto-grpc
opentelemetry-instrumentation-django