Skip to content

feat(jcache): [Cache Tracing 5] Add SentryJCacheWrapper for JCache (JSR-107)#5179

Open
adinauer wants to merge 10 commits intofeat/cache-tracing-samplefrom
feat/cache-tracing-jcache
Open

feat(jcache): [Cache Tracing 5] Add SentryJCacheWrapper for JCache (JSR-107)#5179
adinauer wants to merge 10 commits intofeat/cache-tracing-samplefrom
feat/cache-tracing-jcache

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Mar 9, 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 a new sentry-jcache module that provides cache tracing for apps using the JCache (JSR-107) API. SentryJCacheWrapper<K,V> implements javax.cache.Cache<K,V> and creates Sentry spans for cache operations:

  • cache.getget, getAll, invoke, invokeAll
  • cache.putput, getAndPut, putAll, replace, getAndReplace
  • cache.removeremove, getAndRemove, removeAll
  • cache.flushclear
  • Passthrough (no spans) — putIfAbsent, containsKey, close, loadAll, metadata methods, listener registration, iterator

Sets cache.hit, cache.key span attributes via SpanDataConvention. Gated on isEnableCacheTracing(). Trace origin: auto.cache.jcache.

💡 Motivation and Context

Spring Cache covers Spring users, but many Java apps use JCache directly (plain Java, Micronaut, CDI/Jakarta EE). This module provides the same cache tracing experience for those users. JCache never migrated to Jakarta namespace, so javax.cache works everywhere.

💚 How did you test it?

  • 32 unit tests covering all instrumented methods, hit/miss detection, passthrough operations, error handling, and option gating.

📝 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

  • Console sample showcasing manual JCache usage
  • Port cache classes to sentry-spring-jakarta and sentry-spring

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 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).


New Features ✨

Core

  • [Cache Tracing 2] Add enableCacheTracing option by adinauer in #5173
  • [Cache Tracing 2] Add enableCacheTracing option by adinauer in #5163

Spring

  • [Cache Tracing 1] Add SentryCacheWrapper and SentryCacheManagerWrapper by adinauer in #5172
  • [Cache Tracing 3] Add BeanPostProcessor and auto-configuration by adinauer in #5174
  • [Cache Tracing 3] Add BeanPostProcessor and auto-configuration by adinauer in #5164
  • [Cache Tracing 1] Add SentryCacheWrapper and SentryCacheManagerWrapper by adinauer in #5162
  • [Cache Tracing 1] Add SentryCacheWrapper and SentryCacheManagerWrapper by adinauer in #5137

Other

  • (anr) Profile main thread when ANR and report ANR profiles to Sentry by markushi in #4899
  • (jcache) [Cache Tracing 5] Add SentryJCacheWrapper for JCache (JSR-107) by adinauer in #5179

Bug Fixes 🐛

  • Remove the dependency on protobuf-lite for tombstones by supervacuus in #5157

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

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

Generated by 🚫 dangerJS against bbbb702

@sentry
Copy link

sentry bot commented Mar 9, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 405.46 ms 514.34 ms 108.88 ms
Size 0 B 0 B 0 B

Baseline results on branch: feat/cache-tracing-sample

Startup times

Revision Plain With Sentry Diff
0ceb700 305.81 ms 355.91 ms 50.10 ms
855766f 364.82 ms 427.16 ms 62.35 ms
eeb463c 311.36 ms 371.79 ms 60.43 ms
b2b863f 338.62 ms 376.54 ms 37.92 ms

App size

Revision Plain With Sentry Diff
0ceb700 0 B 0 B 0 B
855766f 0 B 0 B 0 B
eeb463c 0 B 0 B 0 B
b2b863f 0 B 0 B 0 B

Previous results on branch: feat/cache-tracing-jcache

Startup times

Revision Plain With Sentry Diff
bff862e 315.13 ms 364.41 ms 49.28 ms
10c6fa4 308.73 ms 384.38 ms 75.66 ms
290c35b 320.64 ms 355.09 ms 34.45 ms
c3caf85 313.96 ms 352.98 ms 39.02 ms

App size

Revision Plain With Sentry Diff
bff862e 0 B 0 B 0 B
10c6fa4 0 B 0 B 0 B
290c35b 0 B 0 B 0 B
c3caf85 0 B 0 B 0 B

Like putIfAbsent, these are conditional writes that may be no-ops.
Emitting a cache.put span for them would be misleading.
@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

startChild can return a NoOp span (e.g. when span limit is reached).
Skip instrumentation in that case to avoid unnecessary work.
@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

removeAll() with no args removes all entries, which is semantically
equivalent to clear(). Use cache.flush instead of cache.remove.
The keyed removeAll(Set) remains cache.remove.
@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

adinauer and others added 2 commits March 10, 2026 13:04
@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

@adinauer
Copy link
Member Author

cursor review

@adinauer
Copy link
Member Author

@sentry review

1 similar comment
@adinauer
Copy link
Member Author

@sentry review

@adinauer
Copy link
Member Author

cursor review

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

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

} finally {
span.finish();
}
}
Copy link

Choose a reason for hiding this comment

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

Conditional remove(K,V) instrumented unlike other conditional ops

Low Severity

remove(K, V) is a conditional operation (only removes if the current value matches) but is instrumented with a cache.remove span. Meanwhile, replace(K, V), replace(K, V, V), and getAndReplace are also conditional operations but are explicitly made passthrough with the comment that "conditional writes…emitting a cache.put span for a potential no-op would be misleading." The same reasoning applies equally to remove(K, V) — it can be a no-op when the value doesn't match — yet it still emits a cache.remove span with SpanStatus.OK.

Additional Locations (1)

Fix in Cursor Fix in Web

@sentry
Copy link

sentry bot commented Mar 10, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

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