Skip to content

feat: OpenTelemetry metrics + tracing (Meter + ActivitySource) #39

Description

@matthewdevenny

Problem

The cache only logs Connected / Exception (src/NatsDistributedCache/NatsCache.Log.cs). There's no hit-ratio, latency, or error instrumentation, which makes production cache effectiveness hard to observe.

Investigation

Neither IDistributedCache nor (per the current Microsoft caching docs) HybridCache emits documented cache metrics for the backend store. Instrumenting at this layer is therefore genuinely additive and benefits both direct IDistributedCache consumers and HybridCache-L2 users. FusionCache's *.OpenTelemetry package is good prior art for the shape.

Proposal

Add first-class telemetry using System.Diagnostics (no hard OpenTelemetry dependency):

  • A named Meter with: get/set/remove/refresh counters, a hit/miss counter, an operation-duration histogram, and an error counter.
  • A named ActivitySource for spans around KV operations.
  • Documented MeterName / ActivitySourceName constants and OTel-aligned tags so users can wire metrics.AddMeter(...) / tracing.AddSource(...).

Acceptance criteria

  • Hit/miss/latency/error instruments emitted for cache operations.
  • Public, documented meter/source names.
  • Opt-in; no telemetry overhead when not subscribed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions