[Refactor] Deduplicate trace header handling in BaseServing (#60828)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
Chauncey
2026-10-10 05:27:58 +00:00
committed by GitHub
parent 7d0b4e57aa
commit fa5cfd48d5
7 changed files with 19 additions and 80 deletions
+1 -21
View File
@@ -2,14 +2,13 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import json
import time
from collections.abc import Awaitable, Mapping
from collections.abc import Awaitable
from dataclasses import dataclass, field
from http import HTTPStatus
from typing import ClassVar, Generic, TypeVar
from fastapi import Request
from pydantic import ConfigDict
from starlette.datastructures import Headers
from vllm import RequestOutput
from vllm.engine.protocol import EngineClient
@@ -33,11 +32,6 @@ from vllm.logprobs import Logprob, PromptLogprobs
from vllm.lora.request import LoRARequest
from vllm.tokenizers import TokenizerLike
from vllm.tokenizers.detokenizer_utils import convert_ids_list_to_tokens
from vllm.tracing import (
contains_trace_headers,
extract_trace_headers,
log_tracing_disabled_warning,
)
from vllm.v1.metrics.stats import RequestStateStats
logger = init_logger(__name__)
@@ -222,20 +216,6 @@ class GenerateBaseServing(BaseServing, BeamSearchOnlineMixin):
status_code=e.status_code,
)
async def _get_trace_headers(
self,
headers: Headers,
) -> Mapping[str, str] | None:
is_tracing_enabled = await self.engine_client.is_tracing_enabled()
if is_tracing_enabled:
return extract_trace_headers(headers)
if contains_trace_headers(headers):
log_tracing_disabled_warning()
return None
@staticmethod
def _get_data_parallel_rank(raw_request: Request | None) -> int | None:
"""Pulls the data parallel rank from a header, if provided."""
@@ -11,7 +11,6 @@ logits (task="generate").
import asyncio
import math
import time
from collections.abc import Mapping
from typing import Any, Literal
from fastapi import Request
@@ -32,11 +31,6 @@ from vllm.inputs import EngineInput, tokens_input
from vllm.logger import init_logger
from vllm.sampling_params import SamplingParams
from vllm.tokenizers import TokenizerLike
from vllm.tracing import (
contains_trace_headers,
extract_trace_headers,
log_tracing_disabled_warning,
)
from vllm.utils import random_uuid
logger = init_logger(__name__)
@@ -462,17 +456,3 @@ class ServingGenerativeScoring(BaseServing):
token_id: math.exp(logprob)
for token_id, logprob in label_logprobs.items()
}
async def _get_trace_headers(
self,
headers: Mapping[str, str],
) -> Mapping[str, str] | None:
"""Extract trace headers from request headers."""
if not contains_trace_headers(headers):
return None
if not await self.engine_client.is_tracing_enabled():
log_tracing_disabled_warning()
return None
return extract_trace_headers(headers)
@@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import asyncio
import json
from collections.abc import Mapping
from typing import Any
from fastapi import Request
@@ -12,11 +11,6 @@ from vllm.entrypoints.serve.engine.protocol import ErrorResponse
from vllm.entrypoints.serve.engine.serving import BaseServing
from vllm.entrypoints.serve.utils.request_logger import RequestLogger
from vllm.logger import init_logger
from vllm.tracing import (
contains_trace_headers,
extract_trace_headers,
log_tracing_disabled_warning,
)
from .protocol import (
DecisionUsage,
@@ -74,19 +68,10 @@ class ServingStructuredDecisions(BaseServing):
super().__init__(
models=models, model_config=model_config, request_logger=request_logger
)
self.engine_client = strategy.context.engine_client
self.strategy = strategy
self.limits = strategy.limits()
async def _get_trace_headers(
self, headers: Mapping[str, str]
) -> Mapping[str, str] | None:
if not contains_trace_headers(headers):
return None
if not await self.strategy.context.engine_client.is_tracing_enabled():
log_tracing_disabled_warning()
return None
return extract_trace_headers(headers)
async def create_decision(
self,
request: StructuredDecisionRequest,