Skip to main content

LoongSuite LangGraph Instrumentation

Project description

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+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file loongsuite_instrumentation_langgraph-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for loongsuite_instrumentation_langgraph-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bed3f7979139b04d98ae1f0f41a2bf9bf258e784604b9f29a3c32b96b83a53c
MD5 24bd4d186e023bc4b016feaedc850f0d
BLAKE2b-256 ec5addc0349bcde784d9bd015175c483f7123b64f3b3e48fea2b60dfd1401b70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page