> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monocle.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Bentocache

> Instrument Bentocache cache operations for observability

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](/features/cache).

## Installation

```bash theme={"theme":"vesper"}
npm install @bentocache/otel
```

**Peer dependency:** `bentocache >= 1.0.0`

## Usage

Create an instance of `BentoCacheInstrumentation` and call `enable()`.

```typescript title="instrumentation.ts" theme={"theme":"vesper"}
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:

```typescript title="instrumentation.ts" theme={"theme":"vesper"}
import * as bentocache from "bentocache";

instrumentation.manuallyRegister(bentocache);
```

Once enabled, all cache operations (`get`, `set`, `getOrSet`, `delete`, `has`, `clear`, etc.) create spans automatically.

## Configuration

```typescript theme={"theme":"vesper"}
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:

```typescript theme={"theme":"vesper"}
keySanitizer: (key) => key?.replace(/session:.+/, "session:*"),
```
