From eeba1699fd5c84a811a299a1767113028ca3c819 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Sep 14 2023 06:06:23 +0000 Subject: Add instrumentation for database queries This enhances the trace with details on what database queries were used. To enable, set CTS_INSTRUMENT_DATABASE env variable. --- diff --git a/Dockerfile b/Dockerfile index d13b070..8bdd90d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,7 @@ RUN dnf -y --setopt=install_weak_deps=False update \ python3-systemd \ python3-opentelemetry-sdk \ python3-opentelemetry-instrumentation-flask \ + python3-opentelemetry-instrumentation-sqlalchemy \ python3-opentelemetry-exporter-otlp-proto-http \ systemd \ # Debugging packages \ diff --git a/cts/__init__.py b/cts/__init__.py index 8aa8a90..01b7c0e 100644 --- a/cts/__init__.py +++ b/cts/__init__.py @@ -36,6 +36,7 @@ from opentelemetry.sdk.trace.export import ConsoleSpanExporter from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.sdk.trace.export import BatchSpanProcessor from opentelemetry.instrumentation.flask import FlaskInstrumentor +from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor from cts.logger import init_logging from cts.config import init_config @@ -81,6 +82,8 @@ tracer = trace.get_tracer(__name__) # Initialize Flask drop-in instrumentation middleware FlaskInstrumentor().instrument_app(app, tracer_provider=provider) +if "CTS_INSTRUMENT_DATABASE" in os.environ: + SQLAlchemyInstrumentor().instrument() def json_error(status, error, message):