Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Upgrade guide

# Upgrading to the new Embrace Gradle Plugin DSL

The Embrace Gradle Plugin previously had a DSL via the 'swazzler' extension. This has been replaced with a new DSL via the 'embrace'
extension.
You can still use the 'swazzler' extension but it is deprecated and will be removed in a future release. It's recommended you use one
extension or the other, rather than combining their use. Migration instructions are shown
below:

| Old API | New API |
|-------------------------------------------------------|-------------------------------------------------------------------------|
| `swazzler.disableDependencyInjection` | `embrace.autoAddEmbraceDependencies` |
| `swazzler.disableComposeDependencyInjection` | `embrace.autoAddEmbraceComposeDependency` |
| `swazzler.instrumentOkHttp` | `embrace.bytecodeInstrumentation.okhttpEnabled` |
| `swazzler.instrumentOnClick` | `embrace.bytecodeInstrumentation.onClickEnabled` |
| `swazzler.instrumentOnLongClick` | `embrace.bytecodeInstrumentation.onLongClickEnabled` |
| `swazzler.instrumentWebview` | `embrace.bytecodeInstrumentation.webviewOnPageStartedEnabled` |
| `swazzler.instrumentFirebaseMessaging` | `embrace.bytecodeInstrumentation.firebasePushNotificationsEnabled` |
| `swazzler.classSkipList` | `embrace.bytecodeInstrumentation.classIgnorePatterns` |
| `swazzler.variantFilter` | `embrace.buildVariantFilter` |
| `SwazzlerExtension.Variant.enabled` | `embrace.buildVariantFilter.disableBytecodeInstrumentationForVariant()` |
| `SwazzlerExtension.Variant.swazzlerOff` | `embrace.buildVariantFilter.disablePluginForVariant()` |
| `SwazzlerExtension.Variant.setSwazzlingEnabled()` | `embrace.buildVariantFilter.disableBytecodeInstrumentationForVariant()` |
| `SwazzlerExtension.Variant.disablePluginForVariant()` | `embrace.buildVariantFilter.disablePluginForVariant()` |
| `embrace.disableCollectBuildData` | `embrace.telemetryEnabled` |
| `swazzler.forceIncrementalOverwrite` | Obsolete - no alternative provided. |
| `swazzler.disableRNBundleRetriever` | Obsolete - no alternative provided. |
| `swazzler.customSymbolsDirectory` | Obsolete - no alternative provided. |

The following project properties are now ignored and have no effect. You should remove them from your `gradle.properties` file:

- `embrace.logLevel`
- `embrace.instrumentationScope`

# Upgrading from 6.x to 7.x

Version 7 of the Embrace Android SDK contains the following breaking changes:
Expand All @@ -15,8 +48,8 @@ Version 7 of the Embrace Android SDK contains the following breaking changes:
- Several internally used classes and symbols have been hidden from the public API
- Recording a custom trace ID for an HTTP request from a custom request header is no longer supported. IDs in the
`x-emb-trace-id` header will still be recorded and displayed on the dashboard.
- Methods to add and remove the `payer` Persona has been removed.
- Use the generic Persona API methods with the name `payer` to get the equivalent functionality.
- Methods to add and remove the `payer` Persona has been removed.
- Use the generic Persona API methods with the name `payer` to get the equivalent functionality.
- The `setAppId` API has been removed. Changing the `appId` at runtime is no longer supported.
- Removed several obsolete remote config + local config properties. If you specify the below in your
`embrace-config.json` they will be ignored:
Expand All @@ -29,10 +62,11 @@ Version 7 of the Embrace Android SDK contains the following breaking changes:
- `sdk_config.networking.trace_id_header`
- `sdk_config.startup_moment.automatically_end`
- Removed the following properties from the Embrace Gradle plugin, that can be removed if they remain in your buildscripts:
- `customSymbolsDirectory`
- `jarSkipList`
- `encodeExtractedFileNames`
- Embrace no longer attempts to detect other signal handlers & reinstall itself by default. If you notice changes in your NDK crash report quality you can re-enable this behavior by setting `sdk_config.sig_handler_detection` to `true` in your `embrace-config.json`
- `customSymbolsDirectory`
- `jarSkipList`
- `encodeExtractedFileNames`
- Embrace no longer attempts to detect other signal handlers & reinstall itself by default. If you notice changes in your NDK crash report
quality you can re-enable this behavior by setting `sdk_config.sig_handler_detection` to `true` in your `embrace-config.json`

