[Feature] Add API lifecycle events and request attributes (PR #8)#16
Merged
[Feature] Add API lifecycle events and request attributes (PR #8)#16
Conversation
Implements journey tracing PR #8: - Add EVENT_TS_MONOTONIC attribute for API event timestamps - Emit HANDOFF_TO_CORE event after engine.generate() - Emit FIRST_RESPONSE_FROM_CORE event on first response (streaming and non-streaming) - Set request attributes on API spans (model, prompt tokens, sampling params) - Add _update_first_response_time() helper to track first response timing - All span operations wrapped defensively (G7 compliance) - Zero overhead when span not recording (G6 compliance) - 12 behavioral tests covering G1, G3-G7 (G2 verified by code inspection) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements journey tracing PR #8, adding API lifecycle events and request attributes to span instrumentation.
Changes
New Events:
HANDOFF_TO_CORE: Emitted after submitting request to engine (engine.generate())FIRST_RESPONSE_FROM_CORE: Emitted when engine first responds (both streaming and non-streaming paths)Request Attributes:
gen_ai.response.model)gen_ai.usage.prompt_tokens)temperature,top_p,max_tokens,n(when non-None)Infrastructure:
EVENT_TS_MONOTONICattribute for monotonic timestamps on API events_update_first_response_time()helper to track first response timing in_api_spanstupleGuarantees
✅ G1: EVENT_TS_MONOTONIC attribute defined
✅ G2: HANDOFF_TO_CORE emitted after engine.generate() (verified by code inspection)
✅ G3: FIRST_RESPONSE_FROM_CORE emitted exactly once per request
✅ G4: First response time persisted in _api_spans tuple
✅ G5: Request attributes set on API span (conditionally for non-None values)
✅ G6: Early exit when span not recording (zero overhead)
✅ G7: All span operations wrapped defensively (failures never break requests)
Testing
test_api_additional_events.pyFiles Changed
vllm/tracing.py: Added EVENT_TS_MONOTONIC attributevllm/entrypoints/openai/engine/serving.py: Added _update_first_response_time() helpervllm/entrypoints/openai/chat_completion/serving.py: Event emissions and attribute settingtests/entrypoints/openai/test_api_additional_events.py: Test coverage (new file)🤖 Generated with Claude Code