refactor: Remove unnecessary exception logging and improve error logging (#4676)
* Remove unnecessary exception logging in API key decryption * Removes unnecessary exception logging in services * fix: Change debug logging to error logging for user last login update * fix: Enhance error logging to include exception details in various services
This commit is contained in:
parent
6133fed90a
commit
7614cfbac6
8 changed files with 12 additions and 12 deletions
|
|
@ -97,7 +97,7 @@ def setup_llm_caching() -> None:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning(f"Could not import {settings_service.settings.cache_type}. ")
|
logger.warning(f"Could not import {settings_service.settings.cache_type}. ")
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
logger.opt(exception=True).warning("Could not setup LLM caching.")
|
logger.warning("Could not setup LLM caching.")
|
||||||
|
|
||||||
|
|
||||||
def set_langchain_cache(settings) -> None:
|
def set_langchain_cache(settings) -> None:
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,6 @@ def decrypt_api_key(encrypted_api_key: str, settings_service: SettingsService):
|
||||||
try:
|
try:
|
||||||
decrypted_key = fernet.decrypt(encrypted_api_key.encode()).decode()
|
decrypted_key = fernet.decrypt(encrypted_api_key.encode()).decode()
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Failed to decrypt API key")
|
logger.debug("Failed to decrypt API key")
|
||||||
decrypted_key = fernet.decrypt(encrypted_api_key).decode()
|
decrypted_key = fernet.decrypt(encrypted_api_key).decode()
|
||||||
return decrypted_key
|
return decrypted_key
|
||||||
|
|
|
||||||
|
|
@ -56,5 +56,5 @@ async def update_user_last_login_at(user_id: UUID, db: AsyncSession):
|
||||||
user_data = UserUpdate(last_login_at=datetime.now(timezone.utc))
|
user_data = UserUpdate(last_login_at=datetime.now(timezone.utc))
|
||||||
user = await get_user_by_id(db, user_id)
|
user = await get_user_by_id(db, user_id)
|
||||||
return await update_user(user, user_data, db)
|
return await update_user(user, user_data, db)
|
||||||
except Exception: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Error updating user last login at")
|
logger.error(f"Error updating user last login at: {e!s}")
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,7 @@ class DatabaseService(Service):
|
||||||
buffer.write(f"{datetime.now(tz=timezone.utc).astimezone().isoformat()}: Checking migrations\n")
|
buffer.write(f"{datetime.now(tz=timezone.utc).astimezone().isoformat()}: Checking migrations\n")
|
||||||
command.check(alembic_cfg)
|
command.check(alembic_cfg)
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Error checking migrations")
|
logger.debug(f"Error checking migrations: {exc}")
|
||||||
if isinstance(exc, util.exc.CommandError | util.exc.AutogenerateDiffsDetected):
|
if isinstance(exc, util.exc.CommandError | util.exc.AutogenerateDiffsDetected):
|
||||||
command.upgrade(alembic_cfg, "head")
|
command.upgrade(alembic_cfg, "head")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
@ -275,7 +275,7 @@ class DatabaseService(Service):
|
||||||
break
|
break
|
||||||
except util.exc.AutogenerateDiffsDetected:
|
except util.exc.AutogenerateDiffsDetected:
|
||||||
# downgrade to base and upgrade again
|
# downgrade to base and upgrade again
|
||||||
logger.opt(exception=True).warning("AutogenerateDiffsDetected")
|
logger.warning("AutogenerateDiffsDetected")
|
||||||
command.downgrade(alembic_cfg, f"-{i}")
|
command.downgrade(alembic_cfg, f"-{i}")
|
||||||
# wait for the database to be ready
|
# wait for the database to be ready
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,8 @@ class LangFuseTracer(BaseTracer):
|
||||||
logger.exception("Could not import langfuse. Please install it with `pip install langfuse`.")
|
logger.exception("Could not import langfuse. Please install it with `pip install langfuse`.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Error setting up LangSmith tracer")
|
logger.debug(f"Error setting up LangSmith tracer: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class LangSmithTracer(BaseTracer):
|
||||||
self._run_tree.add_event({"name": "Start", "time": datetime.now(timezone.utc).isoformat()})
|
self._run_tree.add_event({"name": "Start", "time": datetime.now(timezone.utc).isoformat()})
|
||||||
self._children: dict[str, RunTree] = {}
|
self._children: dict[str, RunTree] = {}
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Error setting up LangSmith tracer")
|
logger.debug("Error setting up LangSmith tracer")
|
||||||
self._ready = False
|
self._ready = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class LangWatchTracer(BaseTracer):
|
||||||
type="workflow",
|
type="workflow",
|
||||||
)
|
)
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Error setting up LangWatch tracer")
|
logger.debug("Error setting up LangWatch tracer")
|
||||||
self._ready = False
|
self._ready = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,8 @@ class TracingService(Service):
|
||||||
await asyncio.to_thread(self._initialize_langsmith_tracer)
|
await asyncio.to_thread(self._initialize_langsmith_tracer)
|
||||||
await asyncio.to_thread(self._initialize_langwatch_tracer)
|
await asyncio.to_thread(self._initialize_langwatch_tracer)
|
||||||
await asyncio.to_thread(self._initialize_langfuse_tracer)
|
await asyncio.to_thread(self._initialize_langfuse_tracer)
|
||||||
except Exception: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug("Error initializing tracers")
|
logger.debug(f"Error initializing tracers: {e}")
|
||||||
|
|
||||||
def _initialize_langsmith_tracer(self) -> None:
|
def _initialize_langsmith_tracer(self) -> None:
|
||||||
project_name = os.getenv("LANGCHAIN_PROJECT", "Langflow")
|
project_name = os.getenv("LANGCHAIN_PROJECT", "Langflow")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue