Add setting for OpenTelemetry console exporter

This is primarily useful for debugging changes to the OpenTelemetry
setup.
This commit is contained in:
Wesley Aptekar-Cassels 2023-03-16 13:58:09 -04:00
parent 7bb4e21a36
commit 63ab3abe67
4 changed files with 14 additions and 4 deletions

View file

@ -35,7 +35,7 @@ class BookwyrmConfig(AppConfig):
# pylint: disable=no-self-use # pylint: disable=no-self-use
def ready(self): def ready(self):
"""set up OTLP and preview image files, if desired""" """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 # pylint: disable=import-outside-toplevel
from bookwyrm.telemetry import open_telemetry from bookwyrm.telemetry import open_telemetry

View file

@ -377,6 +377,7 @@ CSP_INCLUDE_NONCE_IN = ["script-src"]
OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None) OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None)
OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None) OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None)
OTEL_SERVICE_NAME = env("OTEL_SERVICE_NAME", 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_MAX_SECONDS = env.int("TWO_FACTOR_LOGIN_MAX_SECONDS", 60)
TWO_FACTOR_LOGIN_VALIDITY_WINDOW = env.int("TWO_FACTOR_LOGIN_VALIDITY_WINDOW", 2) TWO_FACTOR_LOGIN_VALIDITY_WINDOW = env.int("TWO_FACTOR_LOGIN_VALIDITY_WINDOW", 2)

View file

@ -1,10 +1,19 @@
from opentelemetry import trace from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider 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.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(): def instrumentDjango():

View file

@ -7,7 +7,7 @@ class CelerywyrmConfig(AppConfig):
verbose_name = "BookWyrm Celery" verbose_name = "BookWyrm Celery"
def ready(self): 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 from bookwyrm.telemetry import open_telemetry
open_telemetry.instrumentCelery() open_telemetry.instrumentCelery()