refactor(loongsuite-instrumentation-langchain): GenAI Util Migration & ReAct Step Support#139
Merged
Cirilla-zmh merged 14 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
…ndler - Integrate ExtendedTelemetryHandler for improved telemetry - Refactor LoongsuiteTracer with context propagation and content capture - Add ReAct step patch for langchain_classic - Refactor semconv and utility functions - Reorganize tests (chain, LLM, tool, retriever spans) - Update tox config for langchain testing Change-Id: I7c09df91dadd9d8ea75afba6502f6513fad800ad Co-developed-by: Cursor <noreply@cursor.com> Made-with: Cursor
Change-Id: I426ce98bc9e1eb2ebca2dfee5fbe0211d801809f Co-developed-by: Cursor <noreply@cursor.com>
…marking Add instrumentation for langchain.agents.create_agent (the new home of create_react_agent after LangGraph v1.0 deprecation). The wrapper marks the returned graph with _loongsuite_react_agent=True so that the langgraph Pregel stream/astream wrapper can inject metadata. Change-Id: Ie6a869ab107e0c91a55e6d2d79212f45d9234646 Co-developed-by: Cursor <noreply@cursor.com> Made-with: Cursor
Change-Id: Idff7ed598bdeb7c9846ffcee171abcce3af32994 Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I78074851d283e36996c94a31bd51a00322f4325e Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: Ie6441ccd1be48d60b3a8740774ad1a290afe8d3f Co-developed-by: Cursor <noreply@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors loongsuite-instrumentation-langchain to use opentelemetry-util-genai via ExtendedTelemetryHandler and adds ReAct step instrumentation for AgentExecutor and LangGraph agents. The legacy wrapt-based function wrapping is replaced with a BaseTracer callback mechanism, and old tests are removed in favor of a new test suite.
Changes:
- Replaced legacy tracer with
ExtendedTelemetryHandler-basedLoongsuiteTracer, adding support for LLM, Chain, Agent, Tool, Retriever, and ReAct Step spans with GenAI semantic conventions - Added monkey-patching of
AgentExecutor._iter_next_step/_aiter_next_stepfor ReAct step instrumentation, plus LangGraph agent detection via metadata propagation - Rewrote test suite (~107 tests) with shared
conftest.pyfixtures, oldest/latest dependency matrices, and updated CI workflows
Reviewed changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
tox-loongsuite.ini |
Enable langchain tests with oldest/latest matrix |
tests/conftest.py |
Shared pytest fixtures for instrumentation and export |
tests/test_basic.py |
Basic tracer injection and chain span tests |
tests/test_llm_spans.py |
LLM span creation and attribute tests |
tests/test_chain_spans.py |
Chain span creation and content tests |
tests/test_tool_spans.py |
Tool span creation and content tests |
tests/test_retriever_spans.py |
Retriever span creation and content tests |
tests/test_agent_spans.py |
Agent detection unit tests |
tests/test_react_step_patch.py |
ReAct step patch application and span tests |
tests/test_data_extraction.py |
Unit tests for data extraction helpers |
tests/test_instrumentor.py |
Instrumentor lifecycle tests |
tests/test_langchain_instrumentor.py |
Integration tests with RetrievalQA and ChatOpenAI |
tests/requirements.oldest.txt |
Oldest dependency pins for test matrix |
tests/requirements.latest.txt |
Latest dependency pins for test matrix |
internal/semconv.py |
Simplified to re-export from util-genai |
internal/_utils.py |
Refactored data extraction helpers |
internal/_tracer.py |
New LoongsuiteTracer based on BaseTracer and ExtendedTelemetryHandler |
internal/patch.py |
ReAct step monkey-patch for AgentExecutor |
__init__.py |
Instrumentor with agent executor and create_agent patching |
pyproject.toml |
Updated dependencies and metadata |
README.md |
Updated usage docs and traced operations table |
CHANGELOG.md |
Documented breaking changes and new features |
.github/workflows/loongsuite_test_0.yml |
CI test jobs for langchain oldest/latest |
.github/workflows/loongsuite_lint_0.yml |
CI lint job for langchain |
| Deleted old test files | Removed legacy test files under tests/instrumentation/langchain/ |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
instrumentation-loongsuite/loongsuite-instrumentation-langchain/tests/requirements.oldest.txt
Show resolved
Hide resolved
...loongsuite-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/__init__.py
Outdated
Show resolved
Hide resolved
...te-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py
Outdated
Show resolved
Hide resolved
instrumentation-loongsuite/loongsuite-instrumentation-langchain/CHANGELOG.md
Outdated
Show resolved
Hide resolved
instrumentation-loongsuite/loongsuite-instrumentation-langchain/tests/test_retriever_spans.py
Outdated
Show resolved
Hide resolved
...te-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py
Outdated
Show resolved
Hide resolved
...loongsuite-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/__init__.py
Outdated
Show resolved
Hide resolved
...te-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py
Outdated
Show resolved
Hide resolved
...te-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py
Show resolved
Hide resolved
...te-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py
Outdated
Show resolved
Hide resolved
...ite-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_utils.py
Outdated
Show resolved
Hide resolved
...te-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py
Show resolved
Hide resolved
Change-Id: Ic7d735e506e29f944cd1c4d3e66ca7e2f0abf529 Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I721d0559c0fcda61c93859295ba3b9a77c62e4c5 Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I186113d97e1ca400434021fc487c4e587f05a1fa Co-developed-by: Cursor <noreply@cursor.com>
123liuziming
approved these changes
Mar 11, 2026
Change-Id: Ib4bdeb22467225d136627702cbba86e6ff7c2425 Co-developed-by: Cursor <noreply@cursor.com>
8 tasks
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
Refactors
loongsuite-instrumentation-langchainto useopentelemetry-util-genaiand adds ReAct step instrumentation for AgentExecutor and LangGraph agents.Key Changes
Architecture
wrapt-based function wrapping with LangChainBaseTracercallback mechanismExtendedTelemetryHandlerfromopentelemetry-util-genaifor standardized GenAI semantic conventionsRLockfor thread safety in tracer callbacksReAct Step Instrumentation
AgentExecutor._iter_next_stepand_aiter_next_stepto instrument each ReAct iterationlangchain.agents(0.x) andlangchain_classic.agents(1.x) when availablegen_ai.span.kind=STEP,gen_ai.operation.name=react,gen_ai.react.round,gen_ai.react.finish_reasonLangGraph ReAct Agent Support
Run.metadata["_loongsuite_react_agent"](injected by langgraph instrumentation)langchain.agents.create_agentto mark ReAct graphs (langchain ≥ 1.x)inside_langgraph_reactpropagationinvoke_agent product_agent) instead of genericinvoke_agent LangGraph"agent"node within the graphOther Improvements
Breaking Changes
Testing & CI
oldest/latestdependency matricesFixes #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.