Skip to content

Commit 0a04d7f

Browse files
Do not enable Sentry SDK for Android when mixed versions are detected (#4271)
* Check for mixed SDK versions * Format code * format + api * Init noops if mixed versions detected * Add BuildConfig * config entries for agentless module sdk names --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent c6e6bbc commit 0a04d7f

File tree

31 files changed

+186
-2
lines changed

31 files changed

+186
-2
lines changed

buildSrc/src/main/java/Config.kt

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ object Config {
253253
val SENTRY_SPRING_BOOT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot"
254254
val SENTRY_SPRING_BOOT_JAKARTA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot.jakarta"
255255
val SENTRY_OPENTELEMETRY_AGENT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agent"
256+
val SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agentless"
257+
val SENTRY_OPENTELEMETRY_AGENTLESS_SPRING_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agentless-spring"
256258
val SENTRY_APOLLO3_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo3"
257259
val SENTRY_APOLLO4_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo4"
258260
val SENTRY_APOLLO_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo"

sentry-android-fragment/src/main/java/io/sentry/android/fragment/FragmentLifecycleIntegration.kt

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public class FragmentLifecycleIntegration(
2222
Integration,
2323
Closeable {
2424

25+
private companion object {
26+
init {
27+
SentryIntegrationPackageStorage.getInstance()
28+
.addPackage("maven:io.sentry:sentry-android-fragment", BuildConfig.VERSION_NAME)
29+
}
30+
}
31+
2532
public constructor(application: Application) : this(
2633
application = application,
2734
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.states,

sentry-android-navigation/src/main/java/io/sentry/android/navigation/SentryNavigationListener.kt

+5
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,10 @@ public class SentryNavigationListener @JvmOverloads constructor(
195195

196196
public companion object {
197197
public const val NAVIGATION_OP: String = "navigation"
198+
199+
init {
200+
SentryIntegrationPackageStorage.getInstance()
201+
.addPackage("maven:io.sentry:sentry-android-navigation", BuildConfig.VERSION_NAME)
202+
}
198203
}
199204
}

sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdkUtil.java

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.android.ndk;
22

3+
import io.sentry.SentryIntegrationPackageStorage;
34
import io.sentry.protocol.SdkVersion;
45
import org.jetbrains.annotations.Nullable;
56

@@ -8,6 +9,11 @@
89
*/
910
final class SentryNdkUtil {
1011

12+
static {
13+
SentryIntegrationPackageStorage.getInstance()
14+
.addPackage("maven:io.sentry:sentry-android-ndk", BuildConfig.VERSION_NAME);
15+
}
16+
1117
private SentryNdkUtil() {}
1218

1319
/**

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public class ReplayIntegration(
7171
IConnectionStatusObserver,
7272
IRateLimitObserver {
7373

74+
private companion object {
75+
init {
76+
SentryIntegrationPackageStorage.getInstance()
77+
.addPackage("maven:io.sentry:sentry-android-replay", BuildConfig.VERSION_NAME)
78+
}
79+
}
80+
7481
// needed for the Java's call site
7582
public constructor(context: Context, dateProvider: ICurrentDateProvider) : this(
7683
context.appContext(),

sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberIntegration.kt

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public class SentryTimberIntegration(
2121
private lateinit var tree: SentryTimberTree
2222
private lateinit var logger: ILogger
2323

24+
private companion object {
25+
init {
26+
SentryIntegrationPackageStorage.getInstance()
27+
.addPackage("maven:io.sentry:sentry-android-timber", VERSION_NAME)
28+
}
29+
}
30+
2431
override fun register(scopes: IScopes, options: SentryOptions) {
2532
logger = options.logger
2633

sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt

+5
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,10 @@ class SentryApollo3HttpInterceptor @JvmOverloads constructor(
453453
const val SENTRY_APOLLO_3_VARIABLES = "SENTRY-APOLLO-3-VARIABLES"
454454
const val SENTRY_APOLLO_3_OPERATION_TYPE = "SENTRY-APOLLO-3-OPERATION-TYPE"
455455
const val DEFAULT_CAPTURE_FAILED_REQUESTS = true
456+
457+
init {
458+
SentryIntegrationPackageStorage.getInstance()
459+
.addPackage("maven:io.sentry:sentry-apollo-3", BuildConfig.VERSION_NAME)
460+
}
456461
}
457462
}

sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt

+5
Original file line numberDiff line numberDiff line change
@@ -449,5 +449,10 @@ class SentryApollo4HttpInterceptor @JvmOverloads constructor(
449449

450450
companion object {
451451
const val DEFAULT_CAPTURE_FAILED_REQUESTS = true
452+
453+
init {
454+
SentryIntegrationPackageStorage.getInstance()
455+
.addPackage("maven:io.sentry:sentry-apollo-4", BuildConfig.VERSION_NAME)
456+
}
452457
}
453458
}

sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class SentryApolloInterceptor(
3636
private val beforeSpan: BeforeSpanCallback? = null
3737
) : ApolloInterceptor {
3838

39+
private companion object {
40+
init {
41+
SentryIntegrationPackageStorage.getInstance().addPackage("maven:io.sentry:sentry-apollo", BuildConfig.VERSION_NAME)
42+
}
43+
}
44+
3945
constructor(scopes: IScopes) : this(scopes, null)
4046
constructor(beforeSpan: BeforeSpanCallback) : this(ScopesAdapter.getInstance(), beforeSpan)
4147

sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public final class ComposeGestureTargetLocator implements GestureTargetLocator {
3333
private volatile @Nullable SentryComposeHelper composeHelper;
3434
private final @NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();
3535

36+
static {
37+
SentryIntegrationPackageStorage.getInstance()
38+
.addPackage("maven:io.sentry:sentry-compose", BuildConfig.VERSION_NAME);
39+
}
40+
3641
public ComposeGestureTargetLocator(final @NotNull ILogger logger) {
3742
this.logger = logger;
3843
SentryIntegrationPackageStorage.getInstance().addIntegration("ComposeUserInteraction");

sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryNavigationIntegration.kt

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ internal class SentryLifecycleObserver(
2626
SentryNavigationListener(traceOriginAppendix = TRACE_ORIGIN_APPENDIX)
2727
) : LifecycleEventObserver {
2828

29+
private companion object {
30+
init {
31+
SentryIntegrationPackageStorage.getInstance().addPackage("maven:io.sentry:sentry-compose", BuildConfig.VERSION_NAME)
32+
}
33+
}
34+
2935
init {
3036
addIntegrationToSdkVersion("ComposeNavigation")
3137
SentryIntegrationPackageStorage.getInstance().addPackage("maven:io.sentry:sentry-compose", BuildConfig.VERSION_NAME)

sentry-graphql-22/src/main/java/io/sentry/graphql22/SentryInstrumentation.java

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
public final class SentryInstrumentation
2323
extends graphql.execution.instrumentation.SimplePerformantInstrumentation {
2424

25+
static {
26+
SentryIntegrationPackageStorage.getInstance()
27+
.addPackage("maven:io.sentry:sentry-graphql-22", BuildConfig.VERSION_NAME);
28+
}
29+
2530
/**
2631
* @deprecated please use {@link SentryGraphqlInstrumentation#SENTRY_SCOPES_CONTEXT_KEY}
2732
*/

sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
public final class SentryInstrumentation
2020
extends graphql.execution.instrumentation.SimpleInstrumentation {
2121

22+
static {
23+
SentryIntegrationPackageStorage.getInstance()
24+
.addPackage("maven:io.sentry:sentry-graphql", BuildConfig.VERSION_NAME);
25+
}
26+
2227
/**
2328
* @deprecated please use {@link SentryGraphqlInstrumentation#SENTRY_SCOPES_CONTEXT_KEY}
2429
*/

sentry-jdbc/src/main/java/io/sentry/jdbc/SentryJdbcEventListener.java

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public class SentryJdbcEventListener extends SimpleJdbcEventListener {
3131
protected final @NotNull AutoClosableReentrantLock databaseDetailsLock =
3232
new AutoClosableReentrantLock();
3333

34+
static {
35+
SentryIntegrationPackageStorage.getInstance()
36+
.addPackage("maven:io.sentry:sentry-jdbc", BuildConfig.VERSION_NAME);
37+
}
38+
3439
public SentryJdbcEventListener(final @NotNull IScopes scopes) {
3540
this.scopes = Objects.requireNonNull(scopes, "scopes are required");
3641
addPackageAndIntegrationInfo();

sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public class SentryHandler extends Handler {
4949
private @NotNull Level minimumBreadcrumbLevel = Level.INFO;
5050
private @NotNull Level minimumEventLevel = Level.SEVERE;
5151

52+
static {
53+
SentryIntegrationPackageStorage.getInstance()
54+
.addPackage("maven:io.sentry:sentry-jul", BuildConfig.VERSION_NAME);
55+
}
56+
5257
/** Creates an instance of SentryHandler. */
5358
public SentryHandler() {
5459
this(new SentryOptions());

sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public class SentryAppender extends AbstractAppender {
5454
private final @NotNull IScopes scopes;
5555
private final @Nullable List<String> contextTags;
5656

57+
static {
58+
SentryIntegrationPackageStorage.getInstance()
59+
.addPackage("maven:io.sentry:sentry-log4j2", BuildConfig.VERSION_NAME);
60+
}
61+
5762
public SentryAppender(
5863
final @NotNull String name,
5964
final @Nullable Filter filter,

sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public class SentryAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
4848
private @NotNull Level minimumEventLevel = Level.ERROR;
4949
private @Nullable Encoder<ILoggingEvent> encoder;
5050

51+
static {
52+
SentryIntegrationPackageStorage.getInstance()
53+
.addPackage("maven:io.sentry:sentry-logback", BuildConfig.VERSION_NAME);
54+
}
55+
5156
@Override
5257
public void start() {
5358
if (options.getDsn() == null || !options.getDsn().endsWith("_IS_UNDEFINED")) {

sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpInterceptor.kt

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public open class SentryOkHttpInterceptor(
5050
private val failedRequestTargets: List<String> = listOf(DEFAULT_PROPAGATION_TARGETS)
5151
) : Interceptor {
5252

53+
private companion object {
54+
init {
55+
SentryIntegrationPackageStorage.getInstance()
56+
.addPackage("maven:io.sentry:sentry-okhttp", BuildConfig.VERSION_NAME)
57+
}
58+
}
59+
5360
public constructor() : this(ScopesAdapter.getInstance())
5461
public constructor(scopes: IScopes) : this(scopes, null)
5562
public constructor(beforeSpan: BeforeSpanCallback) : this(ScopesAdapter.getInstance(), beforeSpan)

sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public final class SentryFeignClient implements Client {
3838
private final @NotNull IScopes scopes;
3939
private final @Nullable BeforeSpanCallback beforeSpan;
4040

41+
static {
42+
SentryIntegrationPackageStorage.getInstance()
43+
.addPackage("maven:io.sentry:sentry-openfeign", BuildConfig.VERSION_NAME);
44+
}
45+
4146
public SentryFeignClient(
4247
final @NotNull Client delegate,
4348
final @NotNull IScopes scopes,

sentry-opentelemetry/sentry-opentelemetry-agentless-spring/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
`java-library`
3+
id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion
34
}
45

56
dependencies {
@@ -12,3 +13,10 @@ dependencies {
1213
api(Config.Libs.OpenTelemetry.otelExtensionAutoconfigure)
1314
api(Config.Libs.springBoot3StarterOpenTelemetry)
1415
}
16+
17+
buildConfig {
18+
useJavaOutput()
19+
packageName("io.sentry.opentelemetry.agentless.spring")
20+
buildConfigField("String", "SENTRY_OPENTELEMETRY_AGENTLESS_SPRING_SDK_NAME", "\"${Config.Sentry.SENTRY_OPENTELEMETRY_AGENTLESS_SPRING_SDK_NAME}\"")
21+
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
package io.sentry.opentelemetry.agent;
22

3-
public final class AgentlessSpringMarker {}
3+
import io.sentry.SentryIntegrationPackageStorage;
4+
import io.sentry.opentelemetry.agentless.spring.BuildConfig;
5+
6+
public final class AgentlessSpringMarker {
7+
static {
8+
SentryIntegrationPackageStorage.getInstance()
9+
.addPackage(
10+
"maven:io.sentry:sentry-opentelemetry-agentless-spring", BuildConfig.VERSION_NAME);
11+
}
12+
}

sentry-opentelemetry/sentry-opentelemetry-agentless/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
`java-library`
3+
id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion
34
}
45

56
dependencies {
@@ -11,3 +12,10 @@ dependencies {
1112
api(Config.Libs.OpenTelemetry.otelSemconvIncubating)
1213
api(Config.Libs.OpenTelemetry.otelExtensionAutoconfigure)
1314
}
15+
16+
buildConfig {
17+
useJavaOutput()
18+
packageName("io.sentry.opentelemetry.agentless")
19+
buildConfigField("String", "SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME", "\"${Config.Sentry.SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME}\"")
20+
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
package io.sentry.opentelemetry.agent;
22

3-
public final class AgentlessMarker {}
3+
import io.sentry.SentryIntegrationPackageStorage;
4+
import io.sentry.opentelemetry.agentless.BuildConfig;
5+
6+
public final class AgentlessMarker {
7+
static {
8+
SentryIntegrationPackageStorage.getInstance()
9+
.addPackage("maven:io.sentry:sentry-opentelemetry-agentless", BuildConfig.VERSION_NAME);
10+
}
11+
}

sentry-quartz/src/main/java/io/sentry/quartz/SentryJobListener.java

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
@ApiStatus.Experimental
2424
public final class SentryJobListener implements JobListener {
2525

26+
static {
27+
SentryIntegrationPackageStorage.getInstance()
28+
.addPackage("maven:io.sentry:sentry-quartz", BuildConfig.VERSION_NAME);
29+
}
30+
2631
public static final String SENTRY_CHECK_IN_ID_KEY = "sentry-checkin-id";
2732
public static final String SENTRY_SLUG_KEY = "sentry-slug";
2833
public static final String SENTRY_SCOPE_LIFECYCLE_TOKEN_KEY = "sentry-scope-lifecycle";

sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletContainerInitializer.java

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
@Open
1717
public class SentryServletContainerInitializer implements ServletContainerInitializer {
18+
19+
static {
20+
SentryIntegrationPackageStorage.getInstance()
21+
.addPackage("maven:io.sentry:sentry-servlet-jakarta", BuildConfig.VERSION_NAME);
22+
}
23+
1824
@Override
1925
public void onStartup(@Nullable Set<Class<?>> c, @NotNull ServletContext ctx)
2026
throws ServletException {

sentry-servlet/src/main/java/io/sentry/servlet/SentryServletContainerInitializer.java

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
@Open
1717
public class SentryServletContainerInitializer implements ServletContainerInitializer {
18+
19+
static {
20+
SentryIntegrationPackageStorage.getInstance()
21+
.addPackage("maven:io.sentry:sentry-servlet", BuildConfig.VERSION_NAME);
22+
}
23+
1824
@Override
1925
public void onStartup(@Nullable Set<Class<?>> c, @NotNull ServletContext ctx)
2026
throws ServletException {

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
@Open
8686
public class SentryAutoConfiguration {
8787

88+
static {
89+
SentryIntegrationPackageStorage.getInstance()
90+
.addPackage("maven:io.sentry:sentry-spring-boot-starter-jakarta", BuildConfig.VERSION_NAME);
91+
}
92+
8893
/** Registers general purpose Sentry related beans. */
8994
@Configuration(proxyBeanMethods = false)
9095
@EnableConfigurationProperties(SentryProperties.class)

sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
@Open
8484
public class SentryAutoConfiguration {
8585

86+
static {
87+
SentryIntegrationPackageStorage.getInstance()
88+
.addPackage("maven:io.sentry:sentry-spring-boot-starter", BuildConfig.VERSION_NAME);
89+
}
90+
8691
/** Registers general purpose Sentry related beans. */
8792
@Configuration(proxyBeanMethods = false)
8893
@EnableConfigurationProperties(SentryProperties.class)

sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryHubRegistrar.java

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
@Open
2121
public class SentryHubRegistrar implements ImportBeanDefinitionRegistrar {
2222

23+
static {
24+
SentryIntegrationPackageStorage.getInstance()
25+
.addPackage("maven:io.sentry:sentry-spring-jakarta", BuildConfig.VERSION_NAME);
26+
}
27+
2328
@Override
2429
public void registerBeanDefinitions(
2530
final @NotNull AnnotationMetadata importingClassMetadata,

sentry-spring/src/main/java/io/sentry/spring/SentryHubRegistrar.java

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
@Open
2121
public class SentryHubRegistrar implements ImportBeanDefinitionRegistrar {
2222

23+
static {
24+
SentryIntegrationPackageStorage.getInstance()
25+
.addPackage("maven:io.sentry:sentry-spring", BuildConfig.VERSION_NAME);
26+
}
27+
2328
@Override
2429
public void registerBeanDefinitions(
2530
final @NotNull AnnotationMetadata importingClassMetadata,

0 commit comments

Comments
 (0)