Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/platforms/java/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ Set this boolean to `false` to disable tracing for `OPTIONS` requests. This opti

</SdkOption>

<SdkOption name="enableCacheTracing" type="boolean" defaultValue="false">

Whether cache operations (`get`, `put`, `remove`, `flush`) should be traced. When enabled, the SDK creates spans for cache operations performed through the <PlatformLink to="/integrations/jcache/">JCache integration</PlatformLink> or Spring Cache (e.g. `@Cacheable`, `@CachePut`, `@CacheEvict`).

</SdkOption>

## Profiling Options

<SdkOption name="profileSessionSampleRate" type="float" availableSince="8.23.0">
Expand Down
37 changes: 37 additions & 0 deletions docs/platforms/java/common/integrations/caffeine.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Caffeine Integration
description: "Learn how to trace Caffeine cache operations with Sentry."
---

Sentry can trace cache operations performed by [Caffeine](https://github.com/ben-manes/caffeine), the high-performance in-memory caching library for Java. Cache spans appear in Sentry's [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/).

<PlatformSection supported={["java.spring-boot"]}>

## Spring Boot

If you're using Caffeine as your Spring Boot cache provider, cache tracing is built into the Sentry Spring Boot starter. Enable it in your configuration:

```properties {tabTitle:application.properties}
sentry.enable-cache-tracing=true
sentry.traces-sample-rate=1.0
```

```yaml {tabTitle:application.yml}
sentry:
enable-cache-tracing: true
traces-sample-rate: 1.0
```

All `@Cacheable`, `@CachePut`, and `@CacheEvict` operations will automatically produce Sentry spans — no additional dependencies or code changes required.

See <PlatformLink to="/configuration/options/#enableCacheTracing">`enableCacheTracing`</PlatformLink> for more details on this option.

</PlatformSection>

<PlatformSection notSupported={["java.spring-boot"]}>

## Plain Java

Caffeine provides a [JCache (JSR-107) adapter](https://github.com/ben-manes/caffeine/wiki/JCache). Use it together with the <PlatformLink to="/integrations/jcache/">Sentry JCache integration</PlatformLink> to trace cache operations.

</PlatformSection>
37 changes: 37 additions & 0 deletions docs/platforms/java/common/integrations/ehcache.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Ehcache Integration
description: "Learn how to trace Ehcache cache operations with Sentry."
---

Sentry can trace cache operations performed by [Ehcache](https://www.ehcache.org/), a widely-used Java caching library. Cache spans appear in Sentry's [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/).

<PlatformSection supported={["java.spring-boot"]}>

## Spring Boot

If you're using Ehcache as your Spring Boot cache provider, cache tracing is built into the Sentry Spring Boot starter. Enable it in your configuration:

```properties {tabTitle:application.properties}
sentry.enable-cache-tracing=true
sentry.traces-sample-rate=1.0
```

```yaml {tabTitle:application.yml}
sentry:
enable-cache-tracing: true
traces-sample-rate: 1.0
```

All `@Cacheable`, `@CachePut`, and `@CacheEvict` operations will automatically produce Sentry spans — no additional dependencies or code changes required.

See <PlatformLink to="/configuration/options/#enableCacheTracing">`enableCacheTracing`</PlatformLink> for more details on this option.

</PlatformSection>

<PlatformSection notSupported={["java.spring-boot"]}>

## Plain Java

Ehcache 3 implements the [JCache (JSR-107)](https://www.ehcache.org/documentation/3.0/107.html) API natively. Use it together with the <PlatformLink to="/integrations/jcache/">Sentry JCache integration</PlatformLink> to trace cache operations.

</PlatformSection>
136 changes: 136 additions & 0 deletions docs/platforms/java/common/integrations/jcache.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: JCache Integration
description: "Learn how to trace cache operations using the Sentry JCache (JSR-107) integration."
notSupported:
- java.spring-boot
---

Sentry's [JCache (JSR-107)](https://www.jcp.org/en/jsr/detail?id=107) integration automatically creates spans for cache operations like `get`, `put`, `remove`, and `clear`. It works with any JCache provider (Caffeine, Ehcache, Hazelcast, etc.).

Cache spans appear in Sentry's [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/).

## Install

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-jcache:{{@inject packages.version('sentry.java.jcache', '8.35.0') }}'
```

```xml {tabTitle:Maven}
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-jcache</artifactId>
<version>{{@inject packages.version('sentry.java.jcache', '8.35.0') }}</version>
</dependency>
```

```scala {tabTitle: SBT}
libraryDependencies += "io.sentry" % "sentry-jcache" % "{{@inject packages.version('sentry.java.jcache', '8.35.0') }}"
```

For other dependency managers, check out the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-jcache).

## Set Up

Enable cache tracing in your Sentry configuration:

```java {tabTitle:Java}
Sentry.init(options -> {
options.setDsn("___DSN___");
options.setTracesSampleRate(1.0);
options.setEnableCacheTracing(true);
});
```

```kotlin {tabTitle:Kotlin}
Sentry.init { options ->
options.dsn = "___DSN___"
options.tracesSampleRate = 1.0
options.isEnableCacheTracing = true
}
```

Wrap your `javax.cache.Cache` instance with `SentryJCacheWrapper`:

```java {tabTitle:Java}
import io.sentry.jcache.SentryJCacheWrapper;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.spi.CachingProvider;

CachingProvider provider = Caching.getCachingProvider();
CacheManager manager = provider.getCacheManager();

Cache<String, String> cache = manager.getCache("myCache");
Cache<String, String> sentryCache = new SentryJCacheWrapper<>(cache);

// Use sentryCache — all operations produce Sentry spans
sentryCache.put("key", "value"); // cache.put span
String val = sentryCache.get("key"); // cache.get span (cache.hit = true)
sentryCache.remove("key"); // cache.remove span
sentryCache.clear(); // cache.clear span
```

```kotlin {tabTitle:Kotlin}
import io.sentry.jcache.SentryJCacheWrapper
import javax.cache.Caching

val provider = Caching.getCachingProvider()
val manager = provider.cacheManager

val cache = manager.getCache<String, String>("myCache")
val sentryCache = SentryJCacheWrapper(cache)

// Use sentryCache — all operations produce Sentry spans
sentryCache.put("key", "value") // cache.put span
val value = sentryCache.get("key") // cache.get span (cache.hit = true)
sentryCache.remove("key") // cache.remove span
sentryCache.clear() // cache.clear span
```

## Traced Operations

All JCache operations are traced. Each method creates a span with the operation `cache.<methodName>` (e.g. `cache.get`, `cache.putIfAbsent`, `cache.removeAll`).

## Span Data

| Key | Type | Description |
|---|---|---|
| `cache.hit` | boolean | Whether the cache lookup returned a value (read spans only) |
| `cache.key` | list of strings | The cache key(s) involved in the operation |
| `cache.operation` | string | The JCache method name (e.g. `get`, `putIfAbsent`, `removeAll`) |
| `cache.write` | boolean | Whether the operation modified the cache. Always `true` for unconditional writes (`put`, `putAll`, `remove`, `clear`); reflects the actual outcome for conditional operations (`putIfAbsent`, `replace`, `getAndReplace`) and value-matched removes |

Bulk operations (`getAll`, `putAll`, `removeAll`) create a single span with all keys listed in `cache.key`.

## Verify

To verify, trigger a cache operation within an active transaction and check the [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/) or the trace view in Sentry.

```java {tabTitle:Java}
import io.sentry.ISentryLifecycleToken;
import io.sentry.ITransaction;
import io.sentry.Sentry;

ITransaction tx = Sentry.startTransaction("test-cache", "task");
try (ISentryLifecycleToken ignored = tx.makeCurrent()) {
sentryCache.put("greeting", "hello");
String value = sentryCache.get("greeting");
} finally {
tx.finish();
}
```

```kotlin {tabTitle:Kotlin}
import io.sentry.Sentry

val tx = Sentry.startTransaction("test-cache", "task")
try {
tx.makeCurrent().use {
sentryCache.put("greeting", "hello")
val value = sentryCache.get("greeting")
}
} finally {
tx.finish()
}
```
43 changes: 43 additions & 0 deletions docs/platforms/java/common/integrations/redis.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Redis Integration
description: "Learn how to trace Redis cache operations with Sentry."
---

Sentry can trace cache operations performed through [Redis](https://redis.io/) using Jedis or Lettuce as the client library. Cache spans appear in Sentry's [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/).

<PlatformSection supported={["java.spring-boot"]}>

## Spring Boot

If you're using Redis (via Spring Data Redis with Jedis or Lettuce) as your Spring Boot cache provider, cache tracing is built into the Sentry Spring Boot starter. Enable it in your configuration:

```properties {tabTitle:application.properties}
sentry.enable-cache-tracing=true
sentry.traces-sample-rate=1.0
```

```yaml {tabTitle:application.yml}
sentry:
enable-cache-tracing: true
traces-sample-rate: 1.0
```

All `@Cacheable`, `@CachePut`, and `@CacheEvict` operations will automatically produce Sentry spans — no additional dependencies or code changes required.

See <PlatformLink to="/configuration/options/#enableCacheTracing">`enableCacheTracing`</PlatformLink> for more details on this option.

</PlatformSection>

<PlatformSection notSupported={["java.spring-boot"]}>

## Plain Java

Jedis provides a [JCache (JSR-107)](https://github.com/redis/jedis/wiki/JCache-Support) adapter. Use it together with the <PlatformLink to="/integrations/jcache/">Sentry JCache integration</PlatformLink> to trace cache operations.

<Alert>

Lettuce does not provide a JCache adapter, so the JCache-based approach described here only works with Jedis. For Lettuce-based cache tracing, use Spring Boot with Spring Data Redis.

</Alert>

</PlatformSection>
Loading