Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
305baf5
replace hub with scopes
adinauer Mar 27, 2024
95f5e1b
Add Scopes
adinauer Apr 2, 2024
27f2398
Introduce `IScopes` interface.
adinauer Apr 2, 2024
ce3c14f
Replace `IHub` with `IScopes` in core
adinauer Apr 2, 2024
ce615f4
Replace `IHub` with `IScopes` in android core
adinauer Apr 2, 2024
22ddc00
Replace `IHub` with `IScopes` in android integrations
adinauer Apr 2, 2024
305c217
Replace `IHub` with `IScopes` in apollo integrations
adinauer Apr 2, 2024
da927bc
Replace `IHub` with `IScopes` in okhttp integration
adinauer Apr 2, 2024
8279276
Replace `IHub` with `IScopes` in graphql integration
adinauer Apr 2, 2024
9bfc086
Replace `IHub` with `IScopes` in logging integrations
adinauer Apr 2, 2024
b998e50
Replace `IHub` with `IScopes` in more integrations
adinauer Apr 2, 2024
739827a
Replace `IHub` with `IScopes` in OTel integration
adinauer Apr 2, 2024
69f2d63
Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations
adinauer Apr 2, 2024
792d482
Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
adinauer Apr 2, 2024
9bcbce6
Replace `IHub` with `IScopes` in samples
adinauer Apr 2, 2024
3f25a4b
Merge branch 'feat/hsm-13-replacements-in-samples' into feat/hubs-sco…
adinauer Apr 2, 2024
d6fb40a
gitscopes -> github
adinauer Apr 2, 2024
7752bcc
Replace ThreadLocal with ScopesStorage
adinauer Apr 4, 2024
1e329c5
Move client and throwable to span map to scope
adinauer Apr 4, 2024
b0d89ae
Add global scope
adinauer Apr 4, 2024
cdd414a
use global scope in Scopes
adinauer Apr 4, 2024
98da9ff
Implement pushScope popScope and withScope for Scopes
adinauer Apr 4, 2024
2d26033
Add pushIsolationScope; add fork methods to ISCope
adinauer Apr 12, 2024
bbb6700
Use separate scopes for current, isolation and global scope; rename m…
adinauer Apr 12, 2024
c714b21
Allow controlling which scope configureScope uses
adinauer Apr 12, 2024
a474402
Combine scopes
adinauer Apr 12, 2024
ae93e33
Use new API for CRONS integrations
adinauer Apr 12, 2024
b01298b
Add lifecycle helper
adinauer Apr 12, 2024
b64e688
Change spring integrations to use new API
adinauer Apr 12, 2024
d06fc50
Use new API in servlet integrations
adinauer Apr 12, 2024
a641526
Merge branch '8.x.x' into feat/hsm-25-servlet-integrations
adinauer Apr 22, 2024
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
1 change: 1 addition & 0 deletions sentry-servlet-jakarta/api/sentry-servlet-jakarta.api
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class io/sentry/servlet/jakarta/SentryServletContainerInitializer : jakar
}

