Skip to content

feat(spring): [Cache Tracing 13] Instrument putIfAbsent, replace, and getAndReplace#5202

Draft
adinauer wants to merge 1 commit intofeat/cache-tracing-db-operation-namefrom
feat/cache-tracing-instrument-conditional-ops
Draft

feat(spring): [Cache Tracing 13] Instrument putIfAbsent, replace, and getAndReplace#5202
adinauer wants to merge 1 commit intofeat/cache-tracing-db-operation-namefrom
feat/cache-tracing-instrument-conditional-ops

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Mar 17, 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
  • This PR — Instrument putIfAbsent, replace, and getAndReplace

📜 Description

Add span instrumentation to previously-passthrough conditional cache operations:

Spring Cache (all 3 modules):

  • putIfAbsent(key, value) — now creates a cache.put span

JCache:

  • putIfAbsent(key, value)cache.put span
  • replace(key, oldValue, newValue)cache.put span (conditional CAS)
  • replace(key, value)cache.put span (replace if present)
  • getAndReplace(key, value)cache.put span (atomic get-and-replace)

All follow the same error-handling pattern as existing instrumented methods (try/catch/finally with SpanStatus.INTERNAL_ERROR + setThrowable on exception). Each sets db.operation.name to the method name via the startSpan helper.

💡 Motivation and Context

These operations were previously skipped because they are conditional writes that may be no-ops. However, they still represent meaningful cache interactions that should be visible in the Sentry Caches UI for observability. The db.operation.name attribute (added in the previous PR) allows distinguishing them from unconditional put operations.

💚 How did you test it?

Updated existing passthrough tests to verify span creation, operation, status, cache.key, and db.operation.name attributes. All tests pass across all 4 modules.

📝 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

None — completes coverage of all data operations in Spring Cache and JCache wrappers.

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

#skip-changelog

…e operations

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

github-actions bot commented Mar 17, 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 17, 2026

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

Generated by 🚫 dangerJS against b8911d9

@sentry
Copy link

sentry bot commented Mar 17, 2026

Sentry Build Distribution

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

@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

@github-actions
Copy link
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 319.06 ms 371.67 ms 52.61 ms
Size 0 B 0 B 0 B

Baseline results on branch: feat/cache-tracing-db-operation-name

Startup times

Revision Plain With Sentry Diff
3a20e54 330.20 ms 383.47 ms 53.27 ms

App size

Revision Plain With Sentry Diff
3a20e54 0 B 0 B 0 B

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.

2 participants