Skip to main content
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.

Prerequisites

  • Python 3.8 or higher
  • Gentrace API key
  • OpenAI API key (or other LLM provider credentials)

Installation

Configuration

To enable Gentrace tracing with LangGraph, you need to set specific environment variables before importing any LangChain or LangGraph modules:
index.py
The OpenTelemetry environment variables must be set before importing LangChain or LangGraph modules. Setting them after imports will not enable tracing.

Usage Example

Here’s a complete example showing how to trace a LangGraph agent with Gentrace:
index.py

Environment Variables

Set these environment variables in your .env file:
.env

How It Works

Gentrace captures LangGraph traces by:
  1. Intercepting LangSmith traces: The OTEL environment variables redirect LangSmith’s built-in tracing to OpenTelemetry
  2. Capturing via OpenTelemetry: Gentrace’s OTEL integration automatically collects these traces
  3. Organizing with interactions: The @interaction decorator groups related agent executions
This approach provides zero-code-change tracing for existing LangGraph applications while maintaining full compatibility with LangGraph’s features.

Advanced Usage

Custom Agent Configurations

You can trace more complex agent setups with custom configurations:
advanced_agent.py

Multiple Agent Coordination

Track complex multi-agent systems:
multi_agent.py