Skip to content

Commit 1fa93ec

Browse files
committed
feat: add optional logfire instrumentation for cloud mode distributed tracing
1 parent 73202d1 commit 1fa93ec

3 files changed

Lines changed: 233 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ dependencies = [
3737
"aiofiles>=24.1.0", # Async file I/O
3838
]
3939

40+
[project.optional-dependencies]
41+
cloud = [
42+
"logfire>=4.10.0", # Distributed tracing for cloud mode
43+
]
4044

4145
[project.urls]
4246
Homepage = "https://github.com/basicmachines-co/basic-memory"

src/basic_memory/api/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ async def lifespan(app: FastAPI): # pragma: no cover
3131
app_config = ConfigManager().config
3232
logger.info("Starting Basic Memory API")
3333

34+
# Instrument httpx client for distributed tracing when in cloud mode
35+
if app_config.cloud_mode_enabled:
36+
try:
37+
import logfire
38+
from basic_memory.mcp.async_client import client as httpx_client
39+
40+
logger.info("Cloud mode enabled - instrumenting httpx client for distributed tracing")
41+
logfire.instrument_httpx(client=httpx_client)
42+
except ImportError:
43+
logger.warning("logfire not available - skipping httpx instrumentation")
44+
3445
await initialize_app(app_config)
3546

3647
# Cache database connections in app state for performance

0 commit comments

Comments
 (0)