Repository navigation
[Bugfix][Tracing] Collect request stats when OTLP tracing is enabled - #68674
Conversation
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]>
Signed-off-by: cipheraxat <[email protected]>
markmc
left a comment
There was a problem hiding this comment.
Thanks for the PR, it will be great to get his fixed 👍
| 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 |
There was a problem hiding this comment.
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.
| # from the frontend (headless, api_server_count > 1). | ||
| self.log_stats = ( | ||
| log_stats | ||
| or vllm_config.observability_config.otlp_traces_endpoint is not None |
There was a problem hiding this comment.
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.
This is the main things I'd like to fix - let's ensure that the Prometheus logger remains off with |
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
|
/ci run |
|
✅ Triggered Buildkite CI #105194 for commit |
main renamed OutputProcessor's log_stats to collect_stats (vllm-project#68674). Assisted-by: Metamate (AI assistant) Signed-off-by: Devanshi Jain <[email protected]>
Adapt to vllm-project/vllm#68674 while preserving the v0.33.0 scheduler contract. Signed-off-by: zhao-stack <[email protected]>
Adapt to vllm-project/vllm#68674 while preserving the v0.33.0 scheduler contract. Signed-off-by: zhao-stack <[email protected]>
Overview
With an OTLP traces endpoint set and request stats disabled, the first finished request crashes in
OutputProcessor.do_tracingonassert req_state.stats is not None. This collects request stats whenever tracing is enabled, so tracing works withdisable_log_stats=True(the offlineLLMdefault) andvllm serve --disable-log-stats.Fixes #68433. Also covers the older stale-closed report #25352 (comment with a
vllm servecrash loop).Claims
LLM(..., otlp_traces_endpoint=...)no longer crashes on its firstgenerate(); it exports anllm_requestspan with the same attributes as with stats on.vllm serve --otlp-traces-endpoint ... --disable-log-statskeeps serving, including with--api-server-count > 1(engine core launched apart from the frontend).disable_log_stats; nothing new is printed.Validation
NVIDIA L4 (Colab),
facebook/opt-125m, base438e9e8ac7(rebased onto2a55c28737without conflicts; main has not touched these files since).tests/v1/tracing/test_tracing.py::test_tracesis now parametrized overdisable_log_stats:test_traces[False]test_traces[True]assert req_state.stats is not None(output_processor.py:950)1 failed, 1 passed in 116.71s2 passed in 62.07svllm serve facebook/opt-125m --otlp-traces-endpoint localhost:4317 --disable-log-stats --enforce-eager, two/v1/completionsrequests, fake OTLP collector fromtests/tracing/conftest.py:--api-server-countllm_requestspans; engine alivellm_requestspans; engine aliveSpan timings with this PR (api-server-count 2, first request):
time_in_queue3.5e-05 s,time_to_first_token0.029 s,time_in_model_prefill0.024 s,time_in_model_decode0.149 s,e2e0.177 s,completion_tokens16. Non-zero queue time confirms the engine core recorded request events.pre-commit run --fileson 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_tracingreadsRequestStateStats,IterationStatsand the scheduler's QUEUED/SCHEDULED events. All three are only collected whenlog_statsis true, while tracing is enabled independently fromotlp_traces_endpoint.Fix (reworked per review): separate stats collection from stat logging, so tracing can turn on collection without turning on any stat logger.
log_statstocollect_statswherever it controls collection:EngineCore, the engine core clients and launch utils,OutputProcessor,SchedulerInterface/Scheduler,KVCacheManagerandLoRARequestStates.LLMEngineandAsyncLLMkeeplog_statsfor logging only and passcollect_stats = log_stats or tracingdown. With--disable-log-stats, noStatLoggerManageris created, so tracing adds no console or Prometheus stat logger.EngineCoredoes not read the tracing config. Engines thatvllm servestarts in headless mode or withapi_server_count > 1getcollect_statscomputed in those CLI launch paths; without it they would skip request events and spans would carry bogus timings.scheduler.pyandkv_cache_manager.py(rename only).Tests:
test_traces[True]also asserts that no stat logger manager exists. Newtest_tracing_collects_stats_without_stat_loggersintests/v1/engine/test_async_llm.pychecks the same forAsyncLLMwith mocked dependencies; it fails on the previous revision (which built aPrometheusStatLogger) 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_statstoSchedulerInterface.__init__need to switch tocollect_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-checklistskill. (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.