Skip to content

Commit 460097d

Browse files
authored
refactor(loongsuite-instrumentation-langchain): GenAI Util Migration & ReAct Step Support (#139)
1 parent edbc955 commit 460097d

35 files changed

+4436
-3446
lines changed

.github/workflows/loongsuite_lint_0.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ jobs:
108108
- name: Run tests
109109
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-google-adk
110110

111+
lint-loongsuite-instrumentation-langchain:
112+
name: LoongSuite loongsuite-instrumentation-langchain
113+
runs-on: ubuntu-latest
114+
timeout-minutes: 30
115+
steps:
116+
- name: Checkout repo @ SHA - ${{ github.sha }}
117+
uses: actions/checkout@v4
118+
119+
- name: Set up Python 3.13
120+
uses: actions/setup-python@v5
121+
with:
122+
python-version: "3.13"
123+
124+
- name: Install tox
125+
run: pip install tox-uv
126+
127+
- name: Run tests
128+
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-langchain
129+
111130
lint-loongsuite-instrumentation-mem0:
112131
name: LoongSuite loongsuite-instrumentation-mem0
113132
runs-on: ubuntu-latest

.github/workflows/loongsuite_test_0.yml

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,196 @@ jobs:
716716
- name: Run tests
717717
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-google-adk-latest -- -ra
718718

719+
py39-test-loongsuite-instrumentation-langchain-oldest_ubuntu-latest:
720+
name: LoongSuite loongsuite-instrumentation-langchain-oldest 3.9 Ubuntu
721+
runs-on: ubuntu-latest
722+
timeout-minutes: 30
723+
steps:
724+
- name: Checkout repo @ SHA - ${{ github.sha }}
725+
uses: actions/checkout@v4
726+
727+
- name: Set up Python 3.9
728+
uses: actions/setup-python@v5
729+
with:
730+
python-version: "3.9"
731+
732+
- name: Install tox
733+
run: pip install tox-uv
734+
735+
- name: Run tests
736+
run: tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-langchain-oldest -- -ra
737+
738+
py39-test-loongsuite-instrumentation-langchain-latest_ubuntu-latest:
739+
name: LoongSuite loongsuite-instrumentation-langchain-latest 3.9 Ubuntu
740+
runs-on: ubuntu-latest
741+
timeout-minutes: 30
742+
steps:
743+
- name: Checkout repo @ SHA - ${{ github.sha }}
744+
uses: actions/checkout@v4
745+
746+
- name: Set up Python 3.9
747+
uses: actions/setup-python@v5
748+
with:
749+
python-version: "3.9"
750+
751+
- name: Install tox
752+
run: pip install tox-uv
753+
754+
- name: Run tests
755+
run: tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-langchain-latest -- -ra
756+
757+
py310-test-loongsuite-instrumentation-langchain-oldest_ubuntu-latest:
758+
name: LoongSuite loongsuite-instrumentation-langchain-oldest 3.10 Ubuntu
759+
runs-on: ubuntu-latest
760+
timeout-minutes: 30
761+
steps:
762+
- name: Checkout repo @ SHA - ${{ github.sha }}
763+
uses: actions/checkout@v4
764+
765+
- name: Set up Python 3.10
766+
uses: actions/setup-python@v5
767+
with:
768+
python-version: "3.10"
769+
770+
- name: Install tox
771+
run: pip install tox-uv
772+
773+
- name: Run tests
774+
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-langchain-oldest -- -ra
775+
776+
py310-test-loongsuite-instrumentation-langchain-latest_ubuntu-latest:
777+
name: LoongSuite loongsuite-instrumentation-langchain-latest 3.10 Ubuntu
778+
runs-on: ubuntu-latest
779+
timeout-minutes: 30
780+
steps:
781+
- name: Checkout repo @ SHA - ${{ github.sha }}
782+
uses: actions/checkout@v4
783+
784+
- name: Set up Python 3.10
785+
uses: actions/setup-python@v5
786+
with:
787+
python-version: "3.10"
788+
789+
- name: Install tox
790+
run: pip install tox-uv
791+
792+
- name: Run tests
793+
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-langchain-latest -- -ra
794+
795+
py311-test-loongsuite-instrumentation-langchain-oldest_ubuntu-latest:
796+
name: LoongSuite loongsuite-instrumentation-langchain-oldest 3.11 Ubuntu
797+
runs-on: ubuntu-latest
798+
timeout-minutes: 30
799+
steps:
800+
- name: Checkout repo @ SHA - ${{ github.sha }}
801+
uses: actions/checkout@v4
802+
803+
- name: Set up Python 3.11
804+
uses: actions/setup-python@v5
805+
with:
806+
python-version: "3.11"
807+
808+
- name: Install tox
809+
run: pip install tox-uv
810+
811+
- name: Run tests
812+
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-langchain-oldest -- -ra
813+
814+
py311-test-loongsuite-instrumentation-langchain-latest_ubuntu-latest:
815+
name: LoongSuite loongsuite-instrumentation-langchain-latest 3.11 Ubuntu
816+
runs-on: ubuntu-latest
817+
timeout-minutes: 30
818+
steps:
819+
- name: Checkout repo @ SHA - ${{ github.sha }}
820+
uses: actions/checkout@v4
821+
822+
- name: Set up Python 3.11
823+
uses: actions/setup-python@v5
824+
with:
825+
python-version: "3.11"
826+
827+
- name: Install tox
828+
run: pip install tox-uv
829+
830+
- name: Run tests
831+
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-langchain-latest -- -ra
832+
833+
py312-test-loongsuite-instrumentation-langchain-oldest_ubuntu-latest:
834+
name: LoongSuite loongsuite-instrumentation-langchain-oldest 3.12 Ubuntu
835+
runs-on: ubuntu-latest
836+
timeout-minutes: 30
837+
steps:
838+
- name: Checkout repo @ SHA - ${{ github.sha }}
839+
uses: actions/checkout@v4
840+
841+
- name: Set up Python 3.12
842+
uses: actions/setup-python@v5
843+
with:
844+
python-version: "3.12"
845+
846+
- name: Install tox
847+
run: pip install tox-uv
848+
849+
- name: Run tests
850+
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-langchain-oldest -- -ra
851+
852+
py312-test-loongsuite-instrumentation-langchain-latest_ubuntu-latest:
853+
name: LoongSuite loongsuite-instrumentation-langchain-latest 3.12 Ubuntu
854+
runs-on: ubuntu-latest
855+
timeout-minutes: 30
856+
steps:
857+
- name: Checkout repo @ SHA - ${{ github.sha }}
858+
uses: actions/checkout@v4
859+
860+
- name: Set up Python 3.12
861+
uses: actions/setup-python@v5
862+
with:
863+
python-version: "3.12"
864+
865+
- name: Install tox
866+
run: pip install tox-uv
867+
868+
- name: Run tests
869+
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-langchain-latest -- -ra
870+
871+
py313-test-loongsuite-instrumentation-langchain-oldest_ubuntu-latest:
872+
name: LoongSuite loongsuite-instrumentation-langchain-oldest 3.13 Ubuntu
873+
runs-on: ubuntu-latest
874+
timeout-minutes: 30
875+
steps:
876+
- name: Checkout repo @ SHA - ${{ github.sha }}
877+
uses: actions/checkout@v4
878+
879+
- name: Set up Python 3.13
880+
uses: actions/setup-python@v5
881+
with:
882+
python-version: "3.13"
883+
884+
- name: Install tox
885+
run: pip install tox-uv
886+
887+
- name: Run tests
888+
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-langchain-oldest -- -ra
889+
890+
py313-test-loongsuite-instrumentation-langchain-latest_ubuntu-latest:
891+
name: LoongSuite loongsuite-instrumentation-langchain-latest 3.13 Ubuntu
892+
runs-on: ubuntu-latest
893+
timeout-minutes: 30
894+
steps:
895+
- name: Checkout repo @ SHA - ${{ github.sha }}
896+
uses: actions/checkout@v4
897+
898+
- name: Set up Python 3.13
899+
uses: actions/setup-python@v5
900+
with:
901+
python-version: "3.13"
902+
903+
- name: Install tox
904+
run: pip install tox-uv
905+
906+
- name: Run tests
907+
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-langchain-latest -- -ra
908+
719909
py310-test-loongsuite-instrumentation-mem0-oldest_ubuntu-latest:
720910
name: LoongSuite loongsuite-instrumentation-mem0-oldest 3.10 Ubuntu
721911
runs-on: ubuntu-latest

instrumentation-loongsuite/loongsuite-instrumentation-langchain/CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- ReAct Step instrumentation for AgentExecutor
13+
([#139](https://github.com/alibaba/loongsuite-python-agent/pull/139))
14+
- Monkey-patch `AgentExecutor._iter_next_step` and `_aiter_next_step` to instrument each ReAct iteration
15+
- Dual patch: patch both `langchain.agents` (0.x) and `langchain_classic.agents` (1.x) when available, so either import path works
16+
- Covers invoke, ainvoke, stream, astream, batch, abatch
17+
- ReAct Step spans: `gen_ai.span.kind=STEP`, `gen_ai.operation.name=react`, `gen_ai.react.round`, `gen_ai.react.finish_reason`
18+
- Span hierarchy: Agent > ReAct Step > LLM/Tool
19+
20+
- LangGraph ReAct agent support (requires `loongsuite-instrumentation-langgraph`)
21+
([#139](https://github.com/alibaba/loongsuite-python-agent/pull/139))
22+
- Detect LangGraph agents via `Run.metadata["_loongsuite_react_agent"]`
23+
(metadata injected by the LangGraph instrumentation)
24+
- Disambiguate the top-level graph (Agent span) from child nodes (chain
25+
spans) using `inside_langgraph_react` propagation
26+
- Agent name resolution: when the ReAct agent is invoked inside an outer
27+
graph node, inherit the node's name (e.g. `invoke_agent product_agent`)
28+
instead of the generic default (`invoke_agent LangGraph`)
29+
- Track ReAct step boundaries via callback-based detection of the
30+
`"agent"` node within the graph
31+
- Span hierarchy: Agent > ReAct Step > LLM/Tool (same as AgentExecutor)
32+
33+
### Breaking Changes
34+
35+
- Rewrite the instrumentation for LangChain with `genai-util`
36+
([#139](https://github.com/alibaba/loongsuite-python-agent/pull/139))
37+
- Replaced the legacy `wrapt`-based function wrapping with `BaseTracer` callback mechanism
38+
- Migrated to `ExtendedTelemetryHandler` from `opentelemetry-util-genai` for standardized GenAI semantic conventions
39+
- Added Agent detection by `run.name`, TTFT tracking, content capture gating, and `RLock` thread safety
40+
- Added new test suite with `oldest`/`latest` dependency matrices
41+
1042
## Version 0.1.0 (2026-02-28)
1143

1244
### Added

0 commit comments

Comments
 (0)