Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion backend/app/core/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import logging
from contextvars import ContextVar
from typing import Optional

from loguru import logger

Expand Down Expand Up @@ -36,6 +35,17 @@ def set_trace_id(trace_id: str) -> None:
trace_id_var.set(trace_id)


def _disable_agentbay_logger_override():
"""Disable AgentBay SDK's logging override to prevent it from resetting loguru."""
if "agentbay._common.logger" in sys.modules:
try:
from agentbay._common.logger import AgentBayLogger
AgentBayLogger._initialized = True
AgentBayLogger.setup = classmethod(lambda cls, *args, **kwargs: None)
except Exception:
pass


def configure_logging():
"""Configure loguru with custom format including trace ID."""
# Remove default handler
Expand All @@ -52,6 +62,8 @@ def configure_logging():
filter=lambda record: (record["extra"].setdefault("trace_id", get_trace_id() or str(uuid4())) is not None)
)

_disable_agentbay_logger_override()

return logger


Expand Down
8 changes: 6 additions & 2 deletions backend/app/services/agentbay_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from typing import Optional
from loguru import logger

from agentbay import AgentBay, BrowserOption, CreateSessionParams
from agentbay import AgentBay, CreateSessionParams
from app.core.logging_config import _disable_agentbay_logger_override, configure_logging

_disable_agentbay_logger_override()
configure_logging()


@dataclass
Expand Down Expand Up @@ -72,7 +76,7 @@ async def close_session(self):
return
try:
await asyncio.to_thread(self._session.delete)
logger.info(f"[AgentBay] Closed session")
logger.info("[AgentBay] Closed session")
except Exception as e:
logger.warning(f"[AgentBay] Failed to close session: {e}")
finally:
Expand Down