From 8b4f93dd4e9b1c1bd06fd365d74acf1210372443 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 31 Dec 2021 03:46:21 -0800 Subject: [PATCH] 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. --- bookwyrm/wsgi.py | 10 ++++++++++ requirements.txt | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/bookwyrm/wsgi.py b/bookwyrm/wsgi.py index e670f7f12..800b40d2c 100644 --- a/bookwyrm/wsgi.py +++ b/bookwyrm/wsgi.py @@ -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() diff --git a/requirements.txt b/requirements.txt index 98ffcc450..f37a675d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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