-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(java): Add cache tracing integration pages #16981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b748ec3
9c620a1
a0df112
5a03ddc
bb0d523
3df4872
08fd094
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| 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. | ||
|
|
||
| Add the dependencies: | ||
|
|
||
| ```groovy {tabTitle:Gradle} | ||
| implementation 'io.sentry:sentry-jcache:{{@inject packages.version('sentry.java.jcache', '8.35.0') }}' | ||
| implementation 'com.github.ben-manes.caffeine:jcache:3.2.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> | ||
| <dependency> | ||
| <groupId>com.github.ben-manes.caffeine</groupId> | ||
| <artifactId>jcache</artifactId> | ||
| <version>3.2.0</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| Then wrap your cache with `SentryJCacheWrapper`. See the <PlatformLink to="/integrations/jcache/">JCache integration</PlatformLink> docs for setup and usage details. | ||
|
|
||
| </PlatformSection> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| 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. | ||
|
|
||
| Add the dependencies: | ||
|
|
||
| ```groovy {tabTitle:Gradle} | ||
| implementation 'io.sentry:sentry-jcache:{{@inject packages.version('sentry.java.jcache', '8.35.0') }}' | ||
| implementation 'org.ehcache:ehcache:3.10.8' | ||
| ``` | ||
|
|
||
| ```xml {tabTitle:Maven} | ||
| <dependency> | ||
| <groupId>io.sentry</groupId> | ||
| <artifactId>sentry-jcache</artifactId> | ||
| <version>{{@inject packages.version('sentry.java.jcache', '8.35.0') }}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.ehcache</groupId> | ||
| <artifactId>ehcache</artifactId> | ||
| <version>3.10.8</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| Then wrap your cache with `SentryJCacheWrapper`. See the <PlatformLink to="/integrations/jcache/">JCache integration</PlatformLink> docs for setup and usage details. | ||
|
|
||
| </PlatformSection> |
| 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." | ||
| --- | ||
|
|
||
| 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/). | ||
|
|
||
| <Alert> | ||
|
|
||
| If you're using Spring Boot with `@Cacheable` / `@CachePut` / `@CacheEvict`, you don't need this integration — cache tracing is built into the Spring Boot starter. Just enable the <PlatformLink to="/configuration/options/#enableCacheTracing">`enableCacheTracing`</PlatformLink> option (or set `sentry.enable-cache-tracing=true` in `application.properties`) and all Spring Cache operations will be traced automatically. | ||
|
|
||
| </Alert> | ||
|
|
||
| ## 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.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") | ||
| tx.makeCurrent().use { | ||
| sentryCache.put("greeting", "hello") | ||
| val value = sentryCache.get("greeting") | ||
| } | ||
| tx.finish() | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| 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 | ||
|
|
||
| Both Jedis and Lettuce provide [JCache (JSR-107)](https://github.com/redis/jedis/wiki/JCache-Support) adapters. Use them together with the <PlatformLink to="/integrations/jcache/">Sentry JCache integration</PlatformLink> to trace cache operations. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The documentation incorrectly states that Lettuce provides a JCache (JSR-107) adapter. Lettuce does not have a JCache provider, making the documented setup non-functional. Suggested FixRemove the incorrect claim that Lettuce provides a JCache adapter from the documentation. The section for using Lettuce in a "Plain Java" setup should be corrected to provide a functional integration example or clarify that an alternative like Redisson is needed for JCache support with Redis. Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
| Add the dependencies for your Redis client: | ||
|
|
||
| ### Jedis | ||
|
|
||
| ```groovy {tabTitle:Gradle} | ||
| implementation 'io.sentry:sentry-jcache:{{@inject packages.version('sentry.java.jcache', '8.35.0') }}' | ||
| implementation 'redis.clients:jedis:5.2.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> | ||
| <dependency> | ||
| <groupId>redis.clients</groupId> | ||
| <artifactId>jedis</artifactId> | ||
| <version>5.2.0</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| ### Lettuce | ||
|
|
||
| ```groovy {tabTitle:Gradle} | ||
| implementation 'io.sentry:sentry-jcache:{{@inject packages.version('sentry.java.jcache', '8.35.0') }}' | ||
| implementation 'io.lettuce:lettuce-core:6.5.5.RELEASE' | ||
| ``` | ||
|
|
||
| ```xml {tabTitle:Maven} | ||
| <dependency> | ||
| <groupId>io.sentry</groupId> | ||
| <artifactId>sentry-jcache</artifactId> | ||
| <version>{{@inject packages.version('sentry.java.jcache', '8.35.0') }}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.lettuce</groupId> | ||
| <artifactId>lettuce-core</artifactId> | ||
| <version>6.5.5.RELEASE</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| Then wrap your cache with `SentryJCacheWrapper`. See the <PlatformLink to="/integrations/jcache/">JCache integration</PlatformLink> docs for setup and usage details. | ||
|
|
||
| </PlatformSection> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(l) are we ok with the subset of the operations here? maybe, just add an e.g.
Also flush is named invalidate in code