Cache

The SDK's caching integration is agnostic to the underlying engine used. In most cases, the SDK will instrument existing cache abstractions in certain frameworks or libraries.

Span conventions

Span Operations

Span OPDescription
cache.getA single item or multiple items are retrieved from the cache
cache.putA single item or multiple items are written to the cache
cache.removeA single item or multiple items are removed from the cache
cache.flushThe entire content of the cache is deleted

Span Data

Data KeyTypeDescriptionConditions
cache.hitboolcache hit or missrequired only on read-operations (cache.get)
cache.key arraythe key(s) involved in the operationrequired only on operations that have a key

The following data attributes are only to be set if exposed by the instrumented cache abstraction or retrievable with minimal overhead.

Data KeyTypeDescriptionConditions
cache.item_size intthe size of the item/items read/written/deleted in bytesonly on operations that have a key
cache.success boolhas the command succeeded
cache.ttl intthe time to life in secondsonly on operations that have a key
network.peer.addressstringThe hostname of the cache instance
network.peer.portintthe port used by the cache instance

Additionally, the span.status can be used to signal if the operation was successful (success) or failed (error).

Instrumentation

Once an application performs a caching operation, the SDK creates a new span based on the operation, wrapping any spans of the underlying engine as direct children.

Example

Copied
item = Cache::get('posts')

This should result in the following spans, assuming a cache hit with an underlying Redis instance being used.

Copied
<span op:"cache.get" description:"posts" cache.key:"posts" cache.hit=true>
	<span op:db.redis description:"GET posts"></span>
</span>

SDK Options

If convenient, the SDK can optionally offer a cache_prefixes option, that wraps existing instrumentations into a cache span. This will likely only be useful if Redis is being used as a cache.

Copied
Sentry.init({
  integrations: [
    new Sentry.Integrations.Redis({
	    cachePrefixes: ['posts:', 'authors:'],
    }),
  ],
})

In this example, all Redis queries involving keys that match posts:* and authors:* will be wrapped into cache.* span.

You can edit this page on GitHub.