From 7bb4e21a369efef993b88bb90e7999a01d96e3a2 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Thu, 16 Mar 2023 13:57:19 -0400 Subject: [PATCH 1/2] Bump opentelemetry versions This isn't actually required for anything, just good practice to keep things up to date. --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index b63c1f30c..6ed492a13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,11 +24,11 @@ pytz>=2022.7 boto3==1.26.57 django-storages==1.13.2 django-redis==5.2.0 -opentelemetry-api==1.11.1 -opentelemetry-exporter-otlp-proto-grpc==1.11.1 -opentelemetry-instrumentation-celery==0.30b1 -opentelemetry-instrumentation-django==0.30b1 -opentelemetry-sdk==1.11.1 +opentelemetry-api==1.16.0 +opentelemetry-exporter-otlp-proto-grpc==1.16.0 +opentelemetry-instrumentation-celery==0.37b0 +opentelemetry-instrumentation-django==0.37b0 +opentelemetry-sdk==1.16.0 protobuf==3.20.* pyotp==2.8.0 qrcode==7.3.1 From 63ab3abe67688b5e7e1a6bfa46d618eb6544e0b1 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Thu, 16 Mar 2023 13:58:09 -0400 Subject: [PATCH 2/2] Add setting for OpenTelemetry console exporter This is primarily useful for debugging changes to the OpenTelemetry setup. --- bookwyrm/apps.py | 2 +- bookwyrm/settings.py | 1 + bookwyrm/telemetry/open_telemetry.py | 13 +++++++++++-- celerywyrm/apps.py | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bookwyrm/apps.py b/bookwyrm/apps.py index 786f86e1c..7f684722d 100644 --- a/bookwyrm/apps.py +++ b/bookwyrm/apps.py @@ -35,7 +35,7 @@ class BookwyrmConfig(AppConfig): # pylint: disable=no-self-use def ready(self): """set up OTLP and preview image files, if desired""" - if settings.OTEL_EXPORTER_OTLP_ENDPOINT: + if settings.OTEL_EXPORTER_OTLP_ENDPOINT or settings.OTEL_EXPORTER_CONSOLE: # pylint: disable=import-outside-toplevel from bookwyrm.telemetry import open_telemetry diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 3f14daf1b..4ac828a0d 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -377,6 +377,7 @@ CSP_INCLUDE_NONCE_IN = ["script-src"] OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None) OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None) OTEL_SERVICE_NAME = env("OTEL_SERVICE_NAME", None) +OTEL_EXPORTER_CONSOLE = env.bool("OTEL_EXPORTER_CONSOLE", False) TWO_FACTOR_LOGIN_MAX_SECONDS = env.int("TWO_FACTOR_LOGIN_MAX_SECONDS", 60) TWO_FACTOR_LOGIN_VALIDITY_WINDOW = env.int("TWO_FACTOR_LOGIN_VALIDITY_WINDOW", 2) diff --git a/bookwyrm/telemetry/open_telemetry.py b/bookwyrm/telemetry/open_telemetry.py index 0b38a04b1..aff68a8b3 100644 --- a/bookwyrm/telemetry/open_telemetry.py +++ b/bookwyrm/telemetry/open_telemetry.py @@ -1,10 +1,19 @@ 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 opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter + +from bookwyrm import settings trace.set_tracer_provider(TracerProvider()) -trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter())) +if settings.OTEL_EXPORTER_CONSOLE: + trace.get_tracer_provider().add_span_processor( + BatchSpanProcessor(ConsoleSpanExporter()) + ) +else: + trace.get_tracer_provider().add_span_processor( + BatchSpanProcessor(OTLPSpanExporter()) + ) def instrumentDjango(): diff --git a/celerywyrm/apps.py b/celerywyrm/apps.py index 6aae849cd..bb2d27edd 100644 --- a/celerywyrm/apps.py +++ b/celerywyrm/apps.py @@ -7,7 +7,7 @@ class CelerywyrmConfig(AppConfig): verbose_name = "BookWyrm Celery" def ready(self): - if settings.OTEL_EXPORTER_OTLP_ENDPOINT: + if settings.OTEL_EXPORTER_OTLP_ENDPOINT or settings.OTEL_EXPORTER_CONSOLE: from bookwyrm.telemetry import open_telemetry open_telemetry.instrumentCelery()