Skip to main content
This example shows how to instrument a LangChain RAG (Retrieval-Augmented Generation) pipeline with OpenInference tracing.

Prerequisites

  • Python 3.9+
  • OpenAI API key
  • Phoenix or another OpenTelemetry collector

Installation

1

Install dependencies

2

Set environment variables

Complete Example

Advanced RAG Example

Here’s a more complete RAG pipeline with retrieval:

Key Features

Automatic Chain Tracing

LangChain instrumentation automatically traces:
  • Chains: All LCEL chains and legacy chain types
  • Retrievers: Vector store retrievals and custom retrievers
  • LLM calls: Chat models, completion models, and embeddings
  • Tools: Function calls and tool executions

Prompt Template Tracking

The instrumentation captures:
  • Template structure and variables
  • Partial variable substitutions
  • Final rendered prompts

Integration with LangGraph

The instrumentor also supports LangGraph for agentic workflows with state machines.

Next Steps