[Bug fix] trace: fix import error in mini_lb if sgl-router image does not install sglang#12338
Conversation
…ll sglang Signed-off-by: Feng Su <sufeng@linux.alibaba.com>
Summary of ChangesHello @sufeng-buaa, 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 resolves a bug where 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.
Code Review
This pull request correctly fixes an ImportError when using mini_lb with tracing enabled in an environment where sglang is not installed. The fix involves adding try...except blocks to gracefully handle the missing dependency.
My review includes suggestions to refactor the implementation slightly. The goal is to improve encapsulation by moving all tracing-related logic for mini_lb into the MiniLoadBalancer class. This will make the code cleaner, remove redundancy, and make MiniLoadBalancer a more self-contained component. The proposed changes centralize the optional dependency check and initialization, improving maintainability.
| if router_args.enable_trace: | ||
| from sglang.srt.tracing.trace import ( | ||
| process_tracing_init, | ||
| trace_set_thread_info, | ||
| ) | ||
|
|
||
| process_tracing_init(router_args.otlp_traces_endpoint, "sglang") | ||
| trace_set_thread_info("Mini lb") | ||
| try: | ||
| from sglang.srt.tracing.trace import ( | ||
| process_tracing_init, | ||
| trace_set_thread_info, | ||
| ) | ||
|
|
||
| process_tracing_init(router_args.otlp_traces_endpoint, "sglang") | ||
| trace_set_thread_info("Mini lb") | ||
| except ImportError: | ||
| logger.warning( | ||
| "Tracing is not supported in this environment. Please install sglang." | ||
| ) |
There was a problem hiding this comment.
To improve encapsulation, the tracing initialization logic could be moved into the MiniLoadBalancer class. This would centralize all tracing-related code and make launch_router.py simpler, as it would no longer need to handle tracing setup for mini_lb. I've added a suggestion in mini_lb.py that demonstrates how to implement this. With that change, this entire if router_args.enable_trace: block is no longer needed.
There was a problem hiding this comment.
Should we set it to false when ImportError?
There was a problem hiding this comment.
I update code according to gemini-code-assist and set enable_trace to false when import error.
take a look again?
| self.prefill_bootstrap_ports = [url[1] for url in router_args.prefill_urls] | ||
| self.decode_urls = router_args.decode_urls | ||
| self.enable_trace = router_args.enable_trace | ||
| self.enable_trace = trace_package_imported and router_args.enable_trace |
There was a problem hiding this comment.
To better encapsulate tracing logic, you could handle the check for trace_package_imported here and log a warning if tracing is requested but unavailable. This makes MiniLoadBalancer more self-contained.
As part of this refactoring, I'd also recommend moving the tracing initialization logic (process_tracing_init and trace_set_thread_info) from launch_router.py into the start() method of this class. This would require storing otlp_traces_endpoint from router_args in __init__, as shown in the suggestion.
| self.enable_trace = trace_package_imported and router_args.enable_trace | |
| self.otlp_traces_endpoint = router_args.otlp_traces_endpoint | |
| self.enable_trace = router_args.enable_trace | |
| if self.enable_trace and not trace_package_imported: | |
| logger.warning( | |
| "Tracing is not supported in this environment. Please install sglang." | |
| ) | |
| self.enable_trace = False |
Signed-off-by: Feng Su <sufeng@linux.alibaba.com>
|
could you add a 'run_ci' tag please? @ShangmingCai |
|
it shouldnt depend on sglang at all |
|
CI failure is not related to this change everything else LGTM |
OK, I will implement a lightweight tracing package in mini_lb. |
Motivation
The tracing package is implemented in sglang, so if mini_lb wants to enable tracing, it needs to import sglang.srt.tracing.trace. However, if the sgl-router image does not include sglang, this will cause an import error in mini_lb.
Thanks for reporting this bug @jinmingyi1998
Modifications
In mini_lb, check whether the tracing package is imported successfully; if not, disable tracing forcefully.
Checklist