Skip to content

Commit a860acf

Browse files
committed
Add Google GenAI and OpenAI instrumentation support in Langfuse integration
1 parent 1035709 commit a860acf

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

implementations/agentic_vqa_eval/src/agentic_chartqapro_eval/langfuse_integration/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
from dotenv import load_dotenv
1111
from langfuse import Langfuse
1212

13+
try:
14+
from openinference.instrumentation.google_genai import GoogleGenAIInstrumentor
15+
16+
_google_instrumentor = GoogleGenAIInstrumentor()
17+
except Exception:
18+
_google_instrumentor = None # type: ignore[assignment]
19+
20+
try:
21+
from openinference.instrumentation.openai import OpenAIInstrumentor
22+
23+
_openai_instrumentor = OpenAIInstrumentor()
24+
except Exception:
25+
_openai_instrumentor = None # type: ignore[assignment]
26+
1327

1428
_client = None
1529
_initialised = False
@@ -51,6 +65,14 @@ def get_client():
5165
kwargs["host"] = host
5266

5367
_client = Langfuse(**kwargs)
68+
# Activate OTel auto-instrumentation so provider SDK calls (Google GenAI,
69+
# OpenAI) are captured as detailed child spans inside Langfuse traces.
70+
if _google_instrumentor is not None:
71+
with suppress(Exception):
72+
_google_instrumentor.instrument()
73+
if _openai_instrumentor is not None:
74+
with suppress(Exception):
75+
_openai_instrumentor.instrument()
5476
except Exception as exc:
5577
print(f"[langfuse] client init failed: {exc}")
5678
_client = None

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ dependencies = [
3030
agentic-xai-eval = [
3131
"crewai>=1.6.1",
3232
"google-genai>=1.67.0",
33+
"openinference-instrumentation-google-genai>=0.1.0",
34+
"openinference-instrumentation-openai>=0.1.0",
3335
"streamlit>=1.55.0",
3436
]
3537
dev = [

0 commit comments

Comments
 (0)