Skip to main content
LangChain is a framework for building applications with LLMs. It provides agents, tools, chains, and integrations with model providers. HoneyHive integrates with LangChain through the OpenInference instrumentor, automatically capturing agent runs, tool calls, chain executions, and LLM interactions.

Quick Start

Add HoneyHive tracing in just 4 lines of code. Add this to your existing LangChain app and all agents, tools, and model calls are automatically traced.
pip install "honeyhive>=1.0.0rc0" langchain langchain-openai openinference-instrumentation-langchain
import os
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.langchain import LangChainInstrumentor

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
LangChainInstrumentor().instrument(tracer_provider=tracer.provider)

# Your existing LangChain code works unchanged

Compatibility

RequirementVersion
Python3.10+
langchain1.0.0+

What Gets Traced

The instrumentor automatically captures:
  • Agent runs - Every create_agent invocation with inputs and outputs
  • LLM calls - Model requests, responses, and token usage
  • Tool calls - Each tool execution with arguments and results
  • Chain operations - LCEL pipes and chain invocations
No manual instrumentation required.

Example: Single Agent with Tools

import os
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.langchain import LangChainInstrumentor
from langchain.agents import create_agent
from langchain_core.tools import tool

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
LangChainInstrumentor().instrument(tracer_provider=tracer.provider)

@tool
def calculator(expression: str) -> str:
    """Evaluate a basic arithmetic expression."""
    return str(eval(expression, {"__builtins__": {}}, {}))

@tool
def policy_lookup(topic: str) -> str:
    """Look up company policy on a topic."""
    policies = {
        "soc2": "SOC 2 focuses on security, availability, processing integrity, confidentiality, and privacy.",
        "retention": "Default retention is 30 days unless compliance requires longer.",
    }
    return policies.get(topic.lower(), "No policy found.")

agent = create_agent(
    model="openai:gpt-4o-mini",
    tools=[calculator, policy_lookup],
    system_prompt="You are a support assistant. Use tools when needed.",
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What is 17 * 3 + 5? Also summarize our SOC2 policy."}]}
)
print(result["messages"][-1].content)

Example: Multi-Agent Routing

import os
from honeyhive import HoneyHiveTracer, trace
from openinference.instrumentation.langchain import LangChainInstrumentor
from langchain.agents import create_agent
from langchain_core.tools import tool

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
LangChainInstrumentor().instrument(tracer_provider=tracer.provider)

@tool
def calculator(expression: str) -> str:
    """Evaluate arithmetic."""
    return str(eval(expression, {"__builtins__": {}}, {}))

@tool
def policy_lookup(topic: str) -> str:
    """Look up company policy."""
    policies = {"soc2": "SOC 2 covers security and privacy controls.", "retention": "30-day default."}
    return policies.get(topic.lower(), "No policy found.")

# Specialist agents
math_agent = create_agent(model="openai:gpt-4o-mini", tools=[calculator],
    system_prompt="You are a math specialist. Use calculator for all arithmetic.")

policy_agent = create_agent(model="openai:gpt-4o-mini", tools=[policy_lookup],
    system_prompt="You are a compliance specialist. Use policy_lookup for questions.")

coordinator = create_agent(model="openai:gpt-4o-mini", tools=[],
    system_prompt="Classify requests. Respond with one word: 'math' or 'policy'.")

@trace(event_type="chain", event_name="multi_agent_router", tracer=tracer)
def route_to_specialist(query: str) -> str:
    decision = coordinator.invoke({"messages": [{"role": "user", "content": query}]})
    route = decision["messages"][-1].content.strip().lower()
    chosen = "math" if "math" in route else "policy"

    tracer.enrich_span(metadata={"router_choice": chosen})

    agent = math_agent if chosen == "math" else policy_agent
    result = agent.invoke({"messages": [{"role": "user", "content": query}]})
    return result["messages"][-1].content

print(route_to_specialist("Compute 24 * 7"))
print(route_to_specialist("What is our retention policy?"))
In HoneyHive, you’ll see the full trace hierarchy: router decision, specialist agent delegation, tool executions, and LLM calls.

Troubleshooting

Traces not appearing

  1. Pass the tracer provider - The instrumentor must receive tracer_provider=tracer.provider:
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.langchain import LangChainInstrumentor

tracer = HoneyHiveTracer.init(project="your-project")

# Correct - pass tracer_provider
LangChainInstrumentor().instrument(tracer_provider=tracer.provider)

# Wrong - missing tracer_provider
LangChainInstrumentor().instrument()
  1. Check environment variables - Ensure HH_API_KEY and HH_PROJECT are set
  2. Initialize before creating agents - Call instrument() before instantiating LangChain agents

Using with LangGraph

LangGraph uses the same OpenInference LangChain instrumentor. If you’ve already set up LangChain instrumentation, LangGraph state graphs are automatically traced too. See the LangGraph integration for custom StateGraph patterns.

Resources