Skip to content

Commit 4e794ef

Browse files
adinauerclaude
andcommitted
ref(spring): Use method-specific span operations for cache spans
Instead of the 4 generic categories (cache.get, cache.put, cache.remove, cache.flush), use the actual method name as the span operation (e.g. cache.evict, cache.putIfAbsent, cache.retrieve). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4b60cec commit 4e794ef

File tree

8 files changed

+62
-62
lines changed

8 files changed

+62
-62
lines changed

sentry-jcache/src/main/java/io/sentry/jcache/SentryJCacheWrapper.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public V get(final K key) {
7171

7272
@Override
7373
public Map<K, V> getAll(final Set<? extends K> keys) {
74-
final ISpan span = startSpanForKeys("cache.get", keys, "getAll");
74+
final ISpan span = startSpanForKeys("cache.getAll", keys, "getAll");
7575
if (span == null) {
7676
return delegate.getAll(keys);
7777
}
@@ -117,7 +117,7 @@ public void put(final K key, final V value) {
117117

118118
@Override
119119
public V getAndPut(final K key, final V value) {
120-
final ISpan span = startSpan("cache.put", key, "getAndPut");
120+
final ISpan span = startSpan("cache.getAndPut", key, "getAndPut");
121121
if (span == null) {
122122
return delegate.getAndPut(key, value);
123123
}
@@ -136,7 +136,7 @@ public V getAndPut(final K key, final V value) {
136136

137137
@Override
138138
public void putAll(final Map<? extends K, ? extends V> map) {
139-
final ISpan span = startSpanForKeys("cache.put", map.keySet(), "putAll");
139+
final ISpan span = startSpanForKeys("cache.putAll", map.keySet(), "putAll");
140140
if (span == null) {
141141
delegate.putAll(map);
142142
return;
@@ -155,7 +155,7 @@ public void putAll(final Map<? extends K, ? extends V> map) {
155155

156156
@Override
157157
public boolean putIfAbsent(final K key, final V value) {
158-
final ISpan span = startSpan("cache.put", key, "putIfAbsent");
158+
final ISpan span = startSpan("cache.putIfAbsent", key, "putIfAbsent");
159159
if (span == null) {
160160
return delegate.putIfAbsent(key, value);
161161
}
@@ -174,7 +174,7 @@ public boolean putIfAbsent(final K key, final V value) {
174174

175175
@Override
176176
public boolean replace(final K key, final V oldValue, final V newValue) {
177-
final ISpan span = startSpan("cache.put", key, "replace");
177+
final ISpan span = startSpan("cache.replace", key, "replace");
178178
if (span == null) {
179179
return delegate.replace(key, oldValue, newValue);
180180
}
@@ -193,7 +193,7 @@ public boolean replace(final K key, final V oldValue, final V newValue) {
193193

194194
@Override
195195
public boolean replace(final K key, final V value) {
196-
final ISpan span = startSpan("cache.put", key, "replace");
196+
final ISpan span = startSpan("cache.replace", key, "replace");
197197
if (span == null) {
198198
return delegate.replace(key, value);
199199
}
@@ -212,7 +212,7 @@ public boolean replace(final K key, final V value) {
212212

213213
@Override
214214
public V getAndReplace(final K key, final V value) {
215-
final ISpan span = startSpan("cache.put", key, "getAndReplace");
215+
final ISpan span = startSpan("cache.getAndReplace", key, "getAndReplace");
216216
if (span == null) {
217217
return delegate.getAndReplace(key, value);
218218
}
@@ -271,7 +271,7 @@ public boolean remove(final K key, final V oldValue) {
271271

272272
@Override
273273
public V getAndRemove(final K key) {
274-
final ISpan span = startSpan("cache.remove", key, "getAndRemove");
274+
final ISpan span = startSpan("cache.getAndRemove", key, "getAndRemove");
275275
if (span == null) {
276276
return delegate.getAndRemove(key);
277277
}
@@ -290,7 +290,7 @@ public V getAndRemove(final K key) {
290290

291291
@Override
292292
public void removeAll(final Set<? extends K> keys) {
293-
final ISpan span = startSpanForKeys("cache.remove", keys, "removeAll");
293+
final ISpan span = startSpanForKeys("cache.removeAll", keys, "removeAll");
294294
if (span == null) {
295295
delegate.removeAll(keys);
296296
return;
@@ -309,7 +309,7 @@ public void removeAll(final Set<? extends K> keys) {
309309

310310
@Override
311311
public void removeAll() {
312-
final ISpan span = startSpan("cache.flush", null, "removeAll");
312+
final ISpan span = startSpan("cache.removeAll", null, "removeAll");
313313
if (span == null) {
314314
delegate.removeAll();
315315
return;
@@ -330,7 +330,7 @@ public void removeAll() {
330330

331331
@Override
332332
public void clear() {
333-
final ISpan span = startSpan("cache.flush", null, "clear");
333+
final ISpan span = startSpan("cache.clear", null, "clear");
334334
if (span == null) {
335335
delegate.clear();
336336
return;
@@ -358,7 +358,7 @@ public void close() {
358358
public <T> T invoke(
359359
final K key, final EntryProcessor<K, V, T> entryProcessor, final Object... arguments)
360360
throws EntryProcessorException {
361-
final ISpan span = startSpan("cache.get", key, "invoke");
361+
final ISpan span = startSpan("cache.invoke", key, "invoke");
362362
if (span == null) {
363363
return delegate.invoke(key, entryProcessor, arguments);
364364
}
@@ -380,7 +380,7 @@ public <T> Map<K, EntryProcessorResult<T>> invokeAll(
380380
final Set<? extends K> keys,
381381
final EntryProcessor<K, V, T> entryProcessor,
382382
final Object... arguments) {
383-
final ISpan span = startSpanForKeys("cache.get", keys, "invokeAll");
383+
final ISpan span = startSpanForKeys("cache.invokeAll", keys, "invokeAll");
384384
if (span == null) {
385385
return delegate.invokeAll(keys, entryProcessor, arguments);
386386
}

sentry-jcache/src/test/kotlin/io/sentry/jcache/SentryJCacheWrapperTest.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class SentryJCacheWrapperTest {
9494
assertEquals(mapOf("k1" to "v1"), result)
9595
assertEquals(1, tx.spans.size)
9696
val span = tx.spans.first()
97-
assertEquals("cache.get", span.operation)
97+
assertEquals("cache.getAll", span.operation)
9898
assertEquals("testCache", span.description)
9999
assertEquals(true, span.getData(SpanDataConvention.CACHE_HIT_KEY))
100100
val cacheKeys = span.getData(SpanDataConvention.CACHE_KEY_KEY) as List<*>
@@ -144,7 +144,7 @@ class SentryJCacheWrapperTest {
144144

145145
assertEquals("oldValue", result)
146146
assertEquals(1, tx.spans.size)
147-
assertEquals("cache.put", tx.spans.first().operation)
147+
assertEquals("cache.getAndPut", tx.spans.first().operation)
148148
assertEquals("getAndPut", tx.spans.first().getData("db.operation.name"))
149149
}
150150

@@ -161,7 +161,7 @@ class SentryJCacheWrapperTest {
161161
verify(delegate).putAll(entries)
162162
assertEquals(1, tx.spans.size)
163163
val span = tx.spans.first()
164-
assertEquals("cache.put", span.operation)
164+
assertEquals("cache.putAll", span.operation)
165165
assertEquals("testCache", span.description)
166166
val cacheKeys = span.getData(SpanDataConvention.CACHE_KEY_KEY) as List<*>
167167
assertTrue(cacheKeys.containsAll(listOf("k1", "k2")))
@@ -182,7 +182,7 @@ class SentryJCacheWrapperTest {
182182
verify(delegate).putIfAbsent("myKey", "myValue")
183183
assertEquals(1, tx.spans.size)
184184
val span = tx.spans.first()
185-
assertEquals("cache.put", span.operation)
185+
assertEquals("cache.putIfAbsent", span.operation)
186186
assertEquals(SpanStatus.OK, span.status)
187187
assertEquals(listOf("myKey"), span.getData(SpanDataConvention.CACHE_KEY_KEY))
188188
assertEquals("putIfAbsent", span.getData("db.operation.name"))
@@ -202,7 +202,7 @@ class SentryJCacheWrapperTest {
202202
verify(delegate).replace("myKey", "old", "new")
203203
assertEquals(1, tx.spans.size)
204204
val span = tx.spans.first()
205-
assertEquals("cache.put", span.operation)
205+
assertEquals("cache.replace", span.operation)
206206
assertEquals(SpanStatus.OK, span.status)
207207
assertEquals("replace", span.getData("db.operation.name"))
208208
}
@@ -219,7 +219,7 @@ class SentryJCacheWrapperTest {
219219
verify(delegate).replace("myKey", "value")
220220
assertEquals(1, tx.spans.size)
221221
val span = tx.spans.first()
222-
assertEquals("cache.put", span.operation)
222+
assertEquals("cache.replace", span.operation)
223223
assertEquals(SpanStatus.OK, span.status)
224224
assertEquals("replace", span.getData("db.operation.name"))
225225
}
@@ -238,7 +238,7 @@ class SentryJCacheWrapperTest {
238238
verify(delegate).getAndReplace("myKey", "newValue")
239239
assertEquals(1, tx.spans.size)
240240
val span = tx.spans.first()
241-
assertEquals("cache.put", span.operation)
241+
assertEquals("cache.getAndReplace", span.operation)
242242
assertEquals(SpanStatus.OK, span.status)
243243
assertEquals("getAndReplace", span.getData("db.operation.name"))
244244
}
@@ -289,7 +289,7 @@ class SentryJCacheWrapperTest {
289289

290290
assertEquals("value", result)
291291
assertEquals(1, tx.spans.size)
292-
assertEquals("cache.remove", tx.spans.first().operation)
292+
assertEquals("cache.getAndRemove", tx.spans.first().operation)
293293
assertEquals("getAndRemove", tx.spans.first().getData("db.operation.name"))
294294
}
295295

@@ -306,7 +306,7 @@ class SentryJCacheWrapperTest {
306306
verify(delegate).removeAll(keys)
307307
assertEquals(1, tx.spans.size)
308308
val span = tx.spans.first()
309-
assertEquals("cache.remove", span.operation)
309+
assertEquals("cache.removeAll", span.operation)
310310
assertEquals("testCache", span.description)
311311
assertEquals("removeAll", span.getData("db.operation.name"))
312312
}
@@ -322,7 +322,7 @@ class SentryJCacheWrapperTest {
322322

323323
verify(delegate).removeAll()
324324
assertEquals(1, tx.spans.size)
325-
assertEquals("cache.flush", tx.spans.first().operation)
325+
assertEquals("cache.removeAll", tx.spans.first().operation)
326326
assertEquals("removeAll", tx.spans.first().getData("db.operation.name"))
327327
}
328328

@@ -338,7 +338,7 @@ class SentryJCacheWrapperTest {
338338
verify(delegate).clear()
339339
assertEquals(1, tx.spans.size)
340340
val span = tx.spans.first()
341-
assertEquals("cache.flush", span.operation)
341+
assertEquals("cache.clear", span.operation)
342342
assertEquals(SpanStatus.OK, span.status)
343343
assertNull(span.getData(SpanDataConvention.CACHE_KEY_KEY))
344344
assertEquals("clear", span.getData("db.operation.name"))
@@ -357,7 +357,7 @@ class SentryJCacheWrapperTest {
357357

358358
assertEquals("result", result)
359359
assertEquals(1, tx.spans.size)
360-
assertEquals("cache.get", tx.spans.first().operation)
360+
assertEquals("cache.invoke", tx.spans.first().operation)
361361
assertEquals("invoke", tx.spans.first().getData("db.operation.name"))
362362
}
363363

@@ -376,7 +376,7 @@ class SentryJCacheWrapperTest {
376376

377377
assertEquals(resultMap, result)
378378
assertEquals(1, tx.spans.size)
379-
assertEquals("cache.get", tx.spans.first().operation)
379+
assertEquals("cache.invokeAll", tx.spans.first().operation)
380380
assertEquals("invokeAll", tx.spans.first().getData("db.operation.name"))
381381
}
382382

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public SentryCacheWrapper(final @NotNull Cache delegate, final @NotNull IScopes
110110

111111
@Override
112112
public @Nullable CompletableFuture<?> retrieve(final @NotNull Object key) {
113-
final ISpan span = startSpan("cache.get", key, "retrieve");
113+
final ISpan span = startSpan("cache.retrieve", key, "retrieve");
114114
if (span == null) {
115115
return delegate.retrieve(key);
116116
}
@@ -145,7 +145,7 @@ public SentryCacheWrapper(final @NotNull Cache delegate, final @NotNull IScopes
145145
@Override
146146
public <T> CompletableFuture<T> retrieve(
147147
final @NotNull Object key, final @NotNull Supplier<CompletableFuture<T>> valueLoader) {
148-
final ISpan span = startSpan("cache.get", key, "retrieve");
148+
final ISpan span = startSpan("cache.retrieve", key, "retrieve");
149149
if (span == null) {
150150
return delegate.retrieve(key, valueLoader);
151151
}
@@ -200,7 +200,7 @@ public void put(final @NotNull Object key, final @Nullable Object value) {
200200
@Override
201201
public @Nullable ValueWrapper putIfAbsent(
202202
final @NotNull Object key, final @Nullable Object value) {
203-
final ISpan span = startSpan("cache.put", key, "putIfAbsent");
203+
final ISpan span = startSpan("cache.putIfAbsent", key, "putIfAbsent");
204204
if (span == null) {
205205
return delegate.putIfAbsent(key, value);
206206
}
@@ -219,7 +219,7 @@ public void put(final @NotNull Object key, final @Nullable Object value) {
219219

220220
@Override
221221
public void evict(final @NotNull Object key) {
222-
final ISpan span = startSpan("cache.remove", key, "evict");
222+
final ISpan span = startSpan("cache.evict", key, "evict");
223223
if (span == null) {
224224
delegate.evict(key);
225225
return;
@@ -238,7 +238,7 @@ public void evict(final @NotNull Object key) {
238238

239239
@Override
240240
public boolean evictIfPresent(final @NotNull Object key) {
241-
final ISpan span = startSpan("cache.remove", key, "evictIfPresent");
241+
final ISpan span = startSpan("cache.evictIfPresent", key, "evictIfPresent");
242242
if (span == null) {
243243
return delegate.evictIfPresent(key);
244244
}
@@ -257,7 +257,7 @@ public boolean evictIfPresent(final @NotNull Object key) {
257257

258258
@Override
259259
public void clear() {
260-
final ISpan span = startSpan("cache.flush", null, "clear");
260+
final ISpan span = startSpan("cache.clear", null, "clear");
261261
if (span == null) {
262262
delegate.clear();
263263
return;
@@ -276,7 +276,7 @@ public void clear() {
276276

277277
@Override
278278
public boolean invalidate() {
279-
final ISpan span = startSpan("cache.flush", null, "invalidate");
279+
final ISpan span = startSpan("cache.invalidate", null, "invalidate");
280280
if (span == null) {
281281
return delegate.invalidate();
282282
}

sentry-spring-7/src/test/kotlin/io/sentry/spring7/cache/SentryCacheWrapperTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class SentryCacheWrapperTest {
187187
assertEquals("value", result!!.get())
188188
assertEquals(1, tx.spans.size)
189189
val span = tx.spans.first()
190-
assertEquals("cache.get", span.operation)
190+
assertEquals("cache.retrieve", span.operation)
191191
assertEquals("myKey", span.description)
192192
assertEquals(SpanStatus.OK, span.status)
193193
assertEquals(true, span.getData(SpanDataConvention.CACHE_HIT_KEY))
@@ -373,7 +373,7 @@ class SentryCacheWrapperTest {
373373
verify(delegate).putIfAbsent("myKey", "myValue")
374374
assertEquals(1, tx.spans.size)
375375
val span = tx.spans.first()
376-
assertEquals("cache.put", span.operation)
376+
assertEquals("cache.putIfAbsent", span.operation)
377377
assertEquals(SpanStatus.OK, span.status)
378378
assertEquals(listOf("myKey"), span.getData(SpanDataConvention.CACHE_KEY_KEY))
379379
assertEquals("putIfAbsent", span.getData("db.operation.name"))
@@ -391,7 +391,7 @@ class SentryCacheWrapperTest {
391391
verify(delegate).evict("myKey")
392392
assertEquals(1, tx.spans.size)
393393
val span = tx.spans.first()
394-
assertEquals("cache.remove", span.operation)
394+
assertEquals("cache.evict", span.operation)
395395
assertEquals(SpanStatus.OK, span.status)
396396
assertEquals("evict", span.getData("db.operation.name"))
397397
}
@@ -408,7 +408,7 @@ class SentryCacheWrapperTest {
408408

409409
assertTrue(result)
410410
assertEquals(1, tx.spans.size)
411-
assertEquals("cache.remove", tx.spans.first().operation)
411+
assertEquals("cache.evictIfPresent", tx.spans.first().operation)
412412
assertEquals("evictIfPresent", tx.spans.first().getData("db.operation.name"))
413413
}
414414

@@ -424,7 +424,7 @@ class SentryCacheWrapperTest {
424424
verify(delegate).clear()
425425
assertEquals(1, tx.spans.size)
426426
val span = tx.spans.first()
427-
assertEquals("cache.flush", span.operation)
427+
assertEquals("cache.clear", span.operation)
428428
assertEquals(SpanStatus.OK, span.status)
429429
assertNull(span.getData(SpanDataConvention.CACHE_KEY_KEY))
430430
assertEquals("clear", span.getData("db.operation.name"))
@@ -442,7 +442,7 @@ class SentryCacheWrapperTest {
442442

443443
assertTrue(result)
444444
assertEquals(1, tx.spans.size)
445-
assertEquals("cache.flush", tx.spans.first().operation)
445+
assertEquals("cache.invalidate", tx.spans.first().operation)
446446
assertEquals("invalidate", tx.spans.first().getData("db.operation.name"))
447447
}
448448

0 commit comments

Comments
 (0)