Skip to content

Commit 6975e69

Browse files
authored
Merge pull request #2298 from anouar-bm/feat/langfuse-observability
feat: Add optional Langfuse observability integration
2 parents e0966b6 + 9495778 commit 6975e69

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lightrag/llm/openai.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
pm.install("openai")
1212

1313
from openai import (
14-
AsyncOpenAI,
1514
APIConnectionError,
1615
RateLimitError,
1716
APITimeoutError,
@@ -27,6 +26,19 @@
2726
safe_unicode_decode,
2827
logger,
2928
)
29+
30+
# Try to import Langfuse for LLM observability (optional)
31+
# Falls back to standard OpenAI client if not available
32+
try:
33+
from langfuse.openai import AsyncOpenAI
34+
35+
LANGFUSE_ENABLED = True
36+
logger.info("Langfuse observability enabled for OpenAI client")
37+
except ImportError:
38+
from openai import AsyncOpenAI
39+
40+
LANGFUSE_ENABLED = False
41+
logger.debug("Langfuse not available, using standard OpenAI client")
3042
from lightrag.types import GPTKeywordExtractionFormat
3143
from lightrag.api import __api_version__
3244

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ offline = [
113113
"lightrag-hku[offline-docs,offline-storage,offline-llm]",
114114
]
115115

116+
observability = [
117+
# LLM observability and tracing dependencies
118+
"langfuse>=3.8.1",
119+
]
120+
116121
[project.scripts]
117122
lightrag-server = "lightrag.api.lightrag_server:main"
118123
lightrag-gunicorn = "lightrag.api.run_with_gunicorn:main"

0 commit comments

Comments
 (0)