Skip to content

metrics: allow extra labels on HTTP request/response Prometheus metrics - #31530

Merged
ispobock merged 4 commits into
sgl-project:mainfrom
sshleifer:sam/upstream-prometheus-extra-labels
Jul 18, 2026
Merged

ispobock merged 4 commits into
sgl-project:mainfrom
sshleifer:sam/upstream-prometheus-extra-labels

Conversation

@sshleifer

@sshleifer sshleifer commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Add an optional extra_labels: Optional[Dict[str, str]] parameter to add_prometheus_track_response_middleware that is merged into the label set of the sglang:http_requests_total / http_responses_total / http_requests_active metrics (and their inc/dec calls). This lets a deployment attach identifying labels (e.g. job id, replica id) to HTTP metrics so they can be filtered/joined the same way as the scheduler metrics, without a label-join. Defaults to no extra labels, so existing behavior is unchanged.

Motivation

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #29645532213
Latest PR Test (Extra): ❌ Run #29645532167

Add an optional `extra_labels: Optional[Dict[str, str]]` parameter to
`add_prometheus_track_response_middleware` that is merged into the label set of
the sglang:http_requests_total / http_responses_total / http_requests_active
metrics (and their inc/dec calls). This lets a deployment attach identifying
labels (e.g. job id, replica id) to HTTP metrics so they can be filtered/joined
the same way as the scheduler metrics, without a label-join. Defaults to no
extra labels, so existing behavior is unchanged.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 603f91840c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def add_prometheus_track_response_middleware(app):
def add_prometheus_track_response_middleware(
app, extra_labels: Optional[Dict[str, str]] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pass extra labels from the HTTP server

In the normal HTTP-server launch path, the only in-repo call remains add_prometheus_track_response_middleware(app) in python/sglang/srt/entrypoints/http_server.py:2370, so ServerArgs.extra_metric_labels never reaches this new parameter. Deployments using --extra-metric-labels will still get those labels on scheduler/tokenizer metrics but not on these HTTP counters/gauges, which defeats the new filtering/joining use case this parameter is meant to support.

Useful? React with 👍 / 👎.

@ispobock
ispobock merged commit d86ae51 into sgl-project:main Jul 18, 2026
208 of 225 checks passed
Zhylkaaa pushed a commit to Zhylkaaa/sglang that referenced this pull request Jul 29, 2026
jinzhenfan pushed a commit to jinzhenfan/sglang that referenced this pull request Jul 29, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
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.

3 participants