Skip to content

SGLang Tracing: Supports propagating trace headers through sgl.Engine…#15814

Merged
ishandhanani merged 1 commit intosgl-project:mainfrom
openanolis:sufeng-buaa/trace_header_for_engine
Dec 31, 2025
Merged

SGLang Tracing: Supports propagating trace headers through sgl.Engine…#15814
ishandhanani merged 1 commit intosgl-project:mainfrom
openanolis:sufeng-buaa/trace_header_for_engine

Conversation

@sufeng-buaa
Copy link
Collaborator

Motivation

Dynamo directly invokes SGLang through sgl.Engine, and thus cannot propagate trace context via request headers as in the HTTP API approach. Therefore, trace context must be explicitly propagated through the sgl.Engine interface.

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 enhances SGLang's tracing capabilities by enabling explicit propagation of trace context when the sgl.Engine is invoked directly, rather than through an HTTP API. This change introduces a new external_trace_header parameter to key sgl.Engine methods and updates internal data structures and tracing logic to ensure that trace information is consistently carried through the system, improving observability for direct engine interactions.

Highlights

  • Trace Context Propagation: Introduced explicit support for propagating trace headers through the sgl.Engine interface, addressing scenarios where direct engine invocation bypasses HTTP API header propagation.
  • API Interface Update: Added an external_trace_header parameter to the generate, async_generate, encode, and async_encode methods within sgl.Engine to allow callers to provide trace context directly.
  • Internal Data Structure Alignment: Updated internal request input structures (GenerateReqInput and EmbeddingReqInput) to include and propagate the external_trace_header throughout the request lifecycle.
  • Tracing Logic Integration: Modified the _trace_request_start function to prioritize external_trace_header from the request object for trace context if available, ensuring proper tracing even without HTTP headers.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 support for propagating trace headers through sgl.Engine by adding an external_trace_header parameter to generate, async_generate, encode, and async_encode methods. The changes are well-implemented and correctly propagate the trace context down to the tracing logic. I've also pointed out a pre-existing but related issue regarding tracing for embedding requests that could be addressed to make the tracing functionality more robust.

Comment on lines +801 to +802
# Propagates trace context via Engine.encode/async_encode
external_trace_header: Optional[Dict] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Renaming trace_context to external_trace_header is a good change for consistency with GenerateReqInput.

However, I noticed a related pre-existing issue. TokenizedEmbeddingReqInput is missing the trace_context field, which TokenizedGenerateReqInput has. This will likely cause an AttributeError in tokenizer_manager.py inside the _send_one_request method when it tries to set tokenized_obj.trace_context for embedding requests. Since this PR is focused on improving tracing, it would be a good opportunity to fix this to ensure tracing works correctly for embedding requests as well.

You could fix this by adding trace_context: Optional[Dict] = None to the TokenizedEmbeddingReqInput class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix the issue you mentioned in #13152.

@ishandhanani
Copy link
Collaborator

/tag-run-ci-label

… calls

Signed-off-by: Feng Su <sufeng@linux.alibaba.com>
@sufeng-buaa sufeng-buaa force-pushed the sufeng-buaa/trace_header_for_engine branch from 16e497b to 701ca46 Compare December 28, 2025 04:36
@ishandhanani
Copy link
Collaborator

Relevant tests have passed. I will test this with Dynamo and then merge

@ishandhanani ishandhanani merged commit 57d2ba9 into sgl-project:main Dec 31, 2025
95 of 104 checks passed
ishandhanani pushed a commit that referenced this pull request Dec 31, 2025
YChange01 pushed a commit to YChange01/sglang that referenced this pull request Jan 13, 2026
# tracing context
trace_context: Optional[Dict] = None
# Propagates trace context via Engine.encode/async_encode
external_trace_header: Optional[Dict] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants