Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry-jcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ JCache is a standard API — you need a provider implementation at runtime. Comm
- [Apache Ignite](https://ignite.apache.org/)
- [Infinispan](https://infinispan.org/)

Please consult the documentation on how to install and use this integration in the Sentry Docs for [Java](https://docs.sentry.io/platforms/java/tracing/instrumentation/jcache/).
Please consult the documentation on how to install and use this integration in the Sentry Docs for [Java](https://docs.sentry.io/platforms/java/integrations/jcache/).
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public SentryCacheWrapper(final @NotNull Cache delegate, final @NotNull IScopes
return delegate.get(key, type);
}
try {
final ValueWrapper wrapper = delegate.get(key);
span.setData(SpanDataConvention.CACHE_HIT_KEY, wrapper != null);
final T result = delegate.get(key, type);
span.setData(SpanDataConvention.CACHE_HIT_KEY, result != null);
span.setStatus(SpanStatus.OK);
return result;
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class SentryCacheWrapperTest {
fun `get with type creates span with cache hit true on hit`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val valueWrapper = mock<Cache.ValueWrapper>()
whenever(delegate.get("myKey")).thenReturn(valueWrapper)
whenever(delegate.get("myKey", String::class.java)).thenReturn("value")

val result = wrapper.get("myKey", String::class.java)
Expand All @@ -94,10 +96,26 @@ class SentryCacheWrapperTest {
assertEquals(true, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type creates span with cache hit true when cached value is null`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val valueWrapper = mock<Cache.ValueWrapper>()
whenever(delegate.get("myKey")).thenReturn(valueWrapper)
whenever(delegate.get("myKey", String::class.java)).thenReturn(null)

val result = wrapper.get("myKey", String::class.java)

assertNull(result)
assertEquals(1, tx.spans.size)
assertEquals(true, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type creates span with cache hit false on miss`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
whenever(delegate.get("myKey")).thenReturn(null)
whenever(delegate.get("myKey", String::class.java)).thenReturn(null)

val result = wrapper.get("myKey", String::class.java)
Expand All @@ -107,6 +125,22 @@ class SentryCacheWrapperTest {
assertEquals(false, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type sets error status and throwable on exception`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val exception = RuntimeException("cache error")
whenever(delegate.get("myKey")).thenReturn(mock<Cache.ValueWrapper>())
whenever(delegate.get("myKey", String::class.java)).thenThrow(exception)

assertFailsWith<RuntimeException> { wrapper.get("myKey", String::class.java) }

assertEquals(1, tx.spans.size)
val span = tx.spans.first()
assertEquals(SpanStatus.INTERNAL_ERROR, span.status)
assertEquals(exception, span.throwable)
}

// -- get(Object key, Callable<T>) --

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public SentryCacheWrapper(final @NotNull Cache delegate, final @NotNull IScopes
return delegate.get(key, type);
}
try {
final ValueWrapper wrapper = delegate.get(key);
span.setData(SpanDataConvention.CACHE_HIT_KEY, wrapper != null);
final T result = delegate.get(key, type);
span.setData(SpanDataConvention.CACHE_HIT_KEY, result != null);
span.setStatus(SpanStatus.OK);
return result;
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class SentryCacheWrapperTest {
fun `get with type creates span with cache hit true on hit`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val valueWrapper = mock<Cache.ValueWrapper>()
whenever(delegate.get("myKey")).thenReturn(valueWrapper)
whenever(delegate.get("myKey", String::class.java)).thenReturn("value")

val result = wrapper.get("myKey", String::class.java)
Expand All @@ -94,10 +96,26 @@ class SentryCacheWrapperTest {
assertEquals(true, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type creates span with cache hit true when cached value is null`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val valueWrapper = mock<Cache.ValueWrapper>()
whenever(delegate.get("myKey")).thenReturn(valueWrapper)
whenever(delegate.get("myKey", String::class.java)).thenReturn(null)

val result = wrapper.get("myKey", String::class.java)

assertNull(result)
assertEquals(1, tx.spans.size)
assertEquals(true, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type creates span with cache hit false on miss`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
whenever(delegate.get("myKey")).thenReturn(null)
whenever(delegate.get("myKey", String::class.java)).thenReturn(null)

val result = wrapper.get("myKey", String::class.java)
Expand All @@ -107,6 +125,22 @@ class SentryCacheWrapperTest {
assertEquals(false, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type sets error status and throwable on exception`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val exception = RuntimeException("cache error")
whenever(delegate.get("myKey")).thenReturn(mock<Cache.ValueWrapper>())
whenever(delegate.get("myKey", String::class.java)).thenThrow(exception)

assertFailsWith<RuntimeException> { wrapper.get("myKey", String::class.java) }

assertEquals(1, tx.spans.size)
val span = tx.spans.first()
assertEquals(SpanStatus.INTERNAL_ERROR, span.status)
assertEquals(exception, span.throwable)
}

// -- get(Object key, Callable<T>) --

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public SentryCacheWrapper(final @NotNull Cache delegate, final @NotNull IScopes
return delegate.get(key, type);
}
try {
final ValueWrapper wrapper = delegate.get(key);
span.setData(SpanDataConvention.CACHE_HIT_KEY, wrapper != null);
final T result = delegate.get(key, type);
span.setData(SpanDataConvention.CACHE_HIT_KEY, result != null);
span.setStatus(SpanStatus.OK);
return result;
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SentryCacheWrapperTest {
fun `get with type creates span with cache hit true on hit`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val valueWrapper = mock<Cache.ValueWrapper>()
whenever(delegate.get("myKey")).thenReturn(valueWrapper)
whenever(delegate.get("myKey", String::class.java)).thenReturn("value")

val result = wrapper.get("myKey", String::class.java)
Expand All @@ -92,10 +94,26 @@ class SentryCacheWrapperTest {
assertEquals(true, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type creates span with cache hit true when cached value is null`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val valueWrapper = mock<Cache.ValueWrapper>()
whenever(delegate.get("myKey")).thenReturn(valueWrapper)
whenever(delegate.get("myKey", String::class.java)).thenReturn(null)

val result = wrapper.get("myKey", String::class.java)

assertNull(result)
assertEquals(1, tx.spans.size)
assertEquals(true, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type creates span with cache hit false on miss`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
whenever(delegate.get("myKey")).thenReturn(null)
whenever(delegate.get("myKey", String::class.java)).thenReturn(null)

val result = wrapper.get("myKey", String::class.java)
Expand All @@ -105,6 +123,22 @@ class SentryCacheWrapperTest {
assertEquals(false, tx.spans.first().getData(SpanDataConvention.CACHE_HIT_KEY))
}

@Test
fun `get with type sets error status and throwable on exception`() {
val tx = createTransaction()
val wrapper = SentryCacheWrapper(delegate, scopes)
val exception = RuntimeException("cache error")
whenever(delegate.get("myKey")).thenReturn(mock<Cache.ValueWrapper>())
whenever(delegate.get("myKey", String::class.java)).thenThrow(exception)

assertFailsWith<RuntimeException> { wrapper.get("myKey", String::class.java) }

assertEquals(1, tx.spans.size)
val span = tx.spans.first()
assertEquals(SpanStatus.INTERNAL_ERROR, span.status)
assertEquals(exception, span.throwable)
}

// -- get(Object key, Callable<T>) --

@Test
Expand Down
Loading