Repository navigation
feat(telemetry): stamp auth.user_id on tool and REST handler spans - #749
Merged
Merged
Conversation
The caller's id was only on the root request span, while the facts a per-user view needs (lorekit.write.inserted, lorekit.memory.count) sit on the child operation span. Span metrics cannot join the two, so memories per user could not be charted. Co-authored-by: dash0-dev[bot] <257284812+dash0-dev[bot]@users.noreply.github.com>
Contributor
Author
✅ No issues foundStamps auth.user_id on MCP tool spans and REST handler spans so span metrics can group per-user writes and quota counts without a trace join; guarded absent-never-empty, documented, and pinned by a source-scan spec. Review details
Memories used
Nothing to report — measurability (skipped), severity, 0 files skipped.
|
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
auth.user_idwas only on the root request span (lorekit.mcp,lorekit.memories), while the facts a per-user view needs are written on the child operation span:lorekit.write.insertedonlorekit.memory.write,lorekit.memory.countonlorekit.memories.get/quota/lorekit.memory.quota. Span metrics group one span's attributes at a time and cannot join a child to its parent, so "memories held per user" and "new memories per user" could only be answered with a trace-level join. This stamps the same id on the operation span too.Changes
mcp/mcp-handler.ts: setauth.user_idon everylorekit.<tool>span (coversmemory.writeandmemory.quota), using theanalyticsUserIdthe dispatcher already resolves for the usage event._shared/api/router.ts: setauth.user_idon the REST handler spanhs(coverslorekit.memories.get/quotaand the write route), using theusageUserIdalready stamped on the root span.packages/mcp-core/src/mcp-guards/tool-span-user-identity.spec.ts(same pattern asmcp-handler-plan-reuse.spec.ts, since the edge tree has no test job). It fails onmainand passes here.docs/otel.md:auth.user_idrow in thelorekit.memory.*attribute table.Context
usage_events.user_id.lorekit.memory.writebyauth_user_id×lorekit_write_inserted, and quota spans byauth_user_idwithmax(lorekit.memory.count).edge-parity,usage-client-parity,mcp-preamble-usageandmcp-handler-plan-reusespecs (59 tests) pass.deno checkwas not run locally (no Deno in the sandbox), so CI's Edge typecheck job covers it.