Skip to content

Commit 5a729ca

Browse files
adinauerclaude
andcommitted
fix(spring): Skip cache span data when child span is NoOp
Add span.isNoOp() check after startChild() in all three Spring SentryCacheWrapper variants, matching the existing pattern in SentryJCacheWrapper. This avoids setting span data on noop spans when sampling drops the span. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7fa53f7 commit 5a729ca

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

sentry-spring-7/src/main/java/io/sentry/spring7/cache/SentryCacheWrapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ public boolean invalidate() {
295295
spanOptions.setOrigin(TRACE_ORIGIN);
296296
final String keyString = key != null ? String.valueOf(key) : null;
297297
final ISpan span = activeSpan.startChild(operation, keyString, spanOptions);
298+
if (span.isNoOp()) {
299+
return null;
300+
}
298301
if (keyString != null) {
299302
span.setData(SpanDataConvention.CACHE_KEY_KEY, Arrays.asList(keyString));
300303
}

sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/cache/SentryCacheWrapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ public boolean invalidate() {
295295
spanOptions.setOrigin(TRACE_ORIGIN);
296296
final String keyString = key != null ? String.valueOf(key) : null;
297297
final ISpan span = activeSpan.startChild(operation, keyString, spanOptions);
298+
if (span.isNoOp()) {
299+
return null;
300+
}
298301
if (keyString != null) {
299302
span.setData(SpanDataConvention.CACHE_KEY_KEY, Arrays.asList(keyString));
300303
}

sentry-spring/src/main/java/io/sentry/spring/cache/SentryCacheWrapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ public boolean invalidate() {
223223
spanOptions.setOrigin(TRACE_ORIGIN);
224224
final String keyString = key != null ? String.valueOf(key) : null;
225225
final ISpan span = activeSpan.startChild(operation, keyString, spanOptions);
226+
if (span.isNoOp()) {
227+
return null;
228+
}
226229
if (keyString != null) {
227230
span.setData(SpanDataConvention.CACHE_KEY_KEY, Arrays.asList(keyString));
228231
}

0 commit comments

Comments
 (0)