Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.util.Objects;
import io.sentry.util.TracingUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -48,6 +49,8 @@ public void jobToBeExecuted(final @NotNull JobExecutionContext context) {
if (maybeSlug == null) {
return;
}
hub.pushScope();
TracingUtils.startNewTrace(hub);
final @NotNull String slug = maybeSlug;
final @NotNull CheckIn checkIn = new CheckIn(slug, CheckInStatus.IN_PROGRESS);
final @NotNull SentryId checkInId = hub.captureCheckIn(checkIn);
Expand Down Expand Up @@ -97,6 +100,8 @@ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jo
hub.getOptions()
.getLogger()
.log(SentryLevel.ERROR, "Unable to capture check-in in jobWasExecuted.", t);
} finally {
hub.popScope();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.util.Objects;
import io.sentry.util.TracingUtils;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
Expand Down Expand Up @@ -56,6 +57,9 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
return invocation.proceed();
}

hub.pushScope();
TracingUtils.startNewTrace(hub);

@Nullable SentryId checkInId = null;
final long startTime = System.currentTimeMillis();
boolean didError = false;
Expand All @@ -73,6 +77,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
CheckIn checkIn = new CheckIn(checkInId, monitorSlug, status);
checkIn.setDuration(DateUtils.millisToSeconds(System.currentTimeMillis() - startTime));
hub.captureCheckIn(checkIn);
hub.popScope();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import io.sentry.spring.jakarta.checkin.SentryCheckInAdviceConfiguration
import io.sentry.spring.jakarta.checkin.SentryCheckInPointcutConfiguration
import org.junit.jupiter.api.assertThrows
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.inOrder
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.reset
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
Expand Down Expand Up @@ -44,6 +50,7 @@ class SentryCheckInAdviceTest {

@BeforeTest
fun setup() {
reset(hub)
whenever(hub.options).thenReturn(SentryOptions())
}

Expand All @@ -63,6 +70,11 @@ class SentryCheckInAdviceTest {
val doneCheckIn = checkInCaptor.lastValue
assertEquals("monitor_slug_1", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.OK.apiName(), doneCheckIn.status)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub, times(2)).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -82,6 +94,11 @@ class SentryCheckInAdviceTest {
val doneCheckIn = checkInCaptor.lastValue
assertEquals("monitor_slug_1e", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.ERROR.apiName(), doneCheckIn.status)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub, times(2)).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -97,6 +114,11 @@ class SentryCheckInAdviceTest {
assertEquals("monitor_slug_2", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.OK.apiName(), doneCheckIn.status)
assertNotNull(doneCheckIn.duration)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -113,6 +135,11 @@ class SentryCheckInAdviceTest {
assertEquals("monitor_slug_2e", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.ERROR.apiName(), doneCheckIn.status)
assertNotNull(doneCheckIn.duration)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -123,6 +150,10 @@ class SentryCheckInAdviceTest {
val result = sampleServiceNoSlug.hello()
assertEquals(1, result)
assertEquals(0, checkInCaptor.allValues.size)

verify(hub, never()).pushScope()
verify(hub, never()).captureCheckIn(any())
verify(hub, never()).popScope()
}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.util.Objects;
import io.sentry.util.TracingUtils;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
Expand Down Expand Up @@ -56,6 +57,9 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
return invocation.proceed();
}

hub.pushScope();
TracingUtils.startNewTrace(hub);

@Nullable SentryId checkInId = null;
final long startTime = System.currentTimeMillis();
boolean didError = false;
Expand All @@ -73,6 +77,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
CheckIn checkIn = new CheckIn(checkInId, monitorSlug, status);
checkIn.setDuration(DateUtils.millisToSeconds(System.currentTimeMillis() - startTime));
hub.captureCheckIn(checkIn);
hub.popScope();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import io.sentry.spring.checkin.SentryCheckInAdviceConfiguration
import io.sentry.spring.checkin.SentryCheckInPointcutConfiguration
import org.junit.jupiter.api.assertThrows
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.inOrder
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.reset
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
Expand Down Expand Up @@ -44,6 +50,7 @@ class SentryCheckInAdviceTest {

@BeforeTest
fun setup() {
reset(hub)
whenever(hub.options).thenReturn(SentryOptions())
}

Expand All @@ -63,6 +70,11 @@ class SentryCheckInAdviceTest {
val doneCheckIn = checkInCaptor.lastValue
assertEquals("monitor_slug_1", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.OK.apiName(), doneCheckIn.status)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub, times(2)).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -82,6 +94,11 @@ class SentryCheckInAdviceTest {
val doneCheckIn = checkInCaptor.lastValue
assertEquals("monitor_slug_1e", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.ERROR.apiName(), doneCheckIn.status)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub, times(2)).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -97,6 +114,11 @@ class SentryCheckInAdviceTest {
assertEquals("monitor_slug_2", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.OK.apiName(), doneCheckIn.status)
assertNotNull(doneCheckIn.duration)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -113,6 +135,11 @@ class SentryCheckInAdviceTest {
assertEquals("monitor_slug_2e", doneCheckIn.monitorSlug)
assertEquals(CheckInStatus.ERROR.apiName(), doneCheckIn.status)
assertNotNull(doneCheckIn.duration)

val order = inOrder(hub)
order.verify(hub).pushScope()
order.verify(hub).captureCheckIn(any())
order.verify(hub).popScope()
}

@Test
Expand All @@ -123,6 +150,10 @@ class SentryCheckInAdviceTest {
val result = sampleServiceNoSlug.hello()
assertEquals(1, result)
assertEquals(0, checkInCaptor.allValues.size)

verify(hub, never()).pushScope()
verify(hub, never()).captureCheckIn(any())
verify(hub, never()).popScope()
}

@Configuration
Expand Down