Skip to content

[Feature] Propagate Trace Headers into Root Span for OpenTelemetry Cross-Service Context#10808

Merged
hnyls2002 merged 5 commits intosgl-project:mainfrom
zhanghaotong:tracing-add-trace-headers
Nov 12, 2025
Merged

[Feature] Propagate Trace Headers into Root Span for OpenTelemetry Cross-Service Context#10808
hnyls2002 merged 5 commits intosgl-project:mainfrom
zhanghaotong:tracing-add-trace-headers

Conversation

@zhanghaotong
Copy link
Copy Markdown
Contributor

Motivation

Propagate trace headers from upstream requests into the engine trace’s root span to enable OpenTelemetry cross-service context propagation.

Modifications

Extract traceparent and tracestate from HTTP request headers, construct a trace_headers dict, and pass it as the context when starting the request’s root span.

Checklist

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zhanghaotong, 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 the tracing capabilities by implementing OpenTelemetry cross-service context propagation. It modifies the request handling pipeline to capture and utilize trace headers from incoming HTTP requests, ensuring that distributed tracing information is correctly maintained and linked across different services. This change is fundamental for better observability and debugging in a microservices architecture.

Highlights

  • OpenTelemetry Cross-Service Context Propagation: This pull request introduces the capability to propagate OpenTelemetry trace headers from incoming HTTP requests into the root span of the engine's traces, enabling seamless cross-service context propagation.
  • Trace Header Extraction: The system now extracts 'traceparent' and 'tracestate' headers from HTTP requests, which are crucial for linking distributed traces.
  • Root Span Context Integration: The extracted trace headers are used to construct the context for the root span when a new request trace is started, ensuring that the trace continues from the upstream service.
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

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
Copy Markdown
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 correctly implements the propagation of OpenTelemetry trace headers from incoming requests to the engine's root span, which is crucial for enabling cross-service context propagation. The changes are well-structured, adding a new field to GenerateReqInput and modifying the trace initialization logic accordingly. I have a couple of suggestions to improve performance and code clarity. Specifically, I recommend making _get_trace_headers a synchronous method and instantiating TraceContextTextMapPropagator only once at the module level to avoid unnecessary overhead on each request.

Comment thread python/sglang/srt/entrypoints/openai/serving_base.py Outdated
Comment thread python/sglang/srt/tracing/trace.py Outdated
@zhanghaotong

This comment was marked as outdated.

@zhanghaotong
Copy link
Copy Markdown
Contributor Author

I've implemented support for trace part2; Could you please help review this PR? @sufeng-buaa

@sufeng-buaa
Copy link
Copy Markdown
Collaborator

I've implemented support for trace part2; Could you please help review this PR? @sufeng-buaa

ok, let me take a look.

Comment thread python/sglang/srt/managers/io_struct.py Outdated
Comment thread sgl-router/py_src/sglang_router/mini_lb.py Outdated
Comment thread python/sglang/srt/managers/io_struct.py Outdated
@zhanghaotong
Copy link
Copy Markdown
Contributor Author

@stmatengss Hi ~ Could you please help review this PR?

Signed-off-by: zhanghaotong <zhanghaotong.zht@antgroup.com>
Signed-off-by: zhanghaotong <zhanghaotong.zht@antgroup.com>
Signed-off-by: zhanghaotong <zhanghaotong.zht@antgroup.com>
Signed-off-by: zhanghaotong <zhanghaotong.zht@antgroup.com>
@zhanghaotong zhanghaotong force-pushed the tracing-add-trace-headers branch from ae3de59 to 99f658c Compare November 7, 2025 09:27
@zhanghaotong zhanghaotong requested a review from zhyncs as a code owner November 7, 2025 09:27
@github-actions github-actions Bot added the router label Nov 7, 2025
Signed-off-by: zhanghaotong <zhanghaotong.zht@antgroup.com>
@zhanghaotong zhanghaotong force-pushed the tracing-add-trace-headers branch from d0cd27a to 7b329fd Compare November 7, 2025 09:34
@sufeng-buaa
Copy link
Copy Markdown
Collaborator

LGTM. I have verified it in my machine. @ShangmingCai Could you take a look?

@zhanghaotong
Copy link
Copy Markdown
Contributor Author

Could you take a look at the PR when you have a moment? Thanks! @ShangmingCai

Copy link
Copy Markdown
Collaborator

@ShangmingCai ShangmingCai left a comment

Choose a reason for hiding this comment

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

LGTM

@hnyls2002 hnyls2002 merged commit 8359f18 into sgl-project:main Nov 12, 2025
61 of 113 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants