Skip to content
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Add Binder IPC call instrumentation ([#1159](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1159))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: Do we normally also tell folks how to enable/disable (+ inform them that it's auto-enabled)?


## 6.9.0

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ fun ApplicationAndroidComponentsExtension.configure(
extension.includeSourceContext,
extension.dexguardEnabled,
extension.tracingInstrumentation.appStart.enabled,
extension.tracingInstrumentation.binder.enabled,
)
/**
* We have to register SentryModulesService as a build event listener, so it will not be
Expand Down Expand Up @@ -228,6 +229,7 @@ fun ApplicationAndroidComponentsExtension.configure(
params.appStartEnabled.setDisallowChanges(
extension.tracingInstrumentation.appStart.enabled
)
params.binderEnabled.setDisallowChanges(extension.tracingInstrumentation.binder.enabled)
params.tmpDir.set(
project.layout.buildDirectory.dir("sentry-logs/instrumentation/${variant.name}")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.sentry.android.gradle.extensions

import javax.inject.Inject
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property

open class BinderExtension @Inject constructor(objects: ObjectFactory) {
/**
* Enables or disables Binder IPC call instrumentation. Defaults to true. This requires
* sentry-android-core version TODO or above, and needs to be enabled. See

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

h: TODO (same below)

(though I'm sure they're on your radar)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: Should we remove the "and needs to be enabled" since we enable it by default, or is that phrase referring to something else?

* https://docs.sentry.io/platforms/android/configuration/gradle/#tracing-auto-instrumentation for
* more details.
*/
val enabled: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ open class TracingInstrumentationExtension @Inject constructor(objects: ObjectFa
fun appStart(appStartExtensionAction: Action<AppStartExtension>) {
appStartExtensionAction.execute(appStart)
}

val binder: BinderExtension = objects.newInstance(BinderExtension::class.java)

fun binder(binderAction: Action<BinderExtension>) {
binderAction.execute(binder)
}
}

enum class InstrumentationFeature(val integrationName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.sentry.android.gradle.instrumentation.androidx.sqlite.database.Android
import io.sentry.android.gradle.instrumentation.androidx.sqlite.statement.AndroidXSQLiteStatement
import io.sentry.android.gradle.instrumentation.appstart.Application
import io.sentry.android.gradle.instrumentation.appstart.ContentProvider
import io.sentry.android.gradle.instrumentation.binder.Binder
import io.sentry.android.gradle.instrumentation.logcat.Logcat
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel
import io.sentry.android.gradle.instrumentation.okhttp.OkHttp
Expand Down Expand Up @@ -63,6 +64,8 @@ abstract class SpanAddingClassVisitorFactory :
@get:Input val logcatEnabled: Property<Boolean>

@get:Input val appStartEnabled: Property<Boolean>

@get:Input val binderEnabled: Property<Boolean>
}

private val instrumentable: ClassInstrumentable
Expand Down Expand Up @@ -106,6 +109,7 @@ abstract class SpanAddingClassVisitorFactory :
RemappingInstrumentable().takeIf { sentryModulesService.isFileIOInstrEnabled() },
ComposeNavigation().takeIf { sentryModulesService.isComposeInstrEnabled() },
Logcat().takeIf { sentryModulesService.isLogcatInstrEnabled() },
Binder().takeIf { sentryModulesService.isBinderInstrEnabled() },
Application().takeIf { sentryModulesService.isAppStartInstrEnabled() },
ContentProvider().takeIf { sentryModulesService.isAppStartInstrEnabled() },
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.sentry.android.gradle.instrumentation.binder

import com.android.build.api.instrumentation.ClassContext
import io.sentry.android.gradle.instrumentation.ClassInstrumentable
import io.sentry.android.gradle.instrumentation.CommonClassVisitor
import io.sentry.android.gradle.instrumentation.SpanAddingClassVisitorFactory
import io.sentry.android.gradle.instrumentation.util.isSentryClass
import org.objectweb.asm.ClassVisitor

class Binder : ClassInstrumentable {

companion object {
private const val CLASSNAME = "Binder"
}

override fun getVisitor(
instrumentableContext: ClassContext,
apiVersion: Int,
originalVisitor: ClassVisitor,
parameters: SpanAddingClassVisitorFactory.SpanAddingParameters,
): ClassVisitor {
return CommonClassVisitor(
apiVersion,
originalVisitor,
CLASSNAME,
listOf(BinderMethodInstrumentable()),
parameters,
)
}

override fun isInstrumentable(data: ClassContext) = !data.isSentryClass()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

m: Any concerns about impact on build time?

Our hash map lookups are fast, and I see we also perform the same scan for logging, etc., so the effect will be incremental for anyone who hasn't disabled the defaults. Not a blocker, just making sure we considered it + curious to hear how we think about these sorts of scans (eg, okay to add indefinitely b/c cost is marginal vs something we weigh carefully each time out).

Loading