Skip to content

feat(spring): Cache Tracing#5165

Open
adinauer wants to merge 97 commits intomainfrom
feat/cache-tracing
Open

feat(spring): Cache Tracing#5165
adinauer wants to merge 97 commits intomainfrom
feat/cache-tracing

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Mar 5, 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
  • #5190 — Port cache tracing to Spring Boot 3 Jakarta + samples
  • #5191 — Port cache tracing to Spring Boot 2 + samples
  • #5192 — Skip cache span data when child span is NoOp
  • #5201 — Add db.operation.name attribute to cache spans
  • #5202 — Instrument putIfAbsent, replace, and getAndReplace
  • #5203 — Fix cache hit detection for typed get and fix jcache docs link
  • #5204 — Use method-specific span operations for cache spans
  • #5205 — Merge startSpan helpers into shared core method
  • #5206 — Move operation attribute to centralized CACHE_OPERATION_KEY constant
  • #5207 — Add cache.write boolean span attribute
  • #5208 — Use comma-joined keys as span description for bulk JCache operations
  • #5209 — Remove _KEY suffix from cache SpanDataConvention constants
  • #5210 — Fix get(key, type) double-call in SentryCacheWrapper
  • #5212 — Fix cache evict system test to match actual span op
  • #5228 — Add missing cache key assertions and use exact equals

Collection PR for the Cache Tracing stack. Squash-merge this once all stack PRs are merged.

📜 Description

Adds auto-instrumentation for Spring's Cache abstraction, producing cache.get, cache.put, cache.remove, and cache.flush spans per the Sentry cache module spec.

💡 Motivation and Context

Closes #4120

💚 How did you test it?

See individual PRs for test details.

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • No breaking change or entry added to the changelog.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 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 ✨

  • (replay) Add beforeErrorSampling callback to Session Replay by romtsn in #5214
  • (spring) Cache Tracing by adinauer in #5165

Internal Changes 🔧

  • (deps) Update Native SDK to v0.13.3 by github-actions in #5215

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

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

Generated by 🚫 dangerJS against 616aeab

adinauer and others added 4 commits March 9, 2026 09:06
…tion

- Use cache key as span description instead of cache name, matching
  the spec and other SDKs (Python, JavaScript)
- Skip instrumentation for putIfAbsent since we cannot know if a write
  actually occurred; override to bypass default get()+put() delegation
- Wrap valueLoader Callable in get(key, Callable) to detect cache
  hit/miss instead of always reporting hit=true
- Update tests to match new behavior

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…uration

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

sentry bot commented Mar 9, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.36.0 (1) release Install Build

@adinauer adinauer force-pushed the feat/cache-tracing branch from b2dbb4d to 7735a81 Compare March 9, 2026 08:11
@sentry
Copy link

sentry bot commented Mar 9, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

adinauer and others added 3 commits March 9, 2026 09:24
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use Caffeine as the cache provider instead of a plain
ConcurrentMapCacheManager. Spring Boot auto-configures
CaffeineCacheManager when Caffeine is on the classpath,
so the explicit CacheManager bean is no longer needed.

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

github-actions bot commented Mar 9, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 321.08 ms 392.43 ms 71.35 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
27d7cf8 314.17 ms 347.00 ms 32.83 ms
ff8eea4 313.42 ms 337.08 ms 23.66 ms
b750b96 408.98 ms 480.32 ms 71.34 ms
0eaac1e 322.53 ms 389.31 ms 66.78 ms
18c0bc2 306.73 ms 349.77 ms 43.03 ms
abf451a 332.82 ms 403.67 ms 70.85 ms
62b579c 349.26 ms 426.26 ms 77.00 ms
f064536 335.52 ms 408.79 ms 73.27 ms
70118e9 380.00 ms 475.72 ms 95.72 ms
85d7417 347.21 ms 394.35 ms 47.15 ms

App size

Revision Plain With Sentry Diff
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
ff8eea4 1.58 MiB 2.28 MiB 718.64 KiB
b750b96 1.58 MiB 2.10 MiB 533.19 KiB
0eaac1e 1.58 MiB 2.19 MiB 619.17 KiB
18c0bc2 1.58 MiB 2.13 MiB 557.33 KiB
abf451a 1.58 MiB 2.20 MiB 635.29 KiB
62b579c 0 B 0 B 0 B
f064536 1.58 MiB 2.20 MiB 633.90 KiB
70118e9 1.58 MiB 2.29 MiB 719.84 KiB
85d7417 1.58 MiB 2.10 MiB 533.44 KiB

@sentry
Copy link

sentry bot commented Mar 9, 2026

Sentry Build Distribution

App Version Configuration
SDK Size 8.34.1 (1) release

adinauer and others added 6 commits March 9, 2026 16:23
Like putIfAbsent, these are conditional writes that may be no-ops.
Emitting a cache.put span for them would be misleading.
startChild can return a NoOp span (e.g. when span limit is reached).
Skip instrumentation in that case to avoid unnecessary work.
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.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
getsentry-bot and others added 20 commits March 23, 2026 13:41
feat(spring7): [Cache Tracing 8] Add retrieve() overrides for reactive/async cache support
feat(spring-jakarta): [Cache Tracing 9] Port cache tracing to Spring Boot 3 + samples
feat(spring): [Cache Tracing 10] Port cache tracing to Spring Boot 2 + samples
fix(spring): [Cache Tracing 11] Skip cache span data when child span is NoOp
…on-name

feat(spring): [Cache Tracing 12] Add db.operation.name attribute to cache spans
…-conditional-ops

feat(spring): [Cache Tracing 13] Instrument putIfAbsent, replace, and getAndReplace
…it-detection

fix(spring): [Cache Tracing 14] Fix cache hit detection for typed get and fix jcache docs link
…ific-ops

ref(spring): [Cache Tracing 15] Use method-specific span operations for cache spans
…span-helpers

ref(jcache): [Cache Tracing 16] Merge startSpan helpers into shared core method
…tion-key

ref(cache): [Cache Tracing 17] Move operation attribute to centralized CACHE_OPERATION_KEY
feat(cache): [Cache Tracing 18] Add cache.write boolean span attribute
…-description

fix(jcache): [Cache Tracing 19] Use comma-joined keys as span description for bulk operations
…tants

ref(cache): [Cache Tracing 20] Remove _KEY suffix from cache SpanDataConvention constants
…ouble-call

fix(spring): [Cache Tracing 21] Fix get(key, type) double-call in SentryCacheWrapper
…m-test

fix(samples): [Cache Tracing 22] Fix cache evict system test to match actual span op
…w-changes

test(cache): [Cache Tracing 23] Add missing cache key assertions and use exact equals
@adinauer
Copy link
Member Author

@sentry review

@adinauer
Copy link
Member Author

cursor review

CHANGELOG.md Outdated

### Features

- Add cache tracing instrumentation for Spring Boot 2, 3, and 4 ([#5172](https://github.com/getsentry/sentry-java/pull/5172), [#5173](https://github.com/getsentry/sentry-java/pull/5173), [#5174](https://github.com/getsentry/sentry-java/pull/5174), [#5190](https://github.com/getsentry/sentry-java/pull/5190), [#5191](https://github.com/getsentry/sentry-java/pull/5191))
Copy link
Member Author

Choose a reason for hiding this comment

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

Update changelog entries to 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.

✅ Bugbot reviewed your changes and found no new issues!

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

@adinauer adinauer marked this pull request as ready for review March 23, 2026 15:42
Copy link
Collaborator

@lbloder lbloder left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

Java SDK Cache instrumentation

3 participants