feat(mcp-server): metrics and tracing telemetry (prompt 19)#4023
Open
gilgardosh wants to merge 2 commits into
Open
feat(mcp-server): metrics and tracing telemetry (prompt 19)#4023gilgardosh wants to merge 2 commits into
gilgardosh wants to merge 2 commits into
Conversation
gilgardosh
temporarily deployed
to
accounter-fullstack
July 22, 2026 06:07 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
July 22, 2026 06:07 — with
GitHub Actions
Inactive
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds production-oriented telemetry to the @accounter/mcp-server package by introducing an in-memory metrics registry and lightweight tracing spans, then wiring both into request authentication, tool execution, and upstream GraphQL calls, with a /metrics endpoint and accompanying tests/docs.
Changes:
- Introduces
Metrics(counters + latency histogram) and exposes a process-wide snapshot atGET /metrics. - Adds dependency-free
withSpan()tracing and wraps auth verification, tool execution, and upstream GraphQL queries. - Wires metric recording into the tool executor and auth handler; adds vitest coverage for metrics/tracing behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/mcp-server/src/upstream/graphql-client.ts | Wraps upstream GraphQL query retries in a tracing span keyed by correlation id. |
| packages/mcp-server/src/tools/execute.ts | Records per-tool outcomes/latency to an optional metrics registry and wraps tool handlers in spans. |
| packages/mcp-server/src/tools/tests/metrics.execute.test.ts | Adds executor-level tests ensuring metrics are recorded (and no-op when absent). |
| packages/mcp-server/src/server.ts | Exposes GET /metrics returning the in-memory metrics snapshot. |
| packages/mcp-server/src/observability/tracing.ts | Adds lightweight span helper emitting structured start/end debug logs. |
| packages/mcp-server/src/observability/metrics.ts | Adds in-memory metrics registry, snapshot/reset, and outcome mapping. |
| packages/mcp-server/src/observability/tests/tracing.test.ts | Tests span logging, passthrough behavior, and error rethrow semantics. |
| packages/mcp-server/src/observability/tests/metrics.test.ts | Tests counters, histogram bucketing, snapshot/reset, and singleton behavior. |
| packages/mcp-server/src/mcp/handler.ts | Records auth-failure metrics and spans token verification; injects metrics into tool execution. |
| packages/mcp-server/README.md | Documents the new metrics snapshot endpoint and tracing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gilgardosh
force-pushed
the
claude/mcp-prompt-18-rate-limiting
branch
from
July 22, 2026 12:03
a2dc24d to
f545baf
Compare
Add operational telemetry for production readiness (blueprint prompt 19): - Metrics registry (src/observability/metrics.ts): request counters keyed by tool/outcome, a latency histogram, auth-failure counters by reason, upstream error counters, and a rate-limited counter. Labels carry no PII. - Tracing spans (src/observability/tracing.ts): lightweight withSpan wrapper emitting structured start/end debug logs with the correlation id and duration; wired around token verification (auth:verify), tool execution (tool:<name>), and each upstream GraphQL call (upstream:graphql). - Record metrics from the tool executor (success/error outcome + latency) and auth-failure counters from the transport handler. - Expose a snapshot at GET /metrics. - Unit tests for the metrics registry, outcomeForCode mapping, withSpan start/end/error logging, and executor metric recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SPMszz9gdZFhNjobRm6Ndo
- Reconcile the latency-histogram docs with its behavior: buckets hold per-bucket (non-cumulative) counts plus an +Inf overflow bucket; update the code comment and README to match instead of describing it as cumulative. - Guard outcomeOf against a non-taxonomy error code: fall back to internal_error rather than recording a `<tool>|undefined` metric key (folded into the metrics commit during rebase). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SPMszz9gdZFhNjobRm6Ndo
gilgardosh
force-pushed
the
claude/mcp-prompt-19-metrics-tracing
branch
from
July 22, 2026 12:05
9c913b3 to
89f5084
Compare
gilgardosh
temporarily deployed
to
accounter-fullstack
July 22, 2026 12:05 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
July 22, 2026 12:05 — with
GitHub Actions
Inactive
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 Prompt 19 — Metrics and tracing integration from
docs/mcp/implementation-blueprint.md,adding the operational telemetry required for production readiness (spec §11.2/§11.3). Stacked on
top of the prompt 18 branch (
claude/mcp-prompt-18-rate-limiting).What's included
Metrics registry —
src/observability/metrics.tsrequestsTotal— request counter keyed by"<tool>|<outcome>"(outcome issuccessor ataxonomy-derived error class).
latencyMs— cumulative latency histogram (fixed ms buckets ++Inf, withcount/sum).authFailuresTotal— auth-failure counter keyed by reason (missing_token,invalid_token).upstreamErrorsTotal— upstream failure counter keyed by category.rateLimitedTotal— total rate-limited requests.outcomeForCode()maps every error taxonomy code to its outcome label.getMetrics(). Labels carry no PII — only tool names,outcome classes, and error categories.
Tracing spans —
src/observability/tracing.tswithSpan(name, correlationId, fn)emitting structuredspan start/span enddebug logs with the correlation id and duration.
auth:verify), tool execution (tool:<name>), and each upstreamGraphQL call (
upstream:graphql).Wiring
optional injected
Metrics.GET /metricsexposes a snapshot.X-Correlation-Idheader; the upstream spanmakes each call traceable.
Testing
src/observability/__tests__/metrics.test.ts— counters, histogram bucketing, snapshot, reset,singleton, and full
outcomeForCodemapping.src/observability/__tests__/tracing.test.ts—withSpanresult passthrough, start/end logging,and error re-throw with a failed span.
src/tools/__tests__/metrics.execute.test.ts— executor records success / validation_error /rate_limited outcomes and is a no-op without a registry.
yarn workspace @accounter/mcp-server typecheck,lint, andtest(224 passing) all green.🤖 Generated with Claude Code
Generated by Claude Code