feat(telemetry): one session id and one trace per turn (RPT-057) - #105
Draft
Nivesh353 wants to merge 1 commit into
Draft
feat(telemetry): one session id and one trace per turn (RPT-057)#105Nivesh353 wants to merge 1 commit into
Nivesh353 wants to merge 1 commit into
Conversation
One user turn costs several requests to the model gateway — one returns a tool call, the next the answer. The gateway traced each separately, so a single "hi" showed up as two unrelated traces with no way to total them. Send X-Session-Id (this run's id, overridable via --session-id or the SDK's sessionId) on every request, and a per-turn traceparent so the gateway can stitch a turn's requests into one trace. Both no-op safely: the header is set on a cloned model, and traceparent yields to the undici instrumentation when OTel is initialised.
Nivesh353
marked this pull request as draft
August 14, 2026 11:08
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.
What — Every model request now carries X-Session-Id, and every request within a turn shares a traceparent.
Why — RPT-057: one gitagent run produced several unrelated traces in Studio with no way to correlate them or total consumption.
How — loadAgent() takes an optional session id (CLI --session-id, SDK sessionId) and puts it on the model's headers, cloned so the shared pi-ai registry object isn't mutated. startTurnTrace() sets a fresh traceparent before each turn.
Verified — Against dev: two traces sharing one session id, then a single trace of 12 spans once the server-side change landed