From 072d3aaa2b76b2ee7fc50869a4b8af140803e98b Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Fri, 26 Sep 2025 08:48:35 +0300 Subject: [PATCH] fix import for litestar otl --- lite_bootstrap/bootstrappers/litestar_bootstrapper.py | 4 +++- lite_bootstrap/import_checker.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lite_bootstrap/bootstrappers/litestar_bootstrapper.py b/lite_bootstrap/bootstrappers/litestar_bootstrapper.py index 7a57b15..06649a3 100644 --- a/lite_bootstrap/bootstrappers/litestar_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/litestar_bootstrapper.py @@ -27,12 +27,14 @@ import litestar from litestar.config.app import AppConfig from litestar.config.cors import CORSConfig - from litestar.contrib.opentelemetry import OpenTelemetryConfig from litestar.openapi import OpenAPIConfig from litestar.openapi.plugins import SwaggerRenderPlugin from litestar.plugins.prometheus import PrometheusConfig, PrometheusController from litestar.static_files import create_static_files_router +if import_checker.is_litestar_opentelemetry_installed: + from litestar.contrib.opentelemetry import OpenTelemetryConfig + if import_checker.is_opentelemetry_installed: from opentelemetry.trace import get_tracer_provider diff --git a/lite_bootstrap/import_checker.py b/lite_bootstrap/import_checker.py index 7d6e1ce..fc01f50 100644 --- a/lite_bootstrap/import_checker.py +++ b/lite_bootstrap/import_checker.py @@ -12,3 +12,6 @@ is_fastapi_opentelemetry_installed = ( is_opentelemetry_installed and find_spec("opentelemetry.instrumentation.fastapi") is not None ) +is_litestar_opentelemetry_installed = ( + is_opentelemetry_installed and is_litestar_installed and find_spec("opentelemetry.instrumentation.asgi") is not None +)