Integrate LangGraph agents with automatic Gentrace tracing via OpenTelemetry
Gentrace integrates with LangGraph by leveraging OpenTelemetry (OTEL) tracing to automatically capture and monitor your LangGraph agent executions, providing full observability into complex agent workflows and tool usage.
To enable Gentrace tracing with LangGraph, you need to set specific environment variables before importing any LangChain or LangGraph modules:
index.py
Copy
Ask AI
import os# Set OpenTelemetry environment variables BEFORE importing LangChain/LangGraphos.environ['LANGSMITH_OTEL_ENABLED'] = 'true'os.environ['LANGSMITH_OTEL_ONLY'] = 'true'os.environ['LANGSMITH_TRACING'] = 'true'# Now import the librariesimport gentracefrom gentrace import interactionfrom langgraph.prebuilt import create_react_agentfrom langchain_openai import ChatOpenAI# Initialize Gentracegentrace.init(api_key=os.getenv("GENTRACE_API_KEY"))
The OpenTelemetry environment variables must be set before importing LangChain or LangGraph modules. Setting them after imports will not enable tracing.