feat: add Datadog metrics adapter#59
Merged
Merged
Conversation
lan17
marked this pull request as ready for review
July 17, 2026 23:07
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
Closes #54.
This adds a first-party Datadog DogStatsD adapter while preserving DialCache's backend-neutral root package and caller-owned client lifecycle.
Architecture and dependency boundary
The new stable
dialcache/datadogsubpath contains the adapter and its structural client contract. Published code does not importhot-shots, andhot-shotsis neither a runtime dependency nor a peer dependency. Applications install it separately, construct the client, and pass it into the adapter.The adapter uses only:
increment(name, value, tags)histogram(name, value, tags)distribution(name, value, tags)It never creates transport, flushes buffers, closes sockets, or owns client retries/error handling. The existing
DialCachesafe metrics boundary continues to isolate synchronous client failures.Public API
dialcache/datadogexports:DatadogDialCacheMetricscreateDatadogDialCacheMetricsDatadogMetricsOptionsDatadogDogStatsDClientDatadogObservationMetricTypeobservationMetricTypeis a required"histogram" | "distribution"choice. The documented recommendation isdistributionfor globally aggregated latency and size percentiles; histogram remains available for intentional Agent-local workflows.The namespace defaults to
dialcache. Construction rejects unsupported modes, missing client methods, invalid namespaces, and any namespace that would make a final adapter metric name exceed Datadog's 200-character limit. Values are never silently sanitized.Metric contract
All ten current backend-neutral events have exact DogStatsD mappings, including request-local activity and both coalescing scopes. Counters always call
increment(name, 1, tags); observations preserve seconds and bytes. Histogram and distribution modes use identical names, values, and tags through their respective client methods.The adapter preserves the bounded error taxonomy and emits no cache IDs, arguments, Redis keys, raw errors, or messages. End-to-end adversarial coverage verifies those values never reach recorded Datadog calls.
Packaging and ergonomics
Packed-consumer tests now prove:
dialcache/datadogESM/CJS imports work beforehot-shotsexists;hot-shotstypes;hot-shotsis not installed or resolved transitively;hot-shotsinstall, itsStatsDinstance is directly assignable in ESM and CommonJS TypeScript consumers.The README covers installation, global tags and client prefixes, client ownership, distribution percentile/billing implications, namespace migration, failure handling, and shutdown.
Validation
Run on Node 22.22.0:
pnpm checkpnpm test:integration: 46 tests passed across the existing Redis/Valkey integration suitespnpm audit --prod: no known vulnerabilitiesgit diff --checkhot-shotsmock-mode datagram coverage for both distribution and histogramInstrumentation overhead
Directional one-argument process-local-hit measurements were run against the concern tracked in #43. Each number is the median of seven fresh Node 22.22.0 processes, with 100,000 measured hits after 20,000 warm-up hits on the same build:
hot-shotsmock encoding/bufferingThese are informational rather than a regression threshold. They separate the adapter's mapping cost from real-client DogStatsD formatting/buffering work; issue 43 remains the place to establish the repository-wide benchmark budget and optimize shared hot-path instrumentation.