From eb6192c804065f5317c2a4f5e058ff0f915ad720 Mon Sep 17 00:00:00 2001 From: Christophe Haen Date: Fri, 17 Nov 2023 17:07:58 +0100 Subject: [PATCH] Adding middleware is already done in the fastapi instrumentation --- src/diracx/routers/__init__.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/diracx/routers/__init__.py b/src/diracx/routers/__init__.py index f0acf3af..2230c6b3 100644 --- a/src/diracx/routers/__init__.py +++ b/src/diracx/routers/__init__.py @@ -72,7 +72,6 @@ def instrument_otel(app: ASGIApp, app_name: str, log_correlation: bool = True) - # set the tracer provider tracer_provider = TracerProvider(resource=resource) - trace.set_tracer_provider(tracer_provider) # elif MODE == "otel-collector-http": # tracer.add_span_processor( @@ -85,6 +84,7 @@ def instrument_otel(app: ASGIApp, app_name: str, log_correlation: bool = True) - OTLPSpanExporterGRPC(endpoint=OTEL_GRPC_ENDPOINT, insecure=True) ) ) + trace.set_tracer_provider(tracer_provider) # metric_reader = PeriodicExportingMetricReader(ConsoleMetricExporter(),export_interval_millis=1000) metric_reader = PeriodicExportingMetricReader( @@ -105,16 +105,13 @@ def instrument_otel(app: ASGIApp, app_name: str, log_correlation: bool = True) - for hl in logger.handlers: hl.setFormatter(logging.Formatter(DEFAULT_LOGGING_FORMAT)) + # FastAPIInstrumentor.instrument_app( + # app, tracer_provider=tracer_provider, meter_provider=meter_provider + # ) + FastAPIInstrumentor.instrument_app( app, tracer_provider=tracer_provider, meter_provider=meter_provider ) - from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware - - app.add_middleware( - OpenTelemetryMiddleware, - tracer_provider=tracer_provider, - meter_provider=meter_provider, - ) # Rules: