Skip to content

Trace tokenization and propagate request context#679

Open
satyamg1620 wants to merge 2 commits into
llm-d:mainfrom
satyamg1620:trace-kvevents-tokenization
Open

Trace tokenization and propagate request context#679
satyamg1620 wants to merge 2 commits into
llm-d:mainfrom
satyamg1620:trace-kvevents-tokenization

Conversation

@satyamg1620

Copy link
Copy Markdown

Part of #644 ("Extend OTel Tracing Coverage: kvevents + tokenization"). This PR covers the tokenization sub-task
only; the kvevents event-processing span is handled separately in #678

@gyliu513

Signed-off-by: satyamg1620 <Satyam.Gupta.3@ibm.com>
@github-actions github-actions Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 22, 2026
Comment thread pkg/tokenization/pool.go
Comment thread pkg/tokenization/pool.go Outdated
Comment thread pkg/tokenization/pool.go Outdated
Signed-off-by: satyamg1620 <Satyam.Gupta.3@ibm.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends OpenTelemetry trace context propagation into the tokenization worker pool so the tokenization work is parented to the originating request span, closing the “tokenization” observability gap called out in #644.

Changes:

  • Add context.Context propagation across the tokenization workqueue boundary and start a llm_d.kv_cache.tokenization span in the worker.
  • Emit tokenization span attributes (mode, prompt length, token count, multimodal flag) and set span status on errors.
  • Update the TokenizersPool interface + Indexer callers to pass request context, and add span-focused tests for the worker path.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/tokenization/pool.go Propagates caller context via Task.Ctx and creates a tokenization span with attributes/status.
pkg/tokenization/pool_trace_test.go Adds tests validating parent/child span linkage and span attributes/status.
pkg/kvcache/types.go Updates TokenizersPool.Tokenize signature to accept context.Context.
pkg/kvcache/indexer.go Passes request ctx into tokenization so spans parent correctly.
pkg/kvcache/indexer_test.go Updates mock TokenizersPool implementation to match new interface.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/tokenization/pool.go
Comment on lines +208 to +210
// chatPromptLen returns the combined character length of the conversation's
// text content. It is used as an approximate prompt size for chat-mode
// tokenization spans, where task.Prompt is empty.
limitations under the License.
*/

package tokenization
@satyamg1620
satyamg1620 requested a review from gyliu513 June 27, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants