feat: typed Metrics interface and auto-detected client version#6
Merged
Conversation
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
Metricsinterface —RecordCall(server, tool string, dur time.Duration, err error)andRecordToolList(server string, count int). Register viaWithMetrics(m Metrics); passingnilis a no-op. Panics inside any method are recovered by the library. Works alongside existingAfterCallHook.RecordCallis invoked after everyCallToolinvocation including pre-RPC failures (ErrToolNotFound, etc.).durmeasures the upstream MCP call wall-clock time; near-zero for pre-RPC failures.RecordToolListis invoked after every successful tool-list fetch (initial connect + live refresh).clientInfo.version— reads the consuming module's version viaruntime/debug.ReadBuildInfo(); falls back to"dev"forgo run/ untagged builds.WithClientIdentitycontinues to override.runtime/debugis stdlib).Test plan
TestMetrics_RecordCall_Success— RecordCall fires with nil err and dur > 0TestMetrics_RecordCall_Error— RecordCall fires with non-nil err for ErrToolNotFoundTestMetrics_RecordToolList— RecordToolList fires on connect with correct countTestMetrics_PanicRecovered— panic in Metrics doesn't propagate to callerTestMetrics_NilNoOp— WithMetrics(nil) is safeTestMetrics_WithAfterCallCoexists— both Metrics and AfterCallHook fireTestVersion_DefaultIsDev— defaultClientVersion returns "dev" in test envTestVersion_WithClientIdentityOverrides— explicit override takes precedencego test -race ./...,golangci-lint run— all green🤖 Generated with Claude Code