Skip to content

Commit

Permalink
Merge branch 'main' into feat/allow-turning-off-auto-init-in-otel-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Dec 6, 2022
2 parents c787a0f + 1e1ab7f commit 2d1a223
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

### Fixes

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

### Features

Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ object Config {
val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1"

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

val jacksonDatabind = "com.fasterxml.jackson.core:jackson-databind"

val springBootStarter = "org.springframework.boot:spring-boot-starter:$springBootVersion"
val springBootStarterTest = "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
val springBootStarterWeb = "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public void onActivityPaused(@NotNull Activity activity) {}

@Override
public void onActivityStopped(@NotNull Activity activity) {
clearCurrentWindow(activity.getWindow());
stopTrackingWindow(activity.getWindow());
if (currentWindow != null && currentWindow.get() == activity.getWindow()) {
currentWindow = null;
}
}

@Override
Expand Down Expand Up @@ -141,15 +144,12 @@ public void stopCollection(final @Nullable String listenerId) {
}
Window window = currentWindow != null ? currentWindow.get() : null;
if (window != null && listenerMap.isEmpty()) {
clearCurrentWindow(window);
stopTrackingWindow(window);
}
}

@SuppressLint("NewApi")
private void clearCurrentWindow(final @NotNull Window window) {
if (currentWindow != null && currentWindow.get() == window) {
currentWindow = null;
}
private void stopTrackingWindow(final @NotNull Window window) {
if (trackedWindows.contains(window)) {
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.N) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import io.sentry.ILogger
import io.sentry.SentryOptions
import io.sentry.android.core.BuildInfoProvider
import io.sentry.test.getCtor
import io.sentry.test.getProperty
import org.junit.runner.RunWith
import org.mockito.Mockito.spy
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import java.lang.ref.WeakReference
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -229,4 +231,24 @@ class SentryFrameMetricsCollectorTest {
collector.stopCollection(id2)
assertEquals(1, fixture.removeOnFrameMetricsAvailableListenerCounter)
}

@Test
fun `collector removes current window only when last activity stops`() {
val collector = fixture.getSut(context)
val id1 = collector.startCollection(mock())
collector.onActivityStarted(fixture.activity)
collector.onActivityStarted(fixture.activity2)

// Stopping collecting data doesn't clear current tracked window reference
collector.stopCollection(id1)
assertNotNull(collector.getProperty<WeakReference<Window>?>("currentWindow"))

// Stopping first activity doesn't clear current tracked window reference
collector.onActivityStopped(fixture.activity)
assertNotNull(collector.getProperty<WeakReference<Window>?>("currentWindow"))

// Stopping last activity clears current tracked window reference
collector.onActivityStopped(fixture.activity2)
assertNull(collector.getProperty<WeakReference<Window>?>("currentWindow"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ dependencies {
jakartaTransform("org.eclipse.transformer:org.eclipse.transformer.cli:0.5.0")
jakartaTransform("org.eclipse.transformer:org.eclipse.transformer.jakarta:0.5.0")

implementation(Config.Libs.servletApi)
implementation(Config.Libs.servletApiJakarta)
implementation(Config.Libs.springWeb)
implementation(Config.Libs.springAop)
implementation(Config.Libs.aspectj)
implementation(Config.Libs.springSecurityWeb)
implementation(Config.Libs.springSecurityConfig)
implementation(Config.Libs.logbackClassic)
implementation(Config.Libs.slf4jApi2)
implementation(Config.Libs.jacksonDatabind)
implementation(Config.Libs.kotlinReflect)
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
implementation(projects.sentrySpringJakarta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
Expand All @@ -12,6 +13,7 @@
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

// this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan("io.sentry.samples.spring.web")
@ComponentScan("io.sentry.samples.spring.jakarta")
@EnableWebMvc
public class WebConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.sentry.spring.SentrySpringServletContainerInitializer
io.sentry.spring.jakarta.SentrySpringServletContainerInitializer

0 comments on commit 2d1a223

Please sign in to comment.