feat(loongsuite-instrumentation-langgraph): Add langgraph instrumentation to identify react agent#143
Merged
Cirilla-zmh merged 16 commits intoalibaba:mainfrom Mar 11, 2026
Conversation
- Add ExtendedTelemetryHandler with entry span and ReAct span support - Add propagation of session id and user id - Add _extended_common for shared types and utilities - Update gen_ai_extended_attributes for new span types - Add loongsuite workflows for CI Change-Id: I461f3febc206aea281741a01d00f38931483a4dc Co-developed-by: Cursor <noreply@cursor.com> Made-with: Cursor
Change-Id: I426ce98bc9e1eb2ebca2dfee5fbe0211d801809f Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: Idff7ed598bdeb7c9846ffcee171abcce3af32994 Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I78074851d283e36996c94a31bd51a00322f4325e Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I186113d97e1ca400434021fc487c4e587f05a1fa Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: Ib4bdeb22467225d136627702cbba86e6ff7c2425 Co-developed-by: Cursor <noreply@cursor.com>
- Add ExtendedTelemetryHandler with entry span and ReAct span support - Add propagation of session id and user id - Add _extended_common for shared types and utilities - Update gen_ai_extended_attributes for new span types - Add loongsuite workflows for CI Change-Id: I461f3febc206aea281741a01d00f38931483a4dc Co-developed-by: Cursor <noreply@cursor.com> Made-with: Cursor
- Add loongsuite-instrumentation-langgraph package - Patch create_react_agent to set _loongsuite_react_agent flag - Patch Pregel.stream/astream to inject metadata for LangChain tracer - Add tests for instrumentor, patch, and ReAct step spans - Update tox config for langgraph testing Change-Id: I8f1cba4f3f0e99842820815167fb6b03670cd184 Co-developed-by: Cursor <noreply@cursor.com> Made-with: Cursor
…attr Replace hardcoded string literals with the REACT_AGENT_METADATA_KEY constant for both the graph attribute and metadata injection, improving consistency. The constant and wrapper are kept local to the langgraph package (mirrored in langchain instrumentation) to avoid cross-package dependencies. Change-Id: Iea2171ac506269dfd3fac81c8663e2ecb0c9edfd Co-developed-by: Cursor <noreply@cursor.com> Made-with: Cursor
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new loongsuite-instrumentation-langgraph package that patches LangGraph’s ReAct agent entry points so LangChain instrumentation can correctly detect ReAct agents and emit Agent / ReAct Step spans.
Changes:
- Introduces a LangGraph instrumentor that wraps
create_react_agentandPregel.stream/astreamto propagate ReAct detection metadata. - Adds pytest coverage for patching behavior and ReAct-step span hierarchy.
- Extends tox and GitHub Actions workflows to lint/test the new instrumentation across supported Python versions.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tox-loongsuite.ini | Adds tox envs/deps/commands for langgraph instrumentation tests + lint. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/test_react_step_spans.py | Integration-style tests validating Agent/Step/LLM span creation and parenting. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/test_patch.py | Unit tests for wrapper patching / unpatching behavior. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/test_instrumentor.py | Basic lifecycle/dependencies tests for the new instrumentor. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/requirements.oldest.txt | Oldest test dependency set for the new package. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/requirements.latest.txt | Latest test dependency set for the new package. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/conftest.py | Test fixtures wiring OTel providers + installing both instrumentors. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/init.py | Test package marker (license header). |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/version.py | Introduces package version module. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/package.py | Declares _instruments metadata for the instrumentor. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/internal/patch.py | Implements wrapt wrappers for ReAct flagging + metadata injection. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/internal/init.py | Internal package marker (license header). |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/init.py | Implements LangGraphInstrumentor patch/unpatch logic. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/pyproject.toml | Defines new distribution metadata and OTel entry point. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/README.md | Documents installation, usage, and the patching data flow. |
| instrumentation-loongsuite/loongsuite-instrumentation-langgraph/CHANGELOG.md | Adds initial changelog entry for the new instrumentation. |
| copilot-instructions.md | Adds guidance around PLC0415 inline imports and naming conventions. |
| .github/workflows/loongsuite_test_0.yml | Adds CI matrix jobs for langgraph instrumentation tests. |
| .github/workflows/loongsuite_lint_0.yml | Adds CI job for langgraph instrumentation linting. |
Comments suppressed due to low confidence (1)
instrumentation-loongsuite/loongsuite-instrumentation-langgraph/README.md:1
- The README shows calling
instrument()anduninstrument()on two differentLangGraphInstrumentor()instances. It’s safer and more idiomatic to use the same instance for both (especially if patch state becomes instance-scoped as suggested), e.g. createinstrumentor = LangGraphInstrumentor()then callinstrumentor.instrument()/instrumentor.uninstrument().
# LongSuite LangGraph Instrumentation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/__init__.py
Outdated
Show resolved
Hide resolved
...loongsuite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/__init__.py
Outdated
Show resolved
Hide resolved
...uite-instrumentation-langgraph/src/opentelemetry/instrumentation/langgraph/internal/patch.py
Outdated
Show resolved
Hide resolved
instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/test_patch.py
Outdated
Show resolved
Hide resolved
instrumentation-loongsuite/loongsuite-instrumentation-langgraph/tests/conftest.py
Show resolved
Hide resolved
Change-Id: Ic0a6f4856fbde936feb7c6e6d5e2038d1d72849a Co-developed-by: Cursor <noreply@cursor.com>
This reverts commit fa0a402.
8 tasks
123liuziming
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary
This PR introduces OpenTelemetry instrumentation for LangGraph, enabling proper Agent and ReAct Step span creation when used together with the LangChain instrumentation.
Changes
New: LangGraph Instrumentation Package (loongsuite-instrumentation-langgraph)
create_react_agenttoset _loongsuite_react_agent = TrueonCompiledStateGraphPregel.stream/Pregel.astreamto injectmetadata["_loongsuite_react_agent"]intoRunnableConfig, so LangChain instrumentation can detect ReAct agents via callback metadatawrapt.wrap_function_wrapper(aligned withloongsuite-instrumentation-langchain)CI & Tooling
loongsuite_lint_0.ymlandloongsuite_test_0.ymlworkflowstox-loongsuite.inicopilot-instructions.mdFixes #136 (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.