Skip to content

Commit

Permalink
feat: Send SDK Integration List, add missing packages (#2179)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
Co-authored-by: Lukas Bloder <lukas.bloder@gmail.com>
Co-authored-by: Alexander Dinauer <alexander.dinauer@sentry.io>
Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>
  • Loading branch information
5 people authored Feb 21, 2023
1 parent e9b703c commit 4694204
Show file tree
Hide file tree
Showing 81 changed files with 667 additions and 123 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- If set to `true`, performance is enabled, even if no `tracesSampleRate` or `tracesSampler` have been configured.
- If set to `false` performance is disabled, regardless of `tracesSampleRate` and `tracesSampler` options.
- Detect dependencies by listing MANIFEST.MF files at runtime ([#2538](https://github.com/getsentry/sentry-java/pull/2538))
- Report integrations in use, report packages in use more consistently ([#2179](https://github.com/getsentry/sentry-java/pull/2179))

### Fixes

Expand Down
8 changes: 8 additions & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,17 @@ object Config {
val SENTRY_JUL_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.jul"
val SENTRY_LOG4J2_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.log4j2"
val SENTRY_SPRING_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring"
val SENTRY_SPRING_JAKARTA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring.jakarta"
val SENTRY_SPRING_BOOT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot"
val SENTRY_SPRING_BOOT_JAKARTA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot.jakarta"
val SENTRY_OPENTELEMETRY_AGENT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agent"
val SENTRY_APOLLO3_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo3"
val SENTRY_APOLLO_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.apollo"
val SENTRY_GRAPHQL_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.graphql"
val SENTRY_JDBC_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.jdbc"
val SENTRY_SERVLET_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.servlet"
val SENTRY_SERVLET_JAKARTA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.servlet.jakarta"
val SENTRY_COMPOSE_HELPER_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.compose.helper"
val group = "io.sentry"
val description = "SDK for sentry.io"
val versionNameProp = "versionName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
if (this.options.isEnableActivityLifecycleBreadcrumbs() || performanceEnabled) {
application.registerActivityLifecycleCallbacks(this);
this.options.getLogger().log(SentryLevel.DEBUG, "ActivityLifecycleIntegration installed.");
addIntegrationToSdkVersion();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private void register(final @NotNull IHub hub, final @NotNull SentryAndroidOptio
anrWatchDog.start();

options.getLogger().log(SentryLevel.DEBUG, "AnrIntegration installed.");
addIntegrationToSdkVersion();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
options
.getLogger()
.log(SentryLevel.DEBUG, "AppComponentsBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
} catch (Throwable e) {
this.options.setEnableAppComponentBreadcrumbs(false);
options.getLogger().log(SentryLevel.INFO, e, "ComponentCallbacks2 is not available.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void addObserver(final @NotNull IHub hub) {
try {
ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher);
options.getLogger().log(SentryLevel.DEBUG, "AppLifecycleIntegration installed.");
addIntegrationToSdkVersion();
} catch (Throwable e) {
// This is to handle a potential 'AbstractMethodError' gracefully. The error is triggered in
// connection with conflicting dependencies of the androidx.lifecycle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final void register(final @NotNull IHub hub, final @NotNull SentryOptions
method.invoke(null, args);

this.options.getLogger().log(SentryLevel.DEBUG, "NdkIntegration installed.");
addIntegrationToSdkVersion();
} catch (NoSuchMethodException e) {
disableNdkIntegration(this.options);
this.options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
telephonyManager.listen(listener, android.telephony.PhoneStateListener.LISTEN_CALL_STATE);

options.getLogger().log(SentryLevel.DEBUG, "PhoneStateBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
} catch (Throwable e) {
this.options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void register(@NotNull IHub hub, @NotNull SentryOptions options) {
.log(SentryLevel.DEBUG, "Synchronous send timed out, continuing in the background.");
}
}

androidOptions.getLogger().log(SentryLevel.DEBUG, "SendCachedEnvelopeIntegration installed.");
} catch (Throwable e) {
androidOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
this.options
.getLogger()
.log(SentryLevel.DEBUG, "SystemEventsBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
} catch (Throwable e) {
this.options.setEnableSystemEventBreadcrumbs(false);
this.options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
options
.getLogger()
.log(SentryLevel.DEBUG, "TempSensorBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion();
} else {
this.options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void register(@NotNull IHub hub, @NotNull SentryOptions options) {
if (isAndroidXAvailable) {
application.registerActivityLifecycleCallbacks(this);
this.options.getLogger().log(SentryLevel.DEBUG, "UserInteractionIntegration installed.");
addIntegrationToSdkVersion();
} else {
options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class SentryAndroidOptionsTest {
assertEquals(BuildConfig.VERSION_NAME, sdkVersion.version)

assertTrue(
sdkVersion.packages!!.any {
sdkVersion.packageSet.any {
it.name == "maven:io.sentry:sentry-android-core" &&
it.version == BuildConfig.VERSION_NAME
}
)

assertTrue(
sdkVersion.packages!!.any {
sdkVersion.packageSet.any {
it.name == "maven:io.sentry:sentry" &&
it.version == BuildConfig.VERSION_NAME
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import androidx.fragment.app.FragmentActivity
import io.sentry.IHub
import io.sentry.Integration
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel.DEBUG
import io.sentry.SentryOptions
import java.io.Closeable
Expand Down Expand Up @@ -47,6 +48,9 @@ class FragmentLifecycleIntegration(

application.registerActivityLifecycleCallbacks(this)
options.logger.log(DEBUG, "FragmentLifecycleIntegration installed.")
addIntegrationToSdkVersion()
SentryIntegrationPackageStorage.getInstance()
.addPackage("maven:io.sentry:sentry-android-fragment", BuildConfig.VERSION_NAME)
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public final class io/sentry/android/navigation/BuildConfig {
public fun <init> ()V
}

public final class io/sentry/android/navigation/SentryNavigationListener : androidx/navigation/NavController$OnDestinationChangedListener {
public final class io/sentry/android/navigation/SentryNavigationListener : androidx/navigation/NavController$OnDestinationChangedListener, io/sentry/IntegrationName {
public static final field Companion Lio/sentry/android/navigation/SentryNavigationListener$Companion;
public static final field NAVIGATION_OP Ljava/lang/String;
public fun <init> ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import io.sentry.Hint
import io.sentry.HubAdapter
import io.sentry.IHub
import io.sentry.ITransaction
import io.sentry.IntegrationName
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel.DEBUG
import io.sentry.SentryLevel.INFO
import io.sentry.SentryOptions
Expand All @@ -32,7 +34,7 @@ class SentryNavigationListener @JvmOverloads constructor(
private val hub: IHub = HubAdapter.getInstance(),
private val enableNavigationBreadcrumbs: Boolean = true,
private val enableNavigationTracing: Boolean = true
) : NavController.OnDestinationChangedListener {
) : NavController.OnDestinationChangedListener, IntegrationName {

private var previousDestinationRef: WeakReference<NavDestination>? = null
private var previousArgs: Bundle? = null
Expand All @@ -41,6 +43,12 @@ class SentryNavigationListener @JvmOverloads constructor(

private var activeTransaction: ITransaction? = null

init {
addIntegrationToSdkVersion()
SentryIntegrationPackageStorage.getInstance()
.addPackage("maven:io.sentry:sentry-android-navigation", BuildConfig.VERSION_NAME)
}

override fun onDestinationChanged(
controller: NavController,
destination: NavDestination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SentryNdkUtilTest {
val options = SentryOptions()
SentryNdkUtil.addPackage(options.sdkVersion)
assertTrue(
options.sdkVersion!!.packages!!.any {
options.sdkVersion!!.packageSet.any {
it.name == "maven:io.sentry:sentry-android-ndk"
it.version == BuildConfig.VERSION_NAME
}
Expand All @@ -26,6 +26,6 @@ class SentryNdkUtilTest {
}
SentryNdkUtil.addPackage(options.sdkVersion)

assertNull(options.sdkVersion?.packages)
assertNull(options.sdkVersion?.packageSet)
}
}
2 changes: 1 addition & 1 deletion sentry-android-okhttp/api/sentry-android-okhttp.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public final class io/sentry/android/okhttp/BuildConfig {
public fun <init> ()V
}

public final class io/sentry/android/okhttp/SentryOkHttpInterceptor : okhttp3/Interceptor {
public final class io/sentry/android/okhttp/SentryOkHttpInterceptor : io/sentry/IntegrationName, okhttp3/Interceptor {
public fun <init> ()V
public fun <init> (Lio/sentry/IHub;)V
public fun <init> (Lio/sentry/IHub;Lio/sentry/android/okhttp/SentryOkHttpInterceptor$BeforeSpanCallback;ZLjava/util/List;Ljava/util/List;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import io.sentry.HttpStatusCodeRange
import io.sentry.HubAdapter
import io.sentry.IHub
import io.sentry.ISpan
import io.sentry.IntegrationName
import io.sentry.SentryEvent
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SpanStatus
import io.sentry.TypeCheckHint.OKHTTP_REQUEST
import io.sentry.TypeCheckHint.OKHTTP_RESPONSE
Expand Down Expand Up @@ -45,12 +47,18 @@ class SentryOkHttpInterceptor(
HttpStatusCodeRange(HttpStatusCodeRange.DEFAULT_MIN, HttpStatusCodeRange.DEFAULT_MAX)
),
private val failedRequestTargets: List<String> = listOf(".*")
) : Interceptor {
) : Interceptor, IntegrationName {

constructor() : this(HubAdapter.getInstance())
constructor(hub: IHub) : this(hub, null)
constructor(beforeSpan: BeforeSpanCallback) : this(HubAdapter.getInstance(), beforeSpan)

init {
addIntegrationToSdkVersion()
SentryIntegrationPackageStorage.getInstance()
.addPackage("maven:io.sentry:sentry-android-okhttp", BuildConfig.VERSION_NAME)
}

override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.sentry.android.timber
import io.sentry.IHub
import io.sentry.ILogger
import io.sentry.Integration
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel
import io.sentry.SentryOptions
import io.sentry.android.timber.BuildConfig.VERSION_NAME
Expand All @@ -20,14 +21,14 @@ class SentryTimberIntegration(
private lateinit var logger: ILogger

override fun register(hub: IHub, options: SentryOptions) {
options.sdkVersion?.addPackage("maven:io.sentry:sentry-android-timber", VERSION_NAME)

logger = options.logger

tree = SentryTimberTree(hub, minEventLevel, minBreadcrumbLevel)
Timber.plant(tree)

logger.log(SentryLevel.DEBUG, "SentryTimberIntegration installed.")
SentryIntegrationPackageStorage.getInstance().addPackage("maven:io.sentry:sentry-android-timber", VERSION_NAME)
addIntegrationToSdkVersion()
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,25 @@ class SentryTimberIntegrationTest {
}

@Test
fun `Integrations adds itself to the package list`() {
fun `Integration adds itself to the package list`() {
val sut = fixture.getSut()
sut.register(fixture.hub, fixture.options)

assertTrue(
fixture.options.sdkVersion!!.packages!!.any {
fixture.options.sdkVersion!!.packageSet.any {
it.name == "maven:io.sentry:sentry-android-timber" &&
it.version == BuildConfig.VERSION_NAME
}
)
}

@Test
fun `Integration adds itself to the integration list`() {
val sut = fixture.getSut()
sut.register(fixture.hub, fixture.options)

assertTrue(
fixture.options.sdkVersion!!.integrationSet.contains("Timber")
)
}
}
8 changes: 7 additions & 1 deletion sentry-apollo-3/api/sentry-apollo-3.api
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
public final class io/sentry/apollo3/SentryApollo3HttpInterceptor : com/apollographql/apollo3/network/http/HttpInterceptor {
public final class io/sentry/apollo3/BuildConfig {
public static final field SENTRY_APOLLO3_SDK_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
}

public final class io/sentry/apollo3/SentryApollo3HttpInterceptor : com/apollographql/apollo3/network/http/HttpInterceptor, io/sentry/IntegrationName {
public static final field Companion Lio/sentry/apollo3/SentryApollo3HttpInterceptor$Companion;
public static final field SENTRY_APOLLO_3_OPERATION_NAME Ljava/lang/String;
public static final field SENTRY_APOLLO_3_OPERATION_TYPE Ljava/lang/String;
Expand All @@ -8,6 +13,7 @@ public final class io/sentry/apollo3/SentryApollo3HttpInterceptor : com/apollogr
public fun <init> (Lio/sentry/IHub;Lio/sentry/apollo3/SentryApollo3HttpInterceptor$BeforeSpanCallback;)V
public synthetic fun <init> (Lio/sentry/IHub;Lio/sentry/apollo3/SentryApollo3HttpInterceptor$BeforeSpanCallback;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun dispose ()V
public fun getIntegrationName ()Ljava/lang/String;
public fun intercept (Lcom/apollographql/apollo3/api/http/HttpRequest;Lcom/apollographql/apollo3/network/http/HttpInterceptorChain;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

Expand Down
7 changes: 7 additions & 0 deletions sentry-apollo-3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ tasks.withType<JavaCompile>().configureEach {
option("NullAway:AnnotatedPackages", "io.sentry")
}
}

buildConfig {
useJavaOutput()
packageName("io.sentry.apollo3")
buildConfigField("String", "SENTRY_APOLLO3_SDK_NAME", "\"${Config.Sentry.SENTRY_APOLLO3_SDK_NAME}\"")
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ import io.sentry.Hint
import io.sentry.HubAdapter
import io.sentry.IHub
import io.sentry.ISpan
import io.sentry.IntegrationName
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel
import io.sentry.SpanStatus
import io.sentry.TypeCheckHint
import io.sentry.util.PropagationTargetsUtils
import io.sentry.util.UrlUtils

class SentryApollo3HttpInterceptor @JvmOverloads constructor(private val hub: IHub = HubAdapter.getInstance(), private val beforeSpan: BeforeSpanCallback? = null) :
HttpInterceptor {
HttpInterceptor, IntegrationName {

init {
addIntegrationToSdkVersion()
SentryIntegrationPackageStorage.getInstance().addPackage("maven:io.sentry:sentry-apollo-3", BuildConfig.VERSION_NAME)
}

override suspend fun intercept(
request: HttpRequest,
Expand Down Expand Up @@ -76,6 +83,10 @@ class SentryApollo3HttpInterceptor @JvmOverloads constructor(private val hub: IH
}
}

override fun getIntegrationName(): String {
return super.getIntegrationName().replace("Http", "")
}

private fun removeSentryInternalHeaders(headers: List<HttpHeader>): List<HttpHeader> {
return headers.filterNot { it.name == SENTRY_APOLLO_3_VARIABLES || it.name == SENTRY_APOLLO_3_OPERATION_NAME || it.name == SENTRY_APOLLO_3_OPERATION_TYPE }
}
Expand Down
Loading

0 comments on commit 4694204

Please sign in to comment.