Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 14 additions & 6 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Upgrade guide

# Upgrading to the new Embrace Gradle Plugin DSL

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 +22,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 +36,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 @@ -31,7 +31,6 @@ class EmbraceGradlePluginDelegate {
validateMinAgpVersion(agpWrapper)

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

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
@@ -1,7 +1,5 @@
package io.embrace.android.gradle.plugin.config

import com.android.build.api.instrumentation.InstrumentationScope

interface InstrumentationBehavior {

/**
Expand All @@ -10,11 +8,6 @@ interface InstrumentationBehavior {
*/
val invalidateBytecode: Boolean

/**
* The scope of what modules get instrumented, set via `embrace.instrumentationScope`
*/
val scope: InstrumentationScope

/**
* Whether OkHttp should be auto-instrumented
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package io.embrace.android.gradle.plugin.config

import com.android.build.api.instrumentation.InstrumentationScope
import io.embrace.android.gradle.swazzler.plugin.extension.SwazzlerExtension
import org.gradle.api.Project

class InstrumentationBehaviorImpl(
private val project: Project,
private val extension: SwazzlerExtension,
) : InstrumentationBehavior {

override val invalidateBytecode: Boolean by lazy {
extension.forceIncrementalOverwrite.get()
}

override val scope: InstrumentationScope by lazy {
val prop = project.getProperty(EMBRACE_INSTRUMENTATION_SCOPE)
?: return@lazy InstrumentationScope.ALL
try {
InstrumentationScope.valueOf(prop.uppercase())
} catch (e: IllegalArgumentException) {
InstrumentationScope.ALL
}
}

override val okHttpEnabled: Boolean by lazy {
extension.instrumentOkHttp.get()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package io.embrace.android.gradle.plugin.config

import org.gradle.api.logging.LogLevel

interface PluginBehavior {

/**
* The log level, set via `embrace.logLevel`
*/
val logLevel: LogLevel?

/**
* Whether telemetry can be captured for this build, set via `embrace.disableCollectBuildData`.
*/
Expand Down Expand Up @@ -78,8 +71,6 @@ interface PluginBehavior {
}

const val EMBRACE_BASE_URL = "embrace.baseUrl"
const val EMBRACE_LOG_LEVEL = "embrace.logLevel"
const val EMBRACE_INSTRUMENTATION_SCOPE = "embrace.instrumentationScope"
const val EMBRACE_DISABLE_COLLECT_BUILD_DATA = "embrace.disableCollectBuildData"
const val EMBRACE_UPLOAD_IL2CPP_MAPPING_FILES = "embrace.uploadIl2CppMappingFiles"
const val EMBRACE_DISABLE_MAPPING_FILE_UPLOAD = "embrace.disableMappingFileUpload"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.embrace.android.gradle.plugin.config

import io.embrace.android.gradle.plugin.Logger
import io.embrace.android.gradle.swazzler.plugin.extension.SwazzlerExtension
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import java.io.File

class PluginBehaviorImpl(
Expand All @@ -12,11 +10,7 @@ class PluginBehaviorImpl(
) : PluginBehavior {

override val instrumentation: InstrumentationBehavior by lazy {
InstrumentationBehaviorImpl(project, extension)
}

override val logLevel: LogLevel? by lazy {
Logger.getSupportedLogLevel(project.getProperty(EMBRACE_LOG_LEVEL))
InstrumentationBehaviorImpl(extension)
}

override val isTelemetryDisabled: Boolean by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package io.embrace.android.gradle.plugin.instrumentation

import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.AndroidComponentsExtension
import io.embrace.android.gradle.plugin.config.PluginBehavior
import io.embrace.android.gradle.plugin.instrumentation.config.model.VariantConfig
Expand All @@ -20,8 +21,7 @@ fun registerAsmTasks(
) {
// register for asm
project.extensions.getByType(AndroidComponentsExtension::class.java).onVariants { variant ->
val scope = behavior.instrumentation.scope
project.logger.info("Registered ASM task for ${variant.name} with scope=${scope.name}")
project.logger.info("Registered ASM task for ${variant.name}")

// compute frames automatically only for modified methods
variant.instrumentation.setAsmFramesComputationMode(
Expand All @@ -31,7 +31,7 @@ fun registerAsmTasks(
// register the ASM class visitor factory
variant.instrumentation.transformClassesWith(
EmbraceClassVisitorFactory::class.java,
scope
InstrumentationScope.ALL
) { params: BytecodeInstrumentationParams ->
project.logger.debug("Configuring ASM instrumentation")

Expand All @@ -40,11 +40,6 @@ fun registerAsmTasks(
variantConfigs.first { it.variantName == variant.name }
}
)
params.logLevel.set(
project.provider {
behavior.logLevel
}
)
params.disabled.set(
project.provider {
behavior.isPluginDisabledForVariant(variant.name) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package io.embrace.android.gradle.plugin.instrumentation

import com.android.build.api.instrumentation.InstrumentationParameters
import io.embrace.android.gradle.plugin.instrumentation.config.model.VariantConfig
import org.gradle.api.logging.LogLevel
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional

/**
* Contains parameters that affect how bytecode is manipulated during instrumentation.
Expand All @@ -22,14 +20,6 @@ interface BytecodeInstrumentationParams : InstrumentationParameters {
@get:Input
val config: Property<VariantConfig>

/**
* Whether or not the plugin should operate in debug mode. This will mainly affect
* logging.
*/
@get:Optional
@get:Input
val logLevel: Property<LogLevel>

/**
* Whether or not the plugin should operate for this variant.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.embrace.android.gradle.plugin.config

import com.android.build.api.instrumentation.InstrumentationScope
import io.embrace.android.gradle.swazzler.plugin.extension.SwazzlerExtension
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
Expand All @@ -20,24 +19,7 @@ class InstrumentationBehaviorImplTest {
fun setUp() {
project = ProjectBuilder.builder().build()
extension = project.extensions.create("swazzler", SwazzlerExtension::class.java)
behavior = InstrumentationBehaviorImpl(project, extension)
}

@Test
fun `instrumentation scope default`() {
assertEquals(InstrumentationScope.ALL, behavior.scope)
}

@Test
fun `instrumentation scope valid`() {
addGradleProperty(EMBRACE_INSTRUMENTATION_SCOPE, "project")
assertEquals(InstrumentationScope.PROJECT, behavior.scope)
}

@Test
fun `instrumentation scope invalid`() {
addGradleProperty(EMBRACE_INSTRUMENTATION_SCOPE, "foo")
assertEquals(InstrumentationScope.ALL, behavior.scope)
behavior = InstrumentationBehaviorImpl(extension)
}

@Test
Expand Down Expand Up @@ -117,8 +99,4 @@ class InstrumentationBehaviorImplTest {
extension.classSkipList.set(values)
assertEquals(values, behavior.ignoredClasses)
}

private fun addGradleProperty(key: String, value: String) {
project.extensions.extraProperties[key] = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package io.embrace.android.gradle.plugin.config
import io.embrace.android.gradle.swazzler.plugin.extension.SwazzlerExtension
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
Expand All @@ -26,35 +24,6 @@ class PluginBehaviorImplTest {
behavior = PluginBehaviorImpl(project, extension)
}

@Test
fun `log level default`() {
assertNull(behavior.logLevel)
}

@Test
fun `log level INFO`() {
addGradleProperty(EMBRACE_LOG_LEVEL, "info")
assertEquals(LogLevel.INFO, behavior.logLevel)
}

@Test
fun `log level WARN`() {
addGradleProperty(EMBRACE_LOG_LEVEL, "WARN")
assertEquals(LogLevel.WARN, behavior.logLevel)
}

@Test
fun `log level ERROR`() {
addGradleProperty(EMBRACE_LOG_LEVEL, "ErRoR")
assertEquals(LogLevel.ERROR, behavior.logLevel)
}

@Test
fun `log level invalid`() {
addGradleProperty(EMBRACE_LOG_LEVEL, "foo")
assertNull(behavior.logLevel)
}

@Test
fun `telemetry disabled default`() {
assertFalse(behavior.isTelemetryDisabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class EmbraceClassVisitorFactoryTest {
@Test
fun testClassFiltering() {
val filter = ClassInstrumentationFilter(mutableListOf("kotlin.Boolean"))
val params = TestBytecodeInstrumentationParams(disabled = false, classInstrumentationFilter = filter)
val params = TestBytecodeInstrumentationParams(
disabled = false,
classInstrumentationFilter = filter
)
val factory = TestVisitorFactoryImpl(params = params)
assertTrue(factory.isInstrumentable(clzDataString))
assertFalse(factory.isInstrumentable(clzDataBool))
Expand Down Expand Up @@ -183,11 +186,11 @@ class EmbraceClassVisitorFactoryTest {
instrumentFirebaseMessaging: Boolean = true
): TestBytecodeInstrumentationParams {
return TestBytecodeInstrumentationParams(
instrumentFirebaseMessaging = instrumentFirebaseMessaging,
instrumentWebview = instrumentWebview,
instrumentOkHttp = instrumentOkHttp,
instrumentOnClick = instrumentOnClick,
instrumentOnLongClick = instrumentOnLongClick,
instrumentWebview = instrumentWebview,
instrumentFirebaseMessaging = instrumentFirebaseMessaging
instrumentOnClick = instrumentOnClick
)
}

Expand Down
Loading
Loading