Skip to content

Commit 2d1a223

Browse files
authored
Merge branch 'main' into feat/allow-turning-off-auto-init-in-otel-agent
2 parents c787a0f + 1e1ab7f commit 2d1a223

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
### Fixes
66

7+
- Clear window reference only on activity stop in profileMeasurements collector ([#2407](https://github.com/getsentry/sentry-java/pull/2407))
78
- No longer disable OpenTelemetry exporters in default Java Agent config ([#2408](https://github.com/getsentry/sentry-java/pull/2408))
9+
- Fix `ClassNotFoundException` for `io.sentry.spring.SentrySpringServletContainerInitializer` in `sentry-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))
10+
- Fix `sentry-samples-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))
811

912
### Features
1013

buildSrc/src/main/java/Config.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ object Config {
5959
val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1"
6060

6161
val slf4jApi = "org.slf4j:slf4j-api:1.7.30"
62+
val slf4jApi2 = "org.slf4j:slf4j-api:2.0.5"
6263
val slf4jJdk14 = "org.slf4j:slf4j-jdk14:1.7.30"
6364
val logbackVersion = "1.2.9"
6465
val logbackClassic = "ch.qos.logback:logback-classic:$logbackVersion"
@@ -67,6 +68,8 @@ object Config {
6768
val log4j2Api = "org.apache.logging.log4j:log4j-api:$log4j2Version"
6869
val log4j2Core = "org.apache.logging.log4j:log4j-core:$log4j2Version"
6970

71+
val jacksonDatabind = "com.fasterxml.jackson.core:jackson-databind"
72+
7073
val springBootStarter = "org.springframework.boot:spring-boot-starter:$springBootVersion"
7174
val springBootStarterTest = "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
7275
val springBootStarterWeb = "org.springframework.boot:spring-boot-starter-web:$springBootVersion"

sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ public void onActivityPaused(@NotNull Activity activity) {}
113113

114114
@Override
115115
public void onActivityStopped(@NotNull Activity activity) {
116-
clearCurrentWindow(activity.getWindow());
116+
stopTrackingWindow(activity.getWindow());
117+
if (currentWindow != null && currentWindow.get() == activity.getWindow()) {
118+
currentWindow = null;
119+
}
117120
}
118121

119122
@Override
@@ -141,15 +144,12 @@ public void stopCollection(final @Nullable String listenerId) {
141144
}
142145
Window window = currentWindow != null ? currentWindow.get() : null;
143146
if (window != null && listenerMap.isEmpty()) {
144-
clearCurrentWindow(window);
147+
stopTrackingWindow(window);
145148
}
146149
}
147150

148151
@SuppressLint("NewApi")
149-
private void clearCurrentWindow(final @NotNull Window window) {
150-
if (currentWindow != null && currentWindow.get() == window) {
151-
currentWindow = null;
152-
}
152+
private void stopTrackingWindow(final @NotNull Window window) {
153153
if (trackedWindows.contains(window)) {
154154
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.N) {
155155
try {

sentry-android-core/src/test/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollectorTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import io.sentry.ILogger
1111
import io.sentry.SentryOptions
1212
import io.sentry.android.core.BuildInfoProvider
1313
import io.sentry.test.getCtor
14+
import io.sentry.test.getProperty
1415
import org.junit.runner.RunWith
1516
import org.mockito.Mockito.spy
1617
import org.mockito.kotlin.mock
1718
import org.mockito.kotlin.whenever
19+
import java.lang.ref.WeakReference
1820
import kotlin.test.BeforeTest
1921
import kotlin.test.Test
2022
import kotlin.test.assertEquals
@@ -229,4 +231,24 @@ class SentryFrameMetricsCollectorTest {
229231
collector.stopCollection(id2)
230232
assertEquals(1, fixture.removeOnFrameMetricsAvailableListenerCounter)
231233
}
234+
235+
@Test
236+
fun `collector removes current window only when last activity stops`() {
237+
val collector = fixture.getSut(context)
238+
val id1 = collector.startCollection(mock())
239+
collector.onActivityStarted(fixture.activity)
240+
collector.onActivityStarted(fixture.activity2)
241+
242+
// Stopping collecting data doesn't clear current tracked window reference
243+
collector.stopCollection(id1)
244+
assertNotNull(collector.getProperty<WeakReference<Window>?>("currentWindow"))
245+
246+
// Stopping first activity doesn't clear current tracked window reference
247+
collector.onActivityStopped(fixture.activity)
248+
assertNotNull(collector.getProperty<WeakReference<Window>?>("currentWindow"))
249+
250+
// Stopping last activity clears current tracked window reference
251+
collector.onActivityStopped(fixture.activity2)
252+
assertNull(collector.getProperty<WeakReference<Window>?>("currentWindow"))
253+
}
232254
}

sentry-samples/sentry-samples-spring-jakarta/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ dependencies {
3434
jakartaTransform("org.eclipse.transformer:org.eclipse.transformer.cli:0.5.0")
3535
jakartaTransform("org.eclipse.transformer:org.eclipse.transformer.jakarta:0.5.0")
3636

37-
implementation(Config.Libs.servletApi)
37+
implementation(Config.Libs.servletApiJakarta)
3838
implementation(Config.Libs.springWeb)
3939
implementation(Config.Libs.springAop)
4040
implementation(Config.Libs.aspectj)
4141
implementation(Config.Libs.springSecurityWeb)
4242
implementation(Config.Libs.springSecurityConfig)
4343
implementation(Config.Libs.logbackClassic)
44+
implementation(Config.Libs.slf4jApi2)
45+
implementation(Config.Libs.jacksonDatabind)
4446
implementation(Config.Libs.kotlinReflect)
4547
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
4648
implementation(projects.sentrySpringJakarta)

sentry-samples/sentry-samples-spring-jakarta/src/main/java/io/sentry/samples/spring/jakarta/SecurityConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
78
import org.springframework.security.core.userdetails.User;
89
import org.springframework.security.core.userdetails.UserDetails;
910
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
@@ -12,6 +13,7 @@
1213
import org.springframework.security.web.SecurityFilterChain;
1314

1415
@Configuration
16+
@EnableWebSecurity
1517
public class SecurityConfiguration {
1618

1719
// this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed.

sentry-samples/sentry-samples-spring-jakarta/src/main/java/io/sentry/samples/spring/jakarta/WebConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@Configuration
1414
@EnableAspectJAutoProxy(proxyTargetClass = true)
15-
@ComponentScan("io.sentry.samples.spring.web")
15+
@ComponentScan("io.sentry.samples.spring.jakarta")
1616
@EnableWebMvc
1717
public class WebConfig {
1818

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
io.sentry.spring.SentrySpringServletContainerInitializer
1+
io.sentry.spring.jakarta.SentrySpringServletContainerInitializer

0 commit comments

Comments
 (0)