Skip to main content
This guide covers how to instrument Bentocache for monitoring cache operations. You will learn how to:
  • Install and configure the instrumentation
  • Customize key sanitization
For the full list of required span attributes and what powers the Cache dashboard, see the Cache feature page.

Installation

npm install @bentocache/otel
Peer dependency: bentocache >= 1.0.0

Usage

Create an instance of BentoCacheInstrumentation and call enable().
instrumentation.ts
import { BentoCacheInstrumentation } from "@bentocache/otel";

const instrumentation = new BentoCacheInstrumentation();
instrumentation.enable();
If the ESM hook does not automatically patch Bentocache (e.g., timing issues), you can register it manually:
instrumentation.ts
import * as bentocache from "bentocache";

instrumentation.manuallyRegister(bentocache);
Once enabled, all cache operations (get, set, getOrSet, delete, has, clear, etc.) create spans automatically.

Configuration

const instrumentation = new BentoCacheInstrumentation({
  // Only trace cache ops within a parent span (default: false)
  requireParentSpan: false,

  // Include cache key names in span attributes (default: true)
  includeKeys: true,

  // Custom key sanitizer to reduce cardinality
  keySanitizer: (key) => key,

  // Suppress internal Redis/L2 store spans (default: false)
  suppressInternalOperations: true,
});

Bentocache-specific behavior

Internal operation suppression

When suppressInternalOperations: true, internal spans from the underlying store (Redis commands, L2 calls) are suppressed. This keeps traces clean by only showing the high-level cache operations.

Key sanitization

The Monocle agent applies a default sanitizer that replaces UUIDs, numeric IDs, and hex hashes with *. You can provide your own:
keySanitizer: (key) => key?.replace(/session:.+/, "session:*"),