fix: bound metrics error labels#58
Merged
Merged
Conversation
lan17
marked this pull request as ready for review
July 17, 2026 21:54
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
Bound DialCache error metrics to a backend-neutral failure-site taxonomy instead of forwarding arbitrary JavaScript exception names.
This keeps the existing
errorlabel andin_fallbackdimension, while ensuring custom adapters, Prometheus, and the planned Datadog adapter receive the same finite values. Per the confirmed scope for this issue,useCaseandkeyTyperemain unchanged.Closes #45.
Root cause
ErrorMetricLabels.errorwas an unconstrainedstring, and core emission paths populated it fromError.name. Application errors and Redis/client-specific error classes could therefore create a new backend series for every caller-defined name.The adapter boundary was vendor-neutral after #56, but the event values crossing that boundary were not cardinality-safe.
Architecture and design
The core now exports a closed
MetricErrorKindunion:key_constructionDialCacheKeyconstructionconfig_resolutioncache_readcache_writeserialization_loadserialization_dumpinvalidationfallbackunknownClassification happens at the component that knows the operation. In particular,
RedisCachedistinguishes client reads/writes from serializer load/dump failures before preserving the existing fail-open control flow. Serializer errors are recorded once and do not also produce a generic write error.Runtime config-provider failures now produce
error="config_resolution"withlayer="noop", because they happen before any cache layer is selected, while retaining the existing fail-open behavior anddisabled(reason="config_error")event.Raw thrown values remain available to the existing logger paths, but exception names, messages, cache IDs, arguments, and Redis keys never enter metric labels.
Public API and migration
MetricErrorKindfromdialcache.ErrorMetricLabels.errorfromstringtoMetricErrorKind.in_fallbacklabel for existing cache-versus-application queries.errorlabel values from exception class names such asErrororTypeErrorto the failure-site values above.Applications with alerts or dashboards matching exception-name values must migrate those queries. Custom adapter implementations continue to receive the same
ErrorMetricLabelsobject shape, now with a bounded error value.Test contract
The tests now lock:
MetricErrorKindmember, including reservedunknown, through both the packed public types and Prometheus export;inFallbackvalues;noop,request_local,local, andremote;Scope
This PR intentionally does not add limits, warnings, normalization, or policy changes for
useCaseorkeyType. It also does not add a classifier hook or any backend dependency.Validation
Validated with Node 22.22.0 unless noted:
corepack pnpm typecheckcorepack pnpm test: 146 tests passed; 97.73% statements and 91.26% branches;src/dialcache.tshas 100% statements, functions, and linescorepack pnpm build: ESM, CJS, and declarationscorepack pnpm test:package: packed ESM/CJS/type consumerscorepack pnpm test:integration: 46 Redis, Valkey, and cluster integration testscorepack pnpm audit --prod --audit-level high: no known vulnerabilitiesgit diff --check