Skip to content

fix(spring): [Cache Tracing 24] Track invalidate cache.write accurately#5231

Merged
adinauer merged 1 commit intofeat/cache-tracingfrom
fix/cache-tracing-invalidate-cache-write
Mar 25, 2026
Merged

fix(spring): [Cache Tracing 24] Track invalidate cache.write accurately#5231
adinauer merged 1 commit intofeat/cache-tracingfrom
fix/cache-tracing-invalidate-cache-write

Conversation

@adinauer
Copy link
Member

PR Stack (Cache Tracing)

  • #5165 — Collection PR
  • (this PR) [Cache Tracing 24] Track invalidate cache.write accurately

Note: All previous Cache Tracing stack PRs (#5172#5228) have already been merged into the collection branch.


📜 Description

This fixes cache span data correctness for invalidate() across Spring cache wrappers (sentry-spring, sentry-spring-jakarta, and sentry-spring-7).

Previously, cache.write was always set to true after delegate.invalidate(), even when invalidate() returned false (no mappings were present or presence could not be determined). This PR sets cache.write to the actual returned boolean.

It also adds regression tests in all three wrapper test suites to verify the false path.

💡 Motivation and Context

During PR review, we found that span data could over-report writes for cache flush operations. This makes span attributes less trustworthy for downstream analysis.

This change aligns span data with Spring's documented Cache.invalidate() semantics.

💚 How did you test it?

  • ./gradlew :sentry-spring:test --tests="*SentryCacheWrapperTest*" :sentry-spring-jakarta:test --tests="*SentryCacheWrapperTest*" :sentry-spring-7:test --tests="*SentryCacheWrapperTest*"
  • Added new test case in each module: invalidate sets cache write false when cache had no mappings

📝 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

  • Merge into the collection branch and include this fix in the final squash merge of feat/cache-tracing to main.

#skip-changelog

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

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>
@github-actions
Copy link
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 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.

@sentry
Copy link

sentry bot commented Mar 25, 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 marked this pull request as ready for review March 25, 2026 05:21
@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 328.21 ms 402.26 ms 74.05 ms
Size 0 B 0 B 0 B

Baseline 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

@adinauer adinauer merged commit 21db8da into feat/cache-tracing Mar 25, 2026
64 of 66 checks passed
@adinauer adinauer deleted the fix/cache-tracing-invalidate-cache-write branch March 25, 2026 09:07
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