Skip to content

[Bugfix][Tracing] Collect request stats when OTLP tracing is enabled - #68674

Merged
markmc merged 5 commits into
vllm-project:mainfrom
cipheraxat:fix/tracing-without-log-stats-68433
Nov 23, 2026
Merged

markmc merged 5 commits into
vllm-project:mainfrom
cipheraxat:fix/tracing-without-log-stats-68433

Conversation

@cipheraxat

@cipheraxat cipheraxat commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Overview

With an OTLP traces endpoint set and request stats disabled, the first finished request crashes in OutputProcessor.do_tracing on assert req_state.stats is not None. This collects request stats whenever tracing is enabled, so tracing works with disable_log_stats=True (the offline LLM default) and vllm serve --disable-log-stats.

Fixes #68433. Also covers the older stale-closed report #25352 (comment with a vllm serve crash loop).

Claims

  • LLM(..., otlp_traces_endpoint=...) no longer crashes on its first generate(); it exports an llm_request span with the same attributes as with stats on.
  • vllm serve --otlp-traces-endpoint ... --disable-log-stats keeps serving, including with --api-server-count > 1 (engine core launched apart from the frontend).
  • Default stat loggers still follow disable_log_stats; nothing new is printed.

Validation

NVIDIA L4 (Colab), facebook/opt-125m, base 438e9e8ac7 (rebased onto 2a55c28737 without conflicts; main has not touched these files since).

tests/v1/tracing/test_tracing.py::test_traces is now parametrized over disable_log_stats:

main this PR
test_traces[False] passed passed
test_traces[True] failed: assert req_state.stats is not None (output_processor.py:950) passed
summary 1 failed, 1 passed in 116.71s 2 passed in 62.07s

vllm serve facebook/opt-125m --otlp-traces-endpoint localhost:4317 --disable-log-stats --enforce-eager, two /v1/completions requests, fake OTLP collector from tests/tracing/conftest.py:

--api-server-count main this PR
1 200, then 500; engine dead; 0 spans 200, 200; 2 llm_request spans; engine alive
2 engine dead after first request; 0 spans 200, 200; 2 llm_request spans; engine alive

Span timings with this PR (api-server-count 2, first request): time_in_queue 3.5e-05 s, time_to_first_token 0.029 s, time_in_model_prefill 0.024 s, time_in_model_decode 0.149 s, e2e 0.177 s, completion_tokens 16. Non-zero queue time confirms the engine core recorded request events.

pre-commit run --files on the changed files passes.

The GPU results above were measured on the first revision. The re-run on the current revision (collection split from logging) is pending; I will update these tables.

Details

Root cause: do_tracing reads RequestStateStats, IterationStats and the scheduler's QUEUED/SCHEDULED events. All three are only collected when log_stats is true, while tracing is enabled independently from otlp_traces_endpoint.

Fix (reworked per review): separate stats collection from stat logging, so tracing can turn on collection without turning on any stat logger.

  • Rename the internal log_stats to collect_stats wherever it controls collection: EngineCore, the engine core clients and launch utils, OutputProcessor, SchedulerInterface/Scheduler, KVCacheManager and LoRARequestStates.
  • LLMEngine and AsyncLLM keep log_stats for logging only and pass collect_stats = log_stats or tracing down. With --disable-log-stats, no StatLoggerManager is created, so tracing adds no console or Prometheus stat logger.
  • EngineCore does not read the tracing config. Engines that vllm serve starts in headless mode or with api_server_count > 1 get collect_stats computed in those CLI launch paths; without it they would skip request events and spans would carry bogus timings.
  • Merged main to resolve conflicts in scheduler.py and kv_cache_manager.py (rename only).

Tests: test_traces[True] also asserts that no stat logger manager exists. New test_tracing_collects_stats_without_stat_loggers in tests/v1/engine/test_async_llm.py checks the same for AsyncLLM with mocked dependencies; it fails on the previous revision (which built a PrometheusStatLogger) and passes now.

Tradeoff: with tracing on and stats off, vLLM pays the CPU-side stats-collection cost (no new GPU syncs). Tracing needs that data anyway. Stat loggers stay off.

Compatibility: out-of-tree schedulers that pass log_stats to SchedulerInterface.__init__ need to switch to collect_stats.

Not a duplicate: no open PR references #68433. The only earlier fix, #25645, was closed by the stale bot. Open feature PR #32162 (tracing aborted requests) adds a startup error for this flag pair instead; that would also reject LLM(otlp_traces_endpoint=...) unless users opt back into stat logging, so this PR keeps the combination working.

AI assistance was used to prepare this change.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

do_tracing builds each llm_request span from the per-request stats and
the scheduler's request events, but both were only collected when stat
logging was on. With an OTLP traces endpoint and stats disabled, the
first finished request hit `assert req_state.stats is not None`. Offline
LLM disables stats by default, so LLM(otlp_traces_endpoint=...) crashed
on its first generate(), and `vllm serve --disable-log-stats` killed the
engine.

Collect stats whenever a traces endpoint is set, in LLMEngine, AsyncLLM
and EngineCore (which covers engines launched apart from the frontend).
The default stat loggers still follow the user's flag, as with custom
stat loggers today.

