From 7093e019252802c0b709624bec69b4901db22628 Mon Sep 17 00:00:00 2001 From: Julius Unverfehrt Date: Wed, 31 Jan 2024 09:09:13 +0100 Subject: [PATCH] feat(opentelemetry): add webserver tracing to default pipeline --- README.md | 4 ++-- pyinfra/examples.py | 3 ++- pyinfra/utils/opentelemetry.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 189ad7d..f497131 100755 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Shared library for the research team, containing code related to infrastructure and communication with other services. Offers a simple interface for processing data and sending responses via AMQP, monitoring via Prometheus and storage -access via S3 or Azure. +access via S3 or Azure. Also export traces via OpenTelemetry for queue messages and webserver requests. To start, see the [complete example](pyinfra/examples.py) which shows how to use all features of the service and can be imported and used directly for default research service pipelines (data ID in message, download data from storage, @@ -66,7 +66,7 @@ configured from environment variables, without additional work in the microservice app, although additional confiuration is possible. -`TRACING_ENDPOINT` should typically be set +`TRACING__OPENTELEMETRY__ENDPOINT` should typically be set to `http://otel-collector-opentelemetry-collector.otel-collector:4318/v1/traces`. ## Queue Manager diff --git a/pyinfra/examples.py b/pyinfra/examples.py index cec9132..de25bae 100644 --- a/pyinfra/examples.py +++ b/pyinfra/examples.py @@ -5,7 +5,7 @@ from kn_utils.logging import logger from pyinfra.config.loader import get_pyinfra_validators, validate_settings from pyinfra.queue.callback import Callback from pyinfra.queue.manager import QueueManager -from pyinfra.utils.opentelemetry import instrument_pika, setup_trace +from pyinfra.utils.opentelemetry import instrument_pika, setup_trace, instrument_app from pyinfra.webserver.prometheus import ( add_prometheus_endpoint, make_prometheus_processing_time_decorator_from_settings, @@ -45,6 +45,7 @@ def start_standard_queue_consumer( logger.info(f"OpenTelemetry tracing enabled.") setup_trace(settings) instrument_pika() + instrument_app(app) app = add_health_check_endpoint(app, queue_manager.is_ready) diff --git a/pyinfra/utils/opentelemetry.py b/pyinfra/utils/opentelemetry.py index 20341cd..f23f6f5 100644 --- a/pyinfra/utils/opentelemetry.py +++ b/pyinfra/utils/opentelemetry.py @@ -69,5 +69,5 @@ def instrument_pika(): PikaInstrumentor().instrument() -def instrument_app(app: FastAPI): - FastAPIInstrumentor().instrument_app(app) +def instrument_app(app: FastAPI, excluded_urls: str = "/health,/ready,/prometheus"): + FastAPIInstrumentor().instrument_app(app, excluded_urls=excluded_urls)