### Removed APIs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
}
}

swazzler {
variantFilter {
embrace {
buildVariantFilter {
if (it.name.contains("demoRelease")) {
it.disablePluginForVariant()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ repositories {

integrationTest.configureAndroidProject(project)

swazzler {
disableDependencyInjection = false
embrace {
autoAddEmbraceDependencies.set(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ android {
}
}

swazzler {
disableDependencyInjection = true
embrace {
autoAddEmbraceDependencies.set(false)
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.embrace.android.gradle.integration.framework

import com.android.build.api.dsl.ApplicationExtension
import io.embrace.android.gradle.plugin.api.EmbraceExtension
import io.embrace.android.gradle.plugin.model.AndroidCompactedVariantData
import io.embrace.android.gradle.plugin.network.EmbraceEndpoint
import io.embrace.android.gradle.plugin.tasks.EmbraceTask
import io.embrace.android.gradle.plugin.tasks.EmbraceUploadTask
import io.embrace.android.gradle.plugin.tasks.common.RequestParams
import io.embrace.android.gradle.swazzler.plugin.extension.SwazzlerExtension
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
Expand Down Expand Up @@ -39,7 +39,7 @@ abstract class IntegrationTestExtension(objectFactory: ObjectFactory) {
project: Project,
task: EmbraceUploadTask,
endpoint: EmbraceEndpoint = EmbraceEndpoint.PROGUARD,
filename: String? = null
filename: String? = null,
) {
configureEmbraceTask(task)
task.requestParams.set(
Expand All @@ -63,8 +63,8 @@ abstract class IntegrationTestExtension(objectFactory: ObjectFactory) {

// disable dependency injection as SNAPSHOT versions of SDK don't necessarily exist
// whenever unit tests are run
val embrace = checkNotNull(project.extensions.findByType(SwazzlerExtension::class.java))
embrace.disableDependencyInjection.set(true)
val embrace = checkNotNull(project.extensions.findByType(EmbraceExtension::class.java))
embrace.autoAddEmbraceDependencies.set(false)

val android = checkNotNull(project.extensions.findByType(ApplicationExtension::class.java))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@file:Suppress("DEPRECATION")

package io.embrace.android.gradle.plugin

import io.embrace.android.gradle.plugin.api.EmbraceExtension
import io.embrace.android.gradle.plugin.gradle.GradleVersion
import io.embrace.android.gradle.plugin.gradle.GradleVersion.Companion.isAtLeast
import io.embrace.android.gradle.plugin.instrumentation.config.model.VariantConfig
Expand Down Expand Up @@ -28,6 +31,12 @@ class EmbraceGradlePlugin : Plugin<Project> {
project.objects
)

val embrace = project.extensions.create(
"embrace",
EmbraceExtension::class.java,
project.objects
)

// this property will hold configuration for each variant. It will be updated each time a new variant
// is configured
val variantConfigurationsListProperty =
Expand All @@ -39,7 +48,8 @@ class EmbraceGradlePlugin : Plugin<Project> {
impl.onAndroidPluginApplied(
project,
variantConfigurationsListProperty,
extension
extension,
embrace,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@file:Suppress("DEPRECATION")

package io.embrace.android.gradle.plugin

import io.embrace.android.gradle.plugin.agp.AgpUtils
import io.embrace.android.gradle.plugin.agp.AgpVersion
import io.embrace.android.gradle.plugin.agp.AgpWrapper
import io.embrace.android.gradle.plugin.agp.AgpWrapperImpl
import io.embrace.android.gradle.plugin.api.EmbraceExtension
import io.embrace.android.gradle.plugin.buildreporter.BuildTelemetryService
import io.embrace.android.gradle.plugin.config.PluginBehaviorImpl
import io.embrace.android.gradle.plugin.config.variant.EmbraceVariantConfigurationBuilder
Expand All @@ -26,12 +29,12 @@ class EmbraceGradlePluginDelegate {
project: Project,
variantConfigurationsListProperty: ListProperty<VariantConfig>,
extension: SwazzlerExtension,
embrace: EmbraceExtension,
) {
val agpWrapper = AgpWrapperImpl(project)
validateMinAgpVersion(agpWrapper)

val behavior = PluginBehaviorImpl(project, extension)
Logger.setPluginLogLevel(behavior.logLevel)
val behavior = PluginBehaviorImpl(project, extension, embrace)

BuildTelemetryService.register(
project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Logger<T>(clazz: Class<T>) {
/**
* Log a message with INFO severity.
*/
fun info(msg: String, throwable: Throwable? = null) = logIfAllowed(
fun info(msg: String, throwable: Throwable? = null) = log(
LogLevel.INFO,
msg,
throwable
Expand All @@ -22,7 +22,7 @@ class Logger<T>(clazz: Class<T>) {
/**
* Log a message with WARN severity.
*/
fun warn(msg: String, throwable: Throwable? = null) = logIfAllowed(
fun warn(msg: String, throwable: Throwable? = null) = log(
LogLevel.WARN,
msg,
throwable
Expand All @@ -31,7 +31,7 @@ class Logger<T>(clazz: Class<T>) {
/**
* Log a message with ERROR severity.
*/
fun error(msg: String, throwable: Throwable? = null) = logIfAllowed(
fun error(msg: String, throwable: Throwable? = null) = log(
LogLevel.ERROR,
msg,
throwable
Expand All @@ -40,37 +40,11 @@ class Logger<T>(clazz: Class<T>) {
/**
* Logs the message only if the current Embrace log level allows it.
*/
private fun logIfAllowed(
private fun log(
gradleLevel: LogLevel,
msg: String,
throwable: Throwable?
throwable: Throwable?,
) {
if (gradleLevel.shouldLog()) {
gradleLogger.log(gradleLevel, "$logPrefix $msg", throwable)
}
}

companion object {
private val errorLevels = setOf(LogLevel.ERROR)
private val warnLevels = errorLevels + LogLevel.WARN
private val infoLevels = warnLevels + LogLevel.INFO

@Volatile
private var levelsToLog: Set<LogLevel> = emptySet()

fun getSupportedLogLevel(logLevelString: String?): LogLevel? = infoLevels.firstOrNull {
it.name.equals(logLevelString, true)
}

fun setPluginLogLevel(logLevel: LogLevel?) {
levelsToLog = when (logLevel) {
LogLevel.INFO -> infoLevels
LogLevel.WARN -> warnLevels
LogLevel.ERROR -> errorLevels
else -> emptySet()
}
}

private fun LogLevel.shouldLog(): Boolean = levelsToLog.contains(this)
gradleLogger.log(gradleLevel, "$logPrefix $msg", throwable)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.embrace.android.gradle.plugin.api

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

/**
* DSL for configuring the Embrace Gradle Plugin's bytecode instrumentation behavior.
*/
abstract class EmbraceBytecodeInstrumentation @Inject internal constructor(objectFactory: ObjectFactory) {

/**
* Global flag that overrides all others & decides whether Embrace should perform any bytecode instrumentation.
* Defaults to true.
*/
val enabled: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(true)

/**
* Whether Embrace should automatically instrument OkHttp requests. Defaults to true.
*/
val okhttpEnabled: Property<Boolean> = objectFactory.property(Boolean::class.java)

/**
* Whether Embrace should automatically instrument android.view.View click events. Defaults to true.
*/
val onClickEnabled: Property<Boolean> = objectFactory.property(Boolean::class.java)

/**
* Whether Embrace should automatically instrument android.view.View long click events. Defaults to true.
*/
val onLongClickEnabled: Property<Boolean> = objectFactory.property(Boolean::class.java)

/**
* Whether Embrace should automatically instrument onPageStarted() in webviews. Defaults to true.
*/
val webviewOnPageStartedEnabled: Property<Boolean> = objectFactory.property(Boolean::class.java)

/**
* Whether Embrace should automatically instrument push notifications from Firebase. Defaults to false.
*/
val firebasePushNotificationsEnabled: Property<Boolean> =
objectFactory.property(Boolean::class.java)

/**
* A list of string patterns that are used to filter classes during bytecode instrumentation. For example, 'com.example.foo.*'
* would avoid instrumenting any classes in the 'com.example.foo' package.
*
* This can be useful if you wish to avoid instrumenting certain parts of your codebase.
*
* Defaults to an empty list.
*/
val classIgnorePatterns: ListProperty<String> = objectFactory.listProperty(String::class.java)
}
Loading
Loading