Fixes vllm-project#68433

Signed-off-by: cipheraxat <[email protected]>
@mergify mergify Bot added the bug Something isn't working label Nov 19, 2026
@cipheraxat
cipheraxat marked this pull request as ready for review November 21, 2026 09:51
@cipheraxat
cipheraxat requested a review from njhill as a code owner November 21, 2026 09:51

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@markmc markmc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR, it will be great to get his fixed 👍

Comment thread vllm/v1/engine/async_llm.py Outdated
has_custom_loggers = bool(custom_stat_loggers)
self.log_stats = log_stats or has_custom_loggers
# Tracing needs the request stats; default stat loggers stay off.
self.log_stats = log_stats or has_custom_loggers or tracing_endpoint is not None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I think log_stats is poorly named for our purpose - we need to properly distinguish between stats collection and "logging" to console/Prometheues. We need to allow tracing the former, but not the latter.

Let's rename internal log_stats to collect_stats wherever it controls collection rather than logging. This will be a pain, but I think it's time we cleaned up these semantics.

Affected files: engine/core.py, engine/core_client.py, engine/utils.py, engine/output_processor.py, core/sched/interface.py, core/sched/scheduler.py, core/kv_cache_manager.py, metrics/stats.py

The next step is in AsyncLLM and LLMEngine, let's have tracing enable stats collection independently of logging. With --disable-log-stats, tracing should not create console or Prometheus stat loggers. The log_stats attribute will remain in the frontend, but it will only control logging not collection.

Comment thread vllm/v1/engine/core.py Outdated
# from the frontend (headless, api_server_count > 1).
self.log_stats = (
log_stats
or vllm_config.observability_config.otlp_traces_endpoint is not None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For headless and multi-API-server serving, let's compute collect_stats = log_stats or tracing_enabled in the CLI launch paths and pass it to EngineCore, keeping the tracing configuration check out of the core.

@markmc

markmc commented Nov 23, 2026

Copy link
Copy Markdown
Member

Tradeoff: with tracing on and stats off, vLLM now [...] registers the Prometheus stat logger [..]

This is the main things I'd like to fix - let's ensure that the Prometheus logger remains off with --disable-log-stats --otlp-traces-endpoint 👍

@markmc markmc moved this from Backlog to In Review in Prometheus Metrics Nov 23, 2026
Address review: tracing needs the collected request stats, but must not
turn on the console or Prometheus stat loggers when stat logging is
disabled.

- Rename the internal log_stats to collect_stats where it controls
  collection: EngineCore, the engine core clients and launch utils,
  OutputProcessor, the scheduler interface and Scheduler,
  KVCacheManager and LoRARequestStates.
- LLMEngine and AsyncLLM keep log_stats for logging only and pass
  collect_stats = log_stats or tracing to collection. With
  --disable-log-stats no StatLoggerManager is created.
- EngineCore no longer reads the tracing config. The headless and
  multi-API-server launch paths in `vllm serve` compute collect_stats
  and pass it in.
- Tests: assert no stat loggers in test_traces with stats disabled, and
  add an AsyncLLM unit test for the same with mocked dependencies.

Signed-off-by: cipheraxat <[email protected]>
…og-stats-68433

Signed-off-by: cipheraxat <[email protected]>

# Conflicts:
#	vllm/v1/core/kv_cache_manager.py
#	vllm/v1/core/sched/scheduler.py
@markmc

markmc commented Nov 23, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #105194 for commit ca80e0232fa1.

@markmc markmc removed this from Sprint - DFlash Nov 23, 2026
@markmc
markmc enabled auto-merge (squash) November 23, 2026 19:34
@mergify mergify Bot added the scheduler label Nov 23, 2026
@markmc
markmc merged commit a688cea into vllm-project:main Nov 23, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Sprint - DFlash Nov 23, 2026
@github-project-automation github-project-automation Bot moved this from In Review to Done in Prometheus Metrics Nov 23, 2026
devanshi-code18 added a commit to devanshi-code18/vllm that referenced this pull request Nov 24, 2026
main renamed OutputProcessor's log_stats to collect_stats (vllm-project#68674).

Assisted-by: Metamate (AI assistant)
Signed-off-by: Devanshi Jain <[email protected]>
zhao-stack added a commit to zhao-stack/vllm-ascend that referenced this pull request Nov 24, 2026
Adapt to vllm-project/vllm#68674 while preserving the v0.33.0 scheduler contract.

Signed-off-by: zhao-stack <[email protected]>
zhao-stack added a commit to zhao-stack/vllm-ascend that referenced this pull request Nov 24, 2026
Adapt to vllm-project/vllm#68674 while preserving the v0.33.0 scheduler contract.

Signed-off-by: zhao-stack <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dflash frontend kv-cache-manager kv-connector multi-modality Related to multi-modality (#4194) ready ONLY add when PR is ready to merge/full CI is needed scheduler speculative-decoding

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: enabling OTLP tracing with offline LLM default statistics settings crashes request completion

2 participants