File tree Expand file tree Collapse file tree
implementations/agentic_vqa_eval/src/agentic_chartqapro_eval/langfuse_integration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010from dotenv import load_dotenv
1111from 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
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ dependencies = [
3030agentic-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]
3537dev = [
You can’t perform that action at this time.
0 commit comments