public class io/sentry/servlet/jakarta/SentryServletRequestListener : jakarta/servlet/ServletRequestListener {
public static final field SENTRY_LIFECYCLE_TOKEN_KEY Ljava/lang/String;
public fun <init> ()V
public fun <init> (Lio/sentry/IScopes;)V
public fun requestDestroyed (Ljakarta/servlet/ServletRequestEvent;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import io.sentry.Breadcrumb;
import io.sentry.Hint;
import io.sentry.IScopes;
import io.sentry.ISentryLifecycleToken;
import io.sentry.ScopesAdapter;
import io.sentry.util.LifecycleHelper;
import io.sentry.util.Objects;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletRequestEvent;
Expand All @@ -21,6 +23,8 @@
@Open
public class SentryServletRequestListener implements ServletRequestListener {

public static final String SENTRY_LIFECYCLE_TOKEN_KEY = "sentry-lifecycle";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: How about making it more clear this key takes care of the scope lifecycle?

Suggested change
public static final String SENTRY_LIFECYCLE_TOKEN_KEY = "sentry-lifecycle";
public static final String SENTRY_SCOPE_LIFECYCLE_TOKEN_KEY = "sentry-scope-lifecycle";


private final IScopes scopes;

public SentryServletRequestListener(@NotNull IScopes scopes) {
Expand All @@ -33,14 +37,16 @@ public SentryServletRequestListener() {

@Override
public void requestDestroyed(@NotNull ServletRequestEvent servletRequestEvent) {
scopes.popScope();
final ServletRequest servletRequest = servletRequestEvent.getServletRequest();
LifecycleHelper.close(servletRequest.getAttribute(SENTRY_LIFECYCLE_TOKEN_KEY));
}

@Override
public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) {
scopes.pushScope();
final @NotNull ISentryLifecycleToken lifecycleToken = scopes.pushIsolationScope();

final ServletRequest servletRequest = servletRequestEvent.getServletRequest();
servletRequest.setAttribute(SENTRY_LIFECYCLE_TOKEN_KEY, lifecycleToken);
if (servletRequest instanceof HttpServletRequest) {
final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package io.sentry.servlet.jakarta

import io.sentry.Breadcrumb
import io.sentry.IScopes
import io.sentry.ISentryLifecycleToken
import jakarta.servlet.ServletRequestEvent
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.check
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.same
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import kotlin.test.Test
Expand All @@ -14,6 +17,7 @@ import kotlin.test.assertEquals
class SentryServletRequestListenerTest {
private class Fixture {
val scopes = mock<IScopes>()
val lifecycleToken = mock<ISentryLifecycleToken>()
val listener =
SentryServletRequestListener(scopes)
val request = mockRequest(
Expand All @@ -24,6 +28,7 @@ class SentryServletRequestListenerTest {

init {
whenever(event.servletRequest).thenReturn(request)
whenever(scopes.pushIsolationScope()).thenReturn(lifecycleToken)
}
}

Expand All @@ -33,7 +38,7 @@ class SentryServletRequestListenerTest {
fun `pushes scope when request gets initialized`() {
fixture.listener.requestInitialized(fixture.event)

verify(fixture.scopes).pushScope()
verify(fixture.scopes).pushIsolationScope()
}

@Test
Expand All @@ -48,12 +53,14 @@ class SentryServletRequestListenerTest {
},
anyOrNull()
)
verify(fixture.request).setAttribute(eq("sentry-lifecycle"), same(fixture.lifecycleToken))
}

@Test
fun `pops scope when request gets destroyed`() {
fixture.listener.requestDestroyed(fixture.event)
whenever(fixture.request.getAttribute(eq("sentry-lifecycle"))).thenReturn(fixture.lifecycleToken)

verify(fixture.scopes).popScope()
fixture.listener.requestDestroyed(fixture.event)
verify(fixture.lifecycleToken).close()
}
}
1 change: 1 addition & 0 deletions sentry-servlet/api/sentry-servlet.api
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class io/sentry/servlet/SentryServletContainerInitializer : javax/servlet
}

public class io/sentry/servlet/SentryServletRequestListener : javax/servlet/ServletRequestListener {
public static final field SENTRY_LIFECYCLE_TOKEN_KEY Ljava/lang/String;
public fun <init> ()V
public fun <init> (Lio/sentry/IScopes;)V
public fun requestDestroyed (Ljavax/servlet/ServletRequestEvent;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import io.sentry.Breadcrumb;
import io.sentry.Hint;
import io.sentry.IScopes;
import io.sentry.ISentryLifecycleToken;
import io.sentry.ScopesAdapter;
import io.sentry.util.LifecycleHelper;
import io.sentry.util.Objects;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
Expand All @@ -21,6 +23,8 @@
@Open
public class SentryServletRequestListener implements ServletRequestListener {

public static final String SENTRY_LIFECYCLE_TOKEN_KEY = "sentry-lifecycle";

private final IScopes scopes;

public SentryServletRequestListener(@NotNull IScopes scopes) {
Expand All @@ -33,14 +37,16 @@ public SentryServletRequestListener() {

@Override
public void requestDestroyed(@NotNull ServletRequestEvent servletRequestEvent) {
scopes.popScope();
final ServletRequest servletRequest = servletRequestEvent.getServletRequest();
LifecycleHelper.close(servletRequest.getAttribute(SENTRY_LIFECYCLE_TOKEN_KEY));
}

@Override
public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) {
scopes.pushScope();
final @NotNull ISentryLifecycleToken lifecycleToken = scopes.pushIsolationScope();

final ServletRequest servletRequest = servletRequestEvent.getServletRequest();
servletRequest.setAttribute(SENTRY_LIFECYCLE_TOKEN_KEY, lifecycleToken);
if (servletRequest instanceof HttpServletRequest) {
final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.sentry.servlet

import io.sentry.Breadcrumb
import io.sentry.IScopes
import io.sentry.ISentryLifecycleToken
import org.assertj.core.api.Assertions.assertThat
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.check
Expand All @@ -11,10 +12,12 @@ import org.mockito.kotlin.whenever
import org.springframework.mock.web.MockHttpServletRequest
import javax.servlet.ServletRequestEvent
import kotlin.test.Test
import kotlin.test.assertSame

class SentryServletRequestListenerTest {
private class Fixture {
val scopes = mock<IScopes>()
val lifecycleToken = mock<ISentryLifecycleToken>()
val listener = SentryServletRequestListener(scopes)
val request = MockHttpServletRequest()
val event = mock<ServletRequestEvent>()
Expand All @@ -23,6 +26,7 @@ class SentryServletRequestListenerTest {
request.requestURI = "http://localhost:8080/some-uri"
request.method = "post"
whenever(event.servletRequest).thenReturn(request)
whenever(scopes.pushIsolationScope()).thenReturn(lifecycleToken)
}
}

Expand All @@ -32,7 +36,7 @@ class SentryServletRequestListenerTest {
fun `pushes scope when request gets initialized`() {
fixture.listener.requestInitialized(fixture.event)

verify(fixture.scopes).pushScope()
verify(fixture.scopes).pushIsolationScope()
}

@Test
Expand All @@ -47,12 +51,14 @@ class SentryServletRequestListenerTest {
},
anyOrNull()
)
assertSame(fixture.lifecycleToken, fixture.request.getAttribute("sentry-lifecycle"))
}

@Test
fun `pops scope when request gets destroyed`() {
fixture.listener.requestDestroyed(fixture.event)
fixture.request.setAttribute("sentry-lifecycle", fixture.lifecycleToken)

verify(fixture.scopes).popScope()
fixture.listener.requestDestroyed(fixture.event)
verify(fixture.lifecycleToken).close()
}
}