From 3346d608aa8e9560ce7af776a30298f88259ffc6 Mon Sep 17 00:00:00 2001 From: inimaz <93inigo93@gmail.com> Date: Sun, 8 Feb 2026 16:07:53 +0100 Subject: [PATCH 1/3] fix(api): deactivate logfire if not compatible --- .../api/services/signup_service.py | 21 +++++++++++++++--- carbonserver/main.py | 22 ++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/carbonserver/carbonserver/api/services/signup_service.py b/carbonserver/carbonserver/api/services/signup_service.py index 7bc380bde..a641ef9c0 100644 --- a/carbonserver/carbonserver/api/services/signup_service.py +++ b/carbonserver/carbonserver/api/services/signup_service.py @@ -1,10 +1,18 @@ import logging +from contextlib import nullcontext from uuid import UUID import jwt -import logfire from fastapi import HTTPException +try: + import logfire + + LOGFIRE_AVAILABLE = True +except (ImportError, AttributeError) as e: + LOGFIRE_AVAILABLE = False + logging.getLogger(__name__).warning(f"Logfire not available: {e}") + from carbonserver.api.infra.repositories.repository_organizations import ( SqlAlchemyRepository as OrganizationRepository, ) @@ -20,6 +28,7 @@ User, UserAutoCreate, ) +from carbonserver.config import settings LOGGER = logging.getLogger(__name__) @@ -39,10 +48,16 @@ def sign_up( self, user: UserAutoCreate, ) -> User: - with logfire.span("User applicative creation", service="signup"): + span_context = ( + logfire.span("User applicative creation", service="signup") + if settings.send_to_logfire and LOGFIRE_AVAILABLE + else nullcontext() + ) + with span_context: created_user = self._user_repository.create_user(user) subscribed_user = self.new_user_setup(created_user) - logfire.info(str(subscribed_user)) + if settings.send_to_logfire and LOGFIRE_AVAILABLE: + logfire.info(str(subscribed_user)) LOGGER.info(f"User {subscribed_user.id} created") return subscribed_user diff --git a/carbonserver/main.py b/carbonserver/main.py index 3a3611b9f..6b1c9c7d4 100644 --- a/carbonserver/main.py +++ b/carbonserver/main.py @@ -1,6 +1,5 @@ import os -import logfire from fastapi import FastAPI from fastapi_pagination import add_pagination from pydantic import ValidationError @@ -8,6 +7,16 @@ from starlette.requests import Request from starlette.responses import JSONResponse +try: + import logfire + + LOGFIRE_AVAILABLE = True +except (ImportError, AttributeError) as e: + LOGFIRE_AVAILABLE = False + import logging + + logging.getLogger(__name__).warning(f"Logfire not available: {e}") + from carbonserver.api.errors import DBException, UserException, get_http_exception from carbonserver.api.infra.database import sql_models from carbonserver.api.routers import ( @@ -83,9 +92,6 @@ def init_db(container): def init_server(container): - logfire.configure( - token=settings.logfire_token, send_to_logfire=settings.send_to_logfire - ) server = FastAPI( servers=[ {"url": "/api/"}, @@ -93,7 +99,13 @@ def init_server(container): port=settings.api_port, host=settings.server_host, ) - logfire.instrument_fastapi(server) + + # Only configure and instrument Logfire if telemetry is enabled and available + if settings.send_to_logfire and LOGFIRE_AVAILABLE: + logfire.configure( + token=settings.logfire_token, send_to_logfire=settings.send_to_logfire + ) + logfire.instrument_fastapi(server) server.container = container server.include_router(users.router) From 5c11377275f5cb580baa76402e2f33c4d644dc13 Mon Sep 17 00:00:00 2001 From: inimaz <93inigo93@gmail.com> Date: Sun, 8 Feb 2026 16:33:12 +0100 Subject: [PATCH 2/3] fix: remove logfire depencies --- carbonserver/pyproject.toml | 2 - pyproject.toml | 2 - requirements/requirements-api.txt | 71 ++----------------------------- 3 files changed, 3 insertions(+), 72 deletions(-) diff --git a/carbonserver/pyproject.toml b/carbonserver/pyproject.toml index d922c3a7e..cf0cef91b 100644 --- a/carbonserver/pyproject.toml +++ b/carbonserver/pyproject.toml @@ -22,7 +22,6 @@ dependencies = [ "fastapi<1.0.0", "fief-client[fastapi]", "fastapi[standard]", - "logfire", "httpx", "pydantic[email]<2.0.0", "psycopg2-binary<3.0.0", @@ -38,7 +37,6 @@ dependencies = [ "requests-mock", "rapidfuzz", "PyJWT", - "logfire[fastapi]>=1.0.1", "fastapi-oidc>=0.0.9", ] diff --git a/pyproject.toml b/pyproject.toml index 46795fdba..8ff8c88c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,6 @@ dev = [ "requests", "requests-mock", "responses", - "logfire>=1.0.1", "pytest-cov", ] doc = [ @@ -133,7 +132,6 @@ api = [ "requests-mock", "rapidfuzz", "PyJWT", - "logfire[fastapi]>=1.0.1", ] [project.scripts] diff --git a/requirements/requirements-api.txt b/requirements/requirements-api.txt index d08394583..e00efcb07 100644 --- a/requirements/requirements-api.txt +++ b/requirements/requirements-api.txt @@ -11,8 +11,6 @@ anyio==4.12.0 # watchfiles arrow==1.4.0 # via codecarbon (pyproject.toml) -asgiref==3.11.0 - # via opentelemetry-instrumentation-asgi bcrypt==4.3.0 # via codecarbon (pyproject.toml) cachetools==6.2.3 @@ -43,8 +41,6 @@ ecdsa==0.19.1 # via python-jose email-validator==2.3.0 # via pydantic -executing==2.2.1 - # via logfire fastapi==0.123.0 # via # codecarbon (pyproject.toml) @@ -57,8 +53,8 @@ fastapi-pagination==0.15.0 # via codecarbon (pyproject.toml) fief-client==0.20.0 # via codecarbon (pyproject.toml) -googleapis-common-protos==1.72.0 - # via opentelemetry-exporter-otlp-proto-http +greenlet==3.3.1 + # via sqlalchemy h11==0.16.0 # via # httpcore @@ -77,14 +73,10 @@ idna==3.11 # email-validator # httpx # requests -importlib-metadata==8.7.0 - # via opentelemetry-api iniconfig==2.3.0 # via pytest jwcrypto==1.5.6 # via fief-client -logfire==4.15.1 - # via codecarbon (pyproject.toml) makefun==1.16.0 # via fief-client mako==1.3.10 @@ -103,49 +95,8 @@ numpy==2.4.2 # pandas nvidia-ml-py==13.580.82 # via codecarbon (pyproject.toml) -opentelemetry-api==1.38.0 - # via - # opentelemetry-exporter-otlp-proto-http - # opentelemetry-instrumentation - # opentelemetry-instrumentation-asgi - # opentelemetry-instrumentation-fastapi - # opentelemetry-sdk - # opentelemetry-semantic-conventions -opentelemetry-exporter-otlp-proto-common==1.38.0 - # via opentelemetry-exporter-otlp-proto-http -opentelemetry-exporter-otlp-proto-http==1.38.0 - # via logfire -opentelemetry-instrumentation==0.59b0 - # via - # logfire - # opentelemetry-instrumentation-asgi - # opentelemetry-instrumentation-fastapi -opentelemetry-instrumentation-asgi==0.59b0 - # via opentelemetry-instrumentation-fastapi -opentelemetry-instrumentation-fastapi==0.59b0 - # via logfire -opentelemetry-proto==1.38.0 - # via - # opentelemetry-exporter-otlp-proto-common - # opentelemetry-exporter-otlp-proto-http -opentelemetry-sdk==1.38.0 - # via - # logfire - # opentelemetry-exporter-otlp-proto-http -opentelemetry-semantic-conventions==0.59b0 - # via - # opentelemetry-instrumentation - # opentelemetry-instrumentation-asgi - # opentelemetry-instrumentation-fastapi - # opentelemetry-sdk -opentelemetry-util-http==0.59b0 - # via - # opentelemetry-instrumentation-asgi - # opentelemetry-instrumentation-fastapi packaging==25.0 - # via - # opentelemetry-instrumentation - # pytest + # via pytest pandas==2.3.3 # via codecarbon (pyproject.toml) pluggy==1.6.0 @@ -154,11 +105,6 @@ prometheus-client==0.23.1 # via codecarbon (pyproject.toml) prompt-toolkit==3.0.52 # via questionary -protobuf==6.33.5 - # via - # googleapis-common-protos - # logfire - # opentelemetry-proto psutil==6.1.1 # via codecarbon (pyproject.toml) psycopg2-binary==2.9.11 @@ -208,7 +154,6 @@ requests==2.32.5 # via # codecarbon (pyproject.toml) # fastapi-oidc - # opentelemetry-exporter-otlp-proto-http # requests-mock # responses requests-mock==1.12.1 @@ -218,7 +163,6 @@ responses==0.25.8 rich==14.2.0 # via # codecarbon (pyproject.toml) - # logfire # typer rsa==4.9.1 # via python-jose @@ -247,11 +191,6 @@ typing-extensions==4.15.0 # fastapi # fastapi-pagination # jwcrypto - # logfire - # opentelemetry-api - # opentelemetry-exporter-otlp-proto-http - # opentelemetry-sdk - # opentelemetry-semantic-conventions # pydantic # starlette # typer @@ -273,9 +212,5 @@ wcwidth==0.2.14 # via prompt-toolkit websockets==15.0.1 # via uvicorn -wrapt==1.17.3 - # via opentelemetry-instrumentation yaspin==3.3.0 # via fief-client -zipp==3.23.0 - # via importlib-metadata From ff83ae343932ffb79787f49829a14eafaa15e326 Mon Sep 17 00:00:00 2001 From: inimaz <93inigo93@gmail.com> Date: Sun, 8 Feb 2026 17:09:51 +0100 Subject: [PATCH 3/3] fix: remove logfire from the server --- .../api/services/signup_service.py | 24 +++---------------- carbonserver/carbonserver/config.py | 2 -- carbonserver/main.py | 17 ------------- pyproject.toml | 1 + 4 files changed, 4 insertions(+), 40 deletions(-) diff --git a/carbonserver/carbonserver/api/services/signup_service.py b/carbonserver/carbonserver/api/services/signup_service.py index a641ef9c0..5f452b408 100644 --- a/carbonserver/carbonserver/api/services/signup_service.py +++ b/carbonserver/carbonserver/api/services/signup_service.py @@ -1,18 +1,9 @@ import logging -from contextlib import nullcontext from uuid import UUID import jwt from fastapi import HTTPException -try: - import logfire - - LOGFIRE_AVAILABLE = True -except (ImportError, AttributeError) as e: - LOGFIRE_AVAILABLE = False - logging.getLogger(__name__).warning(f"Logfire not available: {e}") - from carbonserver.api.infra.repositories.repository_organizations import ( SqlAlchemyRepository as OrganizationRepository, ) @@ -28,7 +19,6 @@ User, UserAutoCreate, ) -from carbonserver.config import settings LOGGER = logging.getLogger(__name__) @@ -48,17 +38,9 @@ def sign_up( self, user: UserAutoCreate, ) -> User: - span_context = ( - logfire.span("User applicative creation", service="signup") - if settings.send_to_logfire and LOGFIRE_AVAILABLE - else nullcontext() - ) - with span_context: - created_user = self._user_repository.create_user(user) - subscribed_user = self.new_user_setup(created_user) - if settings.send_to_logfire and LOGFIRE_AVAILABLE: - logfire.info(str(subscribed_user)) - LOGGER.info(f"User {subscribed_user.id} created") + created_user = self._user_repository.create_user(user) + subscribed_user = self.new_user_setup(created_user) + LOGGER.info(f"User {subscribed_user.id} created") return subscribed_user def subscribe_user_to_org( diff --git a/carbonserver/carbonserver/config.py b/carbonserver/carbonserver/config.py index ccd5f5462..cb711544c 100644 --- a/carbonserver/carbonserver/config.py +++ b/carbonserver/carbonserver/config.py @@ -32,8 +32,6 @@ def fief_url(self) -> str: frontend_url: str = Field("", env="FRONTEND_URL") environment: str = Field("production") jwt_key: str = Field("", env="JWT_KEY") - logfire_token: str = Field("", env="LOGFIRE_TOKEN") - send_to_logfire: bool = Field(False, env="LOGFIRE_SEND_TO_LOGFIRE") api_port: int = Field(8080, env="API_PORT") server_host: str = Field("0.0.0.0", env="SERVER_HOST") diff --git a/carbonserver/main.py b/carbonserver/main.py index 6b1c9c7d4..fbc01bea7 100644 --- a/carbonserver/main.py +++ b/carbonserver/main.py @@ -7,16 +7,6 @@ from starlette.requests import Request from starlette.responses import JSONResponse -try: - import logfire - - LOGFIRE_AVAILABLE = True -except (ImportError, AttributeError) as e: - LOGFIRE_AVAILABLE = False - import logging - - logging.getLogger(__name__).warning(f"Logfire not available: {e}") - from carbonserver.api.errors import DBException, UserException, get_http_exception from carbonserver.api.infra.database import sql_models from carbonserver.api.routers import ( @@ -100,13 +90,6 @@ def init_server(container): host=settings.server_host, ) - # Only configure and instrument Logfire if telemetry is enabled and available - if settings.send_to_logfire and LOGFIRE_AVAILABLE: - logfire.configure( - token=settings.logfire_token, send_to_logfire=settings.send_to_logfire - ) - logfire.instrument_fastapi(server) - server.container = container server.include_router(users.router) server.include_router(authenticate.router) diff --git a/pyproject.toml b/pyproject.toml index 8ff8c88c7..797bcdc8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,6 +91,7 @@ dev = [ "requests-mock", "responses", "pytest-cov", + "logfire>=1.0.1", # For testing Logfire output method ] doc = [ "sphinx",