-
Notifications
You must be signed in to change notification settings - Fork 42
feat: add trace to log #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughA centralized wrapper (wrapGraphMethod) was added to CompiledStateGraphObject to apply tracing and ensure runId for graph.invoke/graph.stream. getTracer() was added to obtain the tracer from Egg context. Plugin test fixture and a unit test were updated to enable and assert tracing. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Wrapper as wrapGraphMethod
participant EggCtx as Egg Context
participant Tracer as LangGraphTracer
participant Original as Original graph.invoke/stream
Client->>Wrapper: invoke/stream(input, config)
activate Wrapper
Wrapper->>EggCtx: get tracer instance
EggCtx-->>Wrapper: tracer (if available)
alt trace-log enabled
Wrapper->>Tracer: configure tracer & ensure runId in config
end
Wrapper->>Original: call originalMethod(input, config)
activate Original
Original-->>Wrapper: result
deactivate Original
Wrapper-->>Client: result
deactivate Wrapper
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @akitaSummer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the observability of LangChain graph executions within the Egg.js framework. It introduces a standardized and context-aware mechanism for integrating tracing into the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces tracing for LangChain graphs by wrapping invoke and stream methods. The refactoring to a common wrapGraphMethod is a good improvement for code clarity and maintainability. However, there are a couple of areas for improvement:
- The implementation of
wrapGraphMethodcan be made more efficient by caching theLangGraphTracerinstance. - There's a potential runtime error in
getTracerdue to unsafe context access.
My review includes specific suggestions to address these points for better performance and robustness. The change to enable the tracer plugin in the test configuration is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
plugin/langchain/lib/graph/CompiledStateGraphObject.ts (1)
40-51: Unused tracer setup ininit()— consider removing.Lines 42-44 fetch a tracer and set its name, but this tracer instance is never used afterward. The
wrapGraphMethodcreates its own tracer instance when tracing is enabled. This appears to be leftover code from the previous implementation.🔧 Suggested fix
const originalInvoke = graph.invoke; const originalStream = graph.stream; - const langGraphTraceObj = await EggContainerFactory.getOrCreateEggObjectFromName('langGraphTracer'); - const tracer = langGraphTraceObj.obj as LangGraphTracer; - tracer.setName(this.graphName); graph.invoke = (input: any, config?: any) => this.wrapGraphMethod(originalInvoke.bind(graph), input, config); graph.stream = (input: any, config?: any) => this.wrapGraphMethod(originalStream.bind(graph), input, config);
🤖 Fix all issues with AI agents
In `@plugin/langchain/lib/graph/CompiledStateGraphObject.ts`:
- Around line 147-150: getTracer uses a non-null assertion on
ContextHandler.getContext() and assumes ctx and ctx.tracer exist, which can
throw at runtime; update getTracer to defensively fetch the context (call
ContextHandler.getContext() without "!"), check that the returned context and
its EGG_CONTEXT entry exist, and either return undefined (or a safe default) or
throw a descriptive error if missing, then access and return ctx.tracer only
after those checks; reference the getTracer method, ContextHandler.getContext,
EGG_CONTEXT and ctx.tracer when making the changes.
- Around line 120-145: wrapGraphMethod currently assigns finalConfig = config ||
{} which lets you mutate the caller's config; change it to make a shallow copy
(e.g., const finalConfig = { ...(config || {}) }) so modifications to runId,
callbacks, etc. don't affect the original object, and when you prepend tracer to
finalConfig.callbacks ensure you create a new array (e.g., finalConfig.callbacks
= [tracer, ...(finalConfig.callbacks || [])]) so the original callbacks array is
not mutated; update the logic in wrapGraphMethod (referencing finalConfig,
originalMethod, and callbacks/runId) accordingly.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugin/langchain/lib/graph/CompiledStateGraphObject.tsplugin/langchain/test/fixtures/apps/langchain/config/plugin.js
🧰 Additional context used
📓 Path-based instructions (3)
**/test/fixtures/**
📄 CodeRabbit inference engine (CLAUDE.md)
Store test fixtures in 'test/fixtures/' directories within packages
Files:
plugin/langchain/test/fixtures/apps/langchain/config/plugin.js
plugin/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Framework internal code in plugin packages should import types from '@eggjs/tegg-types' and decorators from '@eggjs/core-decorator'
Files:
plugin/langchain/lib/graph/CompiledStateGraphObject.ts
plugin/*/lib/**/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Plugin services and lifecycle hooks should be implemented in files within the 'lib/' directory
Files:
plugin/langchain/lib/graph/CompiledStateGraphObject.ts
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Egg-specific subclasses extending core wrappers should be implemented in plugin packages and add context tracking and tegg-specific behavior
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Use 'eggjs/tegg/helper' for internal APIs like ModuleConfigUtil, LoaderFactory, and EggObjectLifeCycleContext in advanced usage scenarios
Applied to files:
plugin/langchain/test/fixtures/apps/langchain/config/plugin.jsplugin/langchain/lib/graph/CompiledStateGraphObject.ts
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Create subpath exports in 'eggjs/tegg' for optional features (aop, orm, dal, schedule, transaction, ajv, helper, standalone)
Applied to files:
plugin/langchain/test/fixtures/apps/langchain/config/plugin.js
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Applies to core/tegg/index.ts : Re-export core decorator, runtime, and type functionality from the main 'eggjs/tegg' package index.ts
Applied to files:
plugin/langchain/test/fixtures/apps/langchain/config/plugin.jsplugin/langchain/lib/graph/CompiledStateGraphObject.ts
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Always import decorators, enums, and public APIs from 'eggjs/tegg' in application code
Applied to files:
plugin/langchain/test/fixtures/apps/langchain/config/plugin.jsplugin/langchain/lib/graph/CompiledStateGraphObject.ts
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Applies to core/**/*.{ts,tsx} : Framework internal code in core packages should import types from 'eggjs/tegg-types' and decorators from 'eggjs/core-decorator'
Applied to files:
plugin/langchain/lib/graph/CompiledStateGraphObject.ts
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Applies to plugin/**/*.{ts,tsx} : Framework internal code in plugin packages should import types from 'eggjs/tegg-types' and decorators from 'eggjs/core-decorator'
Applied to files:
plugin/langchain/lib/graph/CompiledStateGraphObject.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Runner-macos (20)
- GitHub Check: Runner-macos (16)
- GitHub Check: Runner-ubuntu (18)
- GitHub Check: Analyze (javascript)
- GitHub Check: Runner-ubuntu (20)
- GitHub Check: Runner-ubuntu (16)
- GitHub Check: Analyze (typescript)
- GitHub Check: Runner-macos (18)
🔇 Additional comments (2)
plugin/langchain/test/fixtures/apps/langchain/config/plugin.js (1)
31-35: LGTM!The tracer plugin configuration follows the established pattern of other exports in this file and correctly enables
egg-tracerfor testing the new tracing functionality. As per coding guidelines, this test fixture is appropriately placed in thetest/fixtures/directory.plugin/langchain/lib/graph/CompiledStateGraphObject.ts (1)
14-14: LGTM!Import of
EGG_CONTEXTfrom@eggjs/egg-module-commonis appropriate for accessing the Egg context in the newgetTracer()method.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@plugin/langchain/test/llm.test.ts`:
- Line 4: Replace the fragile internal import of Tracer by changing the import
statement that currently reads import Tracer from 'egg-tracer/lib/tracer' to
import Tracer from 'egg-tracer' so the test uses the public API (update the
import for the Tracer symbol in llm.test.ts).
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugin/langchain/test/llm.test.ts
🧰 Additional context used
📓 Path-based instructions (3)
plugin/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Framework internal code in plugin packages should import types from '@eggjs/tegg-types' and decorators from '@eggjs/core-decorator'
Files:
plugin/langchain/test/llm.test.ts
**/test/**/*.{test,spec}.{ts,js}
📄 CodeRabbit inference engine (CLAUDE.md)
Test files should be located in 'test/' directories within each package and use Mocha
Files:
plugin/langchain/test/llm.test.ts
plugin/**/*.test.{ts,js}
📄 CodeRabbit inference engine (CLAUDE.md)
Use 'egg-mock' with 'app.mockModuleContextScope()' for testing plugin modules in isolation
Files:
plugin/langchain/test/llm.test.ts
🧠 Learnings (2)
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Applies to plugin/**/*.test.{ts,js} : Use 'egg-mock' with 'app.mockModuleContextScope()' for testing plugin modules in isolation
Applied to files:
plugin/langchain/test/llm.test.ts
📚 Learning: 2026-01-10T12:35:11.421Z
Learnt from: CR
Repo: eggjs/tegg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T12:35:11.421Z
Learning: Create subpath exports in 'eggjs/tegg' for optional features (aop, orm, dal, schedule, transaction, ajv, helper, standalone)
Applied to files:
plugin/langchain/test/llm.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Runner-ubuntu (16)
- GitHub Check: Runner-macos (20)
- GitHub Check: Runner-macos (18)
- GitHub Check: Runner-macos (16)
- GitHub Check: Runner-ubuntu (20)
- GitHub Check: Runner-ubuntu (18)
- GitHub Check: Analyze (javascript)
- GitHub Check: Analyze (typescript)
🔇 Additional comments (1)
plugin/langchain/test/llm.test.ts (1)
74-83: LGTM!The test correctly:
- Captures logs with
app.mockLog()- Stubs
Tracer.prototype.traceIdto provide a deterministic trace ID- Asserts the traceId appears in the log output
The mock is properly cleaned up by the existing
mm.restore()inafterEach. This effectively validates the new tracing integration.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
killagu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Checklist
npm testpassesAffected core subsystem(s)
Description of change
Summary by CodeRabbit
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.