Document OTLP in env, only load if env vars exist

Also move telemetry into its own file, all those imports seemed like
unnecessary clutter
This commit is contained in:
Joel Bradshaw 2022-01-01 13:16:17 -08:00
parent 7cb7063da5
commit 3d7f73d73c
3 changed files with 30 additions and 8 deletions

View file

@ -73,3 +73,19 @@ PREVIEW_TEXT_COLOR=#363636
PREVIEW_IMG_WIDTH=1200
PREVIEW_IMG_HEIGHT=630
PREVIEW_DEFAULT_COVER_COLOR=#002549
# Below are example keys if you want to enable automatically
# sending telemetry to an OTLP-compatible service. Many of
# the main monitoring apps have OLTP collectors, including
# NewRelic, DataDog, and Honeycomb.io - consult their
# documentation for setup instructions, and what exactly to
# put below!
#
# Service name is an arbitrary tag that is attached to any
# data sent, used to distinguish different sources. Useful
# for sending prod and dev metrics to the same place and
# keeping them separate, for instance!
#
# OTEL_EXPORTER_OTLP_ENDPOINT=https://your.api.endpoint # API endpoint for your provider
# OTEL_EXPORTER_OTLP_HEADERS= # Any headers required, usually authentication info
# OTEL_SERVICE_NAME=your_service_name

10
bookwyrm/telemetry.py Normal file
View file

@ -0,0 +1,10 @@
def InstallOpenTelemetry():
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
DjangoInstrumentor().instrument()
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))

View file

@ -10,17 +10,13 @@ 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
from bookwyrm.telemetry import InstallOpenTelemetry
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()))
if 'OTEL_EXPORTER_OTLP_ENDPOINT' in os.environ:
InstallOpenTelemetry()
application = get_wsgi_application()