Skip to content

feat(telemetry): stamp auth.user_id on tool and REST handler spans - #749

Merged
dash0-dev[bot] merged 1 commit into
mainfrom
feat/tool-span-user-id
Nov 14, 2026
Merged

dash0-dev[bot] merged 1 commit into
mainfrom
feat/tool-span-user-id

Conversation

@dash0-dev

@dash0-dev dash0-dev Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Summary

auth.user_id was 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.inserted on lorekit.memory.write, lorekit.memory.count on lorekit.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: set auth.user_id on every lorekit.<tool> span (covers memory.write and memory.quota), using the analyticsUserId the dispatcher already resolves for the usage event.
  • _shared/api/router.ts: set auth.user_id on the REST handler span hs (covers lorekit.memories.get/quota and the write route), using the usageUserId already stamped on the root span.
  • Both follow the existing rule: absent, never empty, for service-role callers.
  • New source-scan guard packages/mcp-core/src/mcp-guards/tool-span-user-identity.spec.ts (same pattern as mcp-handler-plan-reuse.spec.ts, since the edge tree has no test job). It fails on main and passes here.
  • docs/otel.md: auth.user_id row in the lorekit.memory.* attribute table.

Context

  • No new identifier is introduced: the same pseudonymous Supabase UUID is already on the root span and in usage_events.user_id.
  • Once deployed, per-user panels can group lorekit.memory.write by auth_user_id × lorekit_write_inserted, and quota spans by auth_user_id with max(lorekit.memory.count).
  • Verified locally: the new guard plus edge-parity, usage-client-parity, mcp-preamble-usage and mcp-handler-plan-reuse specs (59 tests) pass. deno check was not run locally (no Deno in the sandbox), so CI's Edge typecheck job covers it.

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>
@dash0-dev

dash0-dev Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

✅ No issues found

Stamps 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.

Re-review

Review details
Gate Details
Description vs. code ✅ Matches the diff; the router change also stamps lorekit.orgs.* handler spans (shared createRouter).
Prior review feedback ✅ Earlier review comments are resolved.
Documentation ✅ Inline comments, the docs/otel.md row and the spec header explain purpose and the absent rule.
Self-review signals ✅ No debug logs, leftover TODOs, or unreviewed stubs.
Code review ✅ The multi-lens review found no blocking issues.
Run Details
Mode full · 96 lines in delta · tier standard (small PR) · depth checkout
Anomaly ⚠️ no sub-agent dispatch available — the intent finder ran in-context with the other finders at effective thoroughness 0.7, instead of as its own sub-agent
Checked 4 of 4 changed files read · 2 possible issues → 0 confirmed → 0 posted
Reach 2 changed exports · 4 dependent files · 1 checked · 3 not checked
createRouter — 3 consumer files · 0 checked
handleMcp — 1 consumer file · 1 checked
Found produced 2 → posted inline 0 · cleared 0 · carried forward 0 · deferred 0 · below-bar 0
Dropped 2 below-bar
Lenses tdd (auto)
Standards ran · 3 governing docs, 77 bullets · 0 findings (router uses the analyticsUserId helper per _shared/api/CLAUDE.md:64)
Integrations none
Memories 69 indexed · 1 used (1 lesson)

Memories used

  • lesson otel::omit-the-attribute-rather-than-emit-a-placeholder-outside-the-semconv-enum — checked both new stamps omit auth.user_id for service-role rather than writing a placeholder

Nothing to report — measurability (skipped), severity, 0 files skipped.

pr-reviewer · commit 4763bd1 · full review · how these findings are produced · updated Nov 14, 2026 11:42am UTC

@dash0-dev
dash0-dev Bot marked this pull request as ready for review November 14, 2026 11:44
@dash0-dev
dash0-dev Bot requested a review from mthines as a code owner November 14, 2026 11:44
@dash0-dev
dash0-dev Bot merged commit 64309e8 into main Nov 14, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant