Skip to content

feat(spring7): [Cache Tracing 8] Add retrieve() overrides for reactive/async cache support#5184

Draft
adinauer wants to merge 1 commit intofeat/cache-tracing-all-samplesfrom
feat/cache-tracing-retrieve
Draft

feat(spring7): [Cache Tracing 8] Add retrieve() overrides for reactive/async cache support#5184
adinauer wants to merge 1 commit intofeat/cache-tracing-all-samplesfrom
feat/cache-tracing-retrieve

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Mar 10, 2026

PR Stack (Cache Tracing)

  • #5172 — Add SentryCacheWrapper and SentryCacheManagerWrapper
  • #5173 — Add enableCacheTracing option
  • #5174 — Add BeanPostProcessor and auto-configuration
  • #5175 — Add cache tracing e2e sample
  • #5179 — Add SentryJCacheWrapper for JCache (JSR-107)
  • #5182 — Add JCache console sample
  • #5183 — Add cache tracing to all Spring Boot 4 samples
  • #5184 — Add retrieve() overrides for reactive/async cache support

📜 Description

Adds retrieve(Object key) and retrieve(Object key, Supplier<CompletableFuture<T>>) overrides to SentryCacheWrapper.

Spring 6.1+ added these two methods to the Cache interface for non-blocking cache operations. Spring's CacheInterceptor calls them when @Cacheable is placed on methods returning CompletableFuture<T> or Mono<T>. Without these overrides, the default Cache.retrieve() throws UnsupportedOperationException, meaning any app using reactive @Cacheable with cache tracing enabled would crash.

Key design decisions:

  • Spans are started synchronously and finished asynchronously via CompletableFuture.whenComplete()
  • retrieve(key) handles three result states: null return (immediate miss), CF resolving to null (late miss), CF resolving to value (hit)
  • retrieve(key, valueLoader) uses the same AtomicBoolean loader-tracking pattern as get(key, Callable) for cache hit detection

💡 Motivation and Context

This is a functional bug fix. The SentryCacheWrapper implements Cache but didn't override the retrieve() default methods, which throw UnsupportedOperationException. When cache tracing is enabled and the wrapper intercepts the cache, reactive @Cacheable methods crash instead of working.

💚 How did you test it?

  • 10 new unit tests in SentryCacheWrapperTest covering:
    • Cache hit/miss detection for both retrieve variants
    • Immediate null return vs late-determined null
    • Async error handling (failed futures)
    • Synchronous delegate exceptions
    • No-span behavior when tracing disabled

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Port retrieve() overrides to sentry-spring-jakarta when cache classes are ported there.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

#skip-changelog

Adds support for Spring 6.1+ async cache operations (CompletableFuture
and Mono/Flux). Without these overrides, @Cacheable on reactive return
types crashes with UnsupportedOperationException.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 41872ad

@adinauer
Copy link
Member Author

cursor review

@adinauer
Copy link
Member Author

@sentry review

@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@github-actions
Copy link
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 366.36 ms 466.94 ms 100.58 ms
Size 0 B 0 B 0 B

Baseline results on branch: feat/cache-tracing-all-samples

Startup times

Revision Plain With Sentry Diff
9ce8a42 333.64 ms 422.30 ms 88.66 ms

App size

Revision Plain With Sentry Diff
9ce8a42 0 B 0 B 0 B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant