Skip to content

Commit

Permalink
feat(js-caches): Add Instrumentation with Redis Clients (#10281)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d committed Jun 5, 2024
1 parent 6c3c674 commit 98db824
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ A cache can be used to speed up data retrieval, thereby improving application pe

Sentry offers a [cache-monitoring dashboard](https://sentry.io/orgredirect/organizations/:orgslug/performance/caches/) that can be auto-instrumented using Sentry's Redis integration (more coming soon).

## Instrumentation with Redis Clients

If you're using a Redis client like `ioredis` or `redis` to cache your data, it is necessary to specify the `cachePrefixes` within the `redisIntegration` options. This configuration allows Sentry to categorize accesses to keys with the defined prefixes as "cache operations".

```javascript
Sentry.init({
integrations: [
redisIntegration({
cachePrefixes: ['posts:', 'authors:']
})
]
})
```

## Manual Instrumentation

If you're using anything other than Sentry's Redis integration, you'll need to manually instrument the [Cache Module](<(https://sentry.io/orgredirect/organizations/:orgslug/performance/caches/)>) by following the steps below.
Expand Down Expand Up @@ -58,7 +72,7 @@ const value = "The value I want to cache.";

Sentry.startSpan(
{
name: "Setting auth cache",
name: key,
attributes: {
"cache.key": [key],
"cache.item_size": JSON.stringify(value).length, // Warning: if value is very big this could use lots of memory
Expand Down Expand Up @@ -92,7 +106,7 @@ const key = "myCacheKey123";

Sentry.startSpan(
{
name: "Getting auth cache",
name: key,
attributes: {
"cache.key": [key],
"network.peer.address": "cache.example.com/supercache",
Expand Down

0 comments on commit 98db824

Please sign in to comment.