Skip to content

Emit HTTP cache hit/miss as metrics instead of logs#656

Open
arreyder wants to merge 1 commit intomainfrom
crr/cache-metrics
Open

Emit HTTP cache hit/miss as metrics instead of logs#656
arreyder wants to merge 1 commit intomainfrom
crr/cache-metrics

Conversation

@arreyder
Copy link
Contributor

@arreyder arreyder commented Jan 28, 2026

Summary

  • Replace spammy debug log statements for HTTP cache hits/misses with OpenTelemetry metrics
  • Add WithMetricsHandler option to BaseHttpClient to enable metric recording
  • New metrics: baton_sdk.http_cache_hit and baton_sdk.http_cache_miss

Test plan

  • Existing tests pass
  • Verify metrics are emitted when a metrics handler is configured
  • Verify backward compatibility (no metrics handler = no-op)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Implemented metrics collection for HTTP cache events, automatically tracking cache hits and misses during operations.
    • Added optional metrics handler configuration to HTTP client, enabling monitoring of cache performance and optimization opportunities.
    • Cache metrics now available for integration with monitoring and observability systems.

✏️ Tip: You can customize this high-level summary in your review settings.

Replace debug log statements for cache hits and misses with OpenTelemetry
metrics. Add WithMetricsHandler option to BaseHttpClient to enable metric
recording when a metrics handler is provided.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Walkthrough

The PR introduces metrics integration for HTTP cache events in the HTTP client wrapper. A metrics handler option is added to configure metrics collection, with helper methods to emit cache hit and miss metrics during cache operations.

Changes

Cohort / File(s) Summary
Metrics Integration for HTTP Caching
pkg/uhttp/wrapper.go
Added WithMetricsHandler() option method and metricsHandler field to BaseHttpClient. Introduced recordCacheHit() and recordCacheMiss() helpers. Cache operations now emit metrics (hit/miss counters) when a metrics handler is configured. Replaces prior debug logging with metric increments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hop! Hop! The metrics flow,
Cache hits now aglow!
Handler hooks collect the tale,
Of every cache hit and miss without fail!
Instrumented and true, observability rules!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Emit HTTP cache hit/miss as metrics instead of logs' accurately describes the main change: replacing debug logging of HTTP cache events with OpenTelemetry metrics emission.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@arreyder arreyder requested review from ggreer and kans January 30, 2026 14:10
baseHttpCache icache
HttpClient *http.Client
rateLimiter uRateLimit.Limiter
baseHttpCache icache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to put the metrics handler on the cache itself?

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.

2 participants