feat(spring-jakarta): [Cache Tracing 9] Port cache tracing to Spring Boot 3 + samples#5190
feat(spring-jakarta): [Cache Tracing 9] Port cache tracing to Spring Boot 3 + samples#5190adinauer wants to merge 2 commits intofeat/cache-tracing-retrievefrom
Conversation
Port cache tracing classes from sentry-spring-7 to sentry-spring-jakarta, covering Spring Boot 3 (Spring Framework 6.x) users. Includes SentryCacheWrapper, SentryCacheManagerWrapper, SentryCacheBeanPostProcessor, and auto-configuration in sentry-spring-boot-jakarta. The retrieve() overrides for CompletableFuture/reactive cache operations are included and safe on Spring 6.0 (where retrieve() doesn't exist on the Cache interface) — they're simply dead code, never called by the framework until Spring 6.1+. Co-Authored-By: Claude <noreply@anthropic.com>
Add CacheController, TodoService with @Cacheable/@CachePut/@CacheEvict, Caffeine cache config, and CacheSystemTest e2e tests to all four Jakarta sample modules: - sentry-samples-spring-boot-jakarta - sentry-samples-spring-boot-jakarta-opentelemetry - sentry-samples-spring-boot-jakarta-opentelemetry-noagent - sentry-samples-spring-boot-webflux-jakarta Co-Authored-By: Claude <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
|
Sentry Build Distribution
|
Performance metrics 🚀
|
|
@sentry review |
|
cursor review |
| return result.whenComplete( | ||
| (value, throwable) -> { |
There was a problem hiding this comment.
Bug: The retrieve(key, valueLoader) method in SentryCacheWrapper does not handle null returns from the delegate, leading to a NullPointerException when .whenComplete() is called.
Severity: HIGH
Suggested Fix
Add a null check for the result variable after the call to delegate.retrieve(key, valueLoader). If result is null, it should be handled gracefully, similar to how the retrieve(Object key) overload handles nulls, to prevent the NullPointerException.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location:
sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/cache/SentryCacheWrapper.java#L166-L167
Potential issue: In `SentryCacheWrapper`, the `retrieve(Object key,
Supplier<CompletableFuture<T>> valueLoader)` method calls `delegate.retrieve(key,
valueLoader)` but does not check if the result is `null` before calling
`.whenComplete()` on it. According to Spring Cache documentation, the `retrieve` method
can return `null` to signal an immediate cache miss. In such cases, the current
implementation will throw a `NullPointerException`, causing a runtime crash and
potentially leaving a Sentry span unfinished. This affects applications using reactive
`@Cacheable` methods with a cache implementation that can return `null` from this
method.
Did we get this right? 👍 / 👎 to inform future reviews.
PR Stack (Cache Tracing)
📜 Description
Port cache tracing classes from
sentry-spring-7tosentry-spring-jakarta(Spring Boot 3 / Spring Framework 6), including:SentryCacheWrapper,SentryCacheManagerWrapper,SentryCacheBeanPostProcessorinio.sentry.spring.jakarta.cachesentry-spring-boot-jakarta'sSentryAutoConfigurationretrieve()overrides for reactive/async cache operations (safe on Spring 6.0 as dead code)Also adds cache tracing samples and e2e tests to all 4 Spring Boot 3 sample modules:
sentry-samples-spring-boot-jakartasentry-samples-spring-boot-jakarta-opentelemetrysentry-samples-spring-boot-jakarta-opentelemetry-noagentsentry-samples-spring-boot-webflux-jakartaEach sample includes
CacheController,TodoServicewith@Cacheable/@CachePut/@CacheEvict, Caffeine config, andCacheSystemTest.💡 Motivation and Context
Spring Boot 3 is still the majority of production users. Without this port, cache tracing would only be available on Spring Boot 4.
💚 How did you test it?
./gradlew :sentry-spring-jakarta:test --tests="io.sentry.spring.jakarta.cache.*"spotlessApply, API dump regenerated📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
None — this completes the Spring Boot 3 port for cache tracing.
#skip-changelog