Skip to content

feat(spring): Cache Tracing#5165

Merged
adinauer merged 100 commits intomainfrom
feat/cache-tracing
Mar 25, 2026
Merged

feat(spring): Cache Tracing#5165
adinauer merged 100 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 ✨

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

Bug Fixes 🐛

  • (replay) Text layouts with center/end alignment return incorrect masking bounding box by markushi in #5218

Internal Changes 🔧

  • (deps) Update Native SDK to v0.13.3 by github-actions in #5215
  • (opentelemetry) Bump OpenTelemetry dependencies by adinauer in #5225

🤖 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 43e78bb

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 344.04 ms 420.47 ms 76.43 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
abfcc92 304.04 ms 370.33 ms 66.29 ms
3699cd5 423.60 ms 495.52 ms 71.92 ms
b3d8889 371.33 ms 426.24 ms 54.92 ms
55aaf9b 336.43 ms 364.14 ms 27.71 ms
6727e14 337.22 ms 373.94 ms 36.71 ms
f634d01 359.58 ms 433.88 ms 74.30 ms
ee747ae 374.71 ms 455.18 ms 80.47 ms
bbc35bb 324.88 ms 425.73 ms 100.85 ms
f064536 327.04 ms 405.35 ms 78.31 ms
ee747ae 400.46 ms 423.61 ms 23.15 ms

App size

Revision Plain With Sentry Diff
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
3699cd5 1.58 MiB 2.10 MiB 533.45 KiB
b3d8889 1.58 MiB 2.10 MiB 535.07 KiB
55aaf9b 0 B 0 B 0 B
6727e14 1.58 MiB 2.28 MiB 718.64 KiB
f634d01 1.58 MiB 2.10 MiB 533.40 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
f064536 1.58 MiB 2.20 MiB 633.90 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB

Previous results on branch: feat/cache-tracing

Startup times

Revision Plain With Sentry Diff
2677334 321.08 ms 392.43 ms 71.35 ms

App size

Revision Plain With Sentry Diff
2677334 0 B 0 B 0 B

@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>
adinauer added 13 commits March 23, 2026 15:21
…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

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 👍

Set cache.write based on delegate.invalidate() result instead of always true.
This keeps span data aligned with Spring's invalidate semantics when no
entries were present.

Add tests in spring, spring-jakarta, and spring-7 wrappers to cover the
false return path and assert cache.write is false.

Co-Authored-By: Claude <noreply@anthropic.com>
…cache-write

fix(spring): [Cache Tracing 24] Track invalidate cache.write accurately
@adinauer adinauer merged commit 028aa67 into main Mar 25, 2026
67 checks passed
@adinauer adinauer deleted the feat/cache-tracing branch March 25, 2026 10:14
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