-
-
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
Draft
adinauer
wants to merge
7
commits into
master
Choose a base branch
from
adinauer/java-cache-tracing-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+341
−0
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b748ec3
docs(java): Add cache tracing integration pages
adinauer 9c620a1
Merge branch 'master' into adinauer/java-cache-tracing-docs
adinauer a0df112
docs(java): Simplify verify snippet in jcache.mdx
adinauer 5a03ddc
docs(java): Add Kotlin snippets to jcache.mdx
adinauer bb0d523
Apply suggestion from @adinauer
adinauer 3df4872
remove spring boot config sentence from option
adinauer 08fd094
docs(java): Update JCache traced operations and span data
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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