Skip to main content

LongSuLoongSuiteite LangGraph Instrumentation

LoongSuite instrumentation for LangGraph.

Installation

# Step 1: install LoongSuite distro
pip install loongsuite-distro

# Step 2 (Option C): install this instrumentation from PyPI
pip install loongsuite-instrumentation-langgraph

Usage

from opentelemetry.instrumentation.langgraph import LangGraphInstrumentor

LangGraphInstrumentor().instrument()

What it does

This instrumentation patches two targets to enable LangChain instrumentation (loongsuite-instrumentation-langchain) to recognise LangGraph ReAct agents and create proper Agent / ReAct Step spans.

All patches use wrapt.wrap_function_wrapper (consistent with loongsuite-instrumentation-langchain).

1. create_react_agent patch

Wraps langgraph.prebuilt.create_react_agent to set a boolean flag _loongsuite_react_agent = True on the compiled CompiledStateGraph. The flag itself is not accessible inside LangChain's callback system — it only serves as the trigger for the second patch below.

2. Pregel.stream / Pregel.astream patch

Wraps the graph execution entry points so that when a graph carrying _loongsuite_react_agent = True is invoked, the metadata {"_loongsuite_react_agent": True} is injected into the RunnableConfig before execution begins.

The data flow:

graph._loongsuite_react_agent = True       # set by patch 1
            │
            ▼
Pregel.stream() wrapper intercepts call    # patch 2
            │
            ▼
config["metadata"]["_loongsuite_react_agent"] = True
            │
            ▼
LangChain callback manager reads metadata
            │
            ▼
Run.metadata["_loongsuite_react_agent"]    # LoongsuiteTracer reads this

LangChain's callback system automatically propagates config["metadata"] to all child callbacks, so every sub-node within the graph also carries the flag. The LoongsuiteTracer disambiguates the top-level graph (Agent span) from child nodes (chain spans) by tracking an internal inside_langgraph_react flag that propagates through the run hierarchy.

Pregel.invoke() / ainvoke() internally delegate to stream / astream, so only the latter two need to be patched.

How it works with LangChain instrumentation

When both instrumentors are active, the LoongsuiteTracer in the LangChain instrumentation:

  1. Detects the agent — _has_langgraph_react_metadata(run) checks Run.metadata for the flag. If the parent is not already inside a LangGraph agent, this run becomes an Agent span.

  2. Resolves agent name — when the ReAct agent is invoked inside an outer graph node (e.g. product_agent), the agent span inherits the node's name (invoke_agent product_agent) instead of the generic default (invoke_agent LangGraph).

  3. Tracks ReAct steps — each time the "agent" node fires inside the graph, a new ReAct Step span is created, with the hierarchy: Agent > ReAct Step > LLM / Tool.

Compatibility

  • langgraph >= 0.2
  • langchain_core >= 0.1.0
  • Python 3.9+

Metadata

Release files for loongsuite-instrumentation-langgraph 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for loongsuite-instrumentation-langgraph 0.9.0
File Interpreter ABI Platform
loongsuite_instrumentation_langgraph-0.9.0-py3-none-any.whl Python 3 none any Details

Release files / loongsuite_instrumentation_langgraph-0.9.0-py3-none-any.whl

Download URL loongsuite_instrumentation_langgraph-0.9.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e4a33210a08bf3bdaa870089fb0b41319e4ae836a09e6eee30f95477f165fe2
BLAKE2b-256 checksum
How to use checksums
96fb823dba098fa21ecec9b58971514d537385d895a5274f42224ead0ef2d693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.9.0 This release

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page