Skip to content

Commit

Permalink
Do not run sentry-cli commands if telemetry is disabled (#648)
Browse files Browse the repository at this point in the history
* Do not run sentry-cli commands if telemetry is disabled

* Changelog

* Fix test
  • Loading branch information
romtsn authored Feb 2, 2024
1 parent 4b58fa9 commit afa92e8
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 127 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- This should fix the `java.lang.AssertionError: Class with incorrect id found` exception when using `kotlinx.serialization`
- Fall back to `findTask` if `assembleProvider` of AndroidVariant is null when hooking source bundle and native symbols upload tasks ([#639](https://github.com/getsentry/sentry-android-gradle-plugin/pull/639))
- Hook source context tasks to also run after `install{Variant}` tasks ([#643](https://github.com/getsentry/sentry-android-gradle-plugin/pull/643))
- Do not run sentry-cli commands if telemetry is disabled ([#648](https://github.com/getsentry/sentry-android-gradle-plugin/pull/648))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import io.sentry.SpanStatus
import io.sentry.android.gradle.SentryPlugin
import io.sentry.android.gradle.SentryPropertiesFileProvider
import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.telemetry.SentryCliInfoValueSource.Params
import io.sentry.android.gradle.telemetry.SentryCliInfoValueSource.InfoParams
import io.sentry.android.gradle.telemetry.SentryCliVersionValueSource.VersionParams
import io.sentry.android.gradle.util.AgpVersions
import io.sentry.android.gradle.util.GradleVersions
import io.sentry.android.gradle.util.SentryCliException
Expand Down Expand Up @@ -256,8 +257,11 @@ abstract class SentryTelemetryService :
): SentryTelemetryServiceParams {
val tags = extraTagsFromExtension(project, extension)
val org = sentryOrg ?: extension.org.orNull
val isTelemetryEnabled = extension.telemetry.get()

if (isExecAvailable()) {
// if telemetry is disabled we don't even need to exec sentry-cli as telemetry service
// will be no-op
if (isExecAvailable() && isTelemetryEnabled) {
return paramsWithExecAvailable(
project,
cliExecutable,
Expand All @@ -269,7 +273,7 @@ abstract class SentryTelemetryService :
)
} else {
return SentryTelemetryServiceParams(
extension.telemetry.get(),
isTelemetryEnabled,
extension.telemetryDsn.get(),
org,
buildType,
Expand Down Expand Up @@ -314,13 +318,7 @@ abstract class SentryTelemetryService :
val versionOutput =
project.providers.of(SentryCliVersionValueSource::class.java) { cliVS ->
cliVS.parameters.cliExecutable.set(cliExecutable)
cliVS.parameters.authToken.set(extension.authToken)
cliVS.parameters.url.set(extension.url)
variant?.let { v ->
cliVS.parameters.propertiesFilePath.set(
SentryPropertiesFileProvider.getPropertiesFilePath(project, v)
)
}
}.get()

versionRegex.find(versionOutput)?.let { matchResult ->
Expand Down Expand Up @@ -448,8 +446,8 @@ class SentryMinimalException(message: String) : RuntimeException(message) {
}
}

abstract class SentryCliInfoValueSource : ValueSource<String, Params> {
interface Params : ValueSourceParameters {
abstract class SentryCliInfoValueSource : ValueSource<String, InfoParams> {
interface InfoParams : ValueSourceParameters {
@get:Input
val cliExecutable: Property<String>

Expand Down Expand Up @@ -477,6 +475,7 @@ abstract class SentryCliInfoValueSource : ValueSource<String, Params> {
args.add(url)
}

args.add("--log-level=error")
args.add("info")

parameters.propertiesFilePath.orNull?.let { path ->
Expand All @@ -494,19 +493,13 @@ abstract class SentryCliInfoValueSource : ValueSource<String, Params> {
}
}

abstract class SentryCliVersionValueSource : ValueSource<String, Params> {
interface Params : ValueSourceParameters {
abstract class SentryCliVersionValueSource : ValueSource<String, VersionParams> {
interface VersionParams : ValueSourceParameters {
@get:Input
val cliExecutable: Property<String>

@get:Input
val propertiesFilePath: Property<String>

@get:Input
val url: Property<String>

@get:Input
val authToken: Property<String>
}

@get:Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ abstract class BaseSentryNonAndroidPluginTest(
// unlock transforms because we're running tests in parallel therefore they may conflict
print(providers.exec {
commandLine 'find', project.gradle.gradleUserHomeDir, '-type', 'f', '-name', 'transforms-3.lock', '-delete'
ignoreExitValue true
}.standardOutput.asText.get())
} else {
tasks.register('unlockTransforms', Exec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ abstract class BaseSentryPluginTest(
// unlock transforms because we're running tests in parallel therefore they may conflict
print(providers.exec {
commandLine 'find', project.gradle.gradleUserHomeDir, '-type', 'f', '-name', 'transforms-3.lock', '-delete'
ignoreExitValue true
}.standardOutput.asText.get())
} else {
tasks.register('unlockTransforms', Exec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SentryPluginConfigurationCacheTest :
autoUploadProguardMapping = false
autoInstallation.enabled = false
includeDependenciesReport = false
telemetry = false
telemetry = true
}
""".trimIndent()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,73 @@
package io.sentry.android.gradle.integration

// import kotlin.test.Test
// import kotlin.test.assertTrue
// import org.gradle.util.GradleVersion
//
// class SentryPluginNonAndroidTest :
// BaseSentryNonAndroidPluginTest(GradleVersion.current().version) {
//
// @Test
// fun `telemetry can be disabled`() {
// appBuildFile.writeText(
// // language=Groovy
// """
// plugins {
// id "java"
// id "io.sentry.jvm.gradle"
// }
//
// dependencies {
// implementation 'org.springframework.boot:spring-boot-starter:3.0.0'
// implementation 'ch.qos.logback:logback-classic:1.0.0'
// implementation 'org.apache.logging.log4j:log4j-api:2.0'
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2'
// implementation 'org.postgresql:postgresql:42.6.0'
// implementation 'com.graphql-java:graphql-java:17.3'
// }
//
// sentry {
// telemetry = false
// }
// """.trimIndent()
// )
//
// val result = runner
// .appendArguments("app:assemble", "--debug")
// .build()
//
// assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
// assertTrue(result.output) { "Sentry telemetry has been disabled." in result.output }
// }
//
// @Test
// fun `telemetry is enabled by default`() {
// appBuildFile.writeText(
// // language=Groovy
// """
// plugins {
// id "java"
// id "io.sentry.jvm.gradle"
// }
//
// dependencies {
// implementation 'org.springframework.boot:spring-boot-starter:3.0.0'
// implementation 'ch.qos.logback:logback-classic:1.0.0'
// implementation 'org.apache.logging.log4j:log4j-api:2.0'
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2'
// implementation 'org.postgresql:postgresql:42.6.0'
// implementation 'com.graphql-java:graphql-java:17.3'
// }
// """.trimIndent()
// )
//
// val result = runner
// .appendArguments("app:assemble", "--info")
// .build()
//
// assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
// assertTrue(result.output) { "Sentry telemetry is enabled." in result.output }
// }
// }
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import org.gradle.util.GradleVersion

class SentryPluginNonAndroidTest :
BaseSentryNonAndroidPluginTest(GradleVersion.current().version) {

@Test
fun `telemetry can be disabled`() {
appBuildFile.writeText(
// language=Groovy
"""
plugins {
id "java"
id "io.sentry.jvm.gradle"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter:3.0.0'
implementation 'ch.qos.logback:logback-classic:1.0.0'
implementation 'org.apache.logging.log4j:log4j-api:2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2'
implementation 'org.postgresql:postgresql:42.6.0'
implementation 'com.graphql-java:graphql-java:17.3'
}
sentry {
telemetry = false
}
""".trimIndent()
)

val result = runner
.appendArguments("app:assemble", "--info")
.build()

assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
assertTrue(result.output) { "Sentry telemetry has been disabled." in result.output }
assertFalse(result.output) { "sentry-cli" in result.output }
}

@Test
fun `telemetry is enabled by default`() {
appBuildFile.writeText(
// language=Groovy
"""
plugins {
id "java"
id "io.sentry.jvm.gradle"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter:3.0.0'
implementation 'ch.qos.logback:logback-classic:1.0.0'
implementation 'org.apache.logging.log4j:log4j-api:2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2'
implementation 'org.postgresql:postgresql:42.6.0'
implementation 'com.graphql-java:graphql-java:17.3'
}
""".trimIndent()
)

val result = runner
.appendArguments("app:assemble", "--info")
.build()

assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
assertTrue(result.output) { "Sentry telemetry is enabled." in result.output }
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
package io.sentry.android.gradle.integration

// import io.sentry.BuildConfig
// import kotlin.test.Ignore
// import kotlin.test.Test
// import kotlin.test.assertTrue
// import org.gradle.util.GradleVersion
//
// class SentryPluginTelemetryTest :
// BaseSentryPluginTest(BuildConfig.AgpVersion, GradleVersion.current().version) {
//
// @Test
// fun `telemetry can be disabled`() {
// appBuildFile.appendText(
// // language=Groovy
// """
// sentry {
// telemetry = false
// }
// """.trimIndent()
// )
//
// val result = runner
// .appendArguments("app:assembleDebug", "--debug")
// .build()
//
// assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
// assertTrue(result.output) { "Sentry telemetry has been disabled." in result.output }
// }
//
// @Test
// fun `telemetry is enabled by default`() {
// val result = runner
// .appendArguments("app:assembleDebug", "--info")
// .build()
//
// assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
// assertTrue(result.output) { "Sentry telemetry is enabled." in result.output }
// }
// }
import io.sentry.BuildConfig
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import org.gradle.util.GradleVersion

class SentryPluginTelemetryTest :
BaseSentryPluginTest(BuildConfig.AgpVersion, GradleVersion.current().version) {

@Test
fun `telemetry can be disabled`() {
appBuildFile.appendText(
// language=Groovy
"""
sentry {
telemetry = false
}
""".trimIndent()
)

val result = runner
.appendArguments("app:assembleDebug", "--info")
.build()

assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
assertTrue(result.output) { "Sentry telemetry has been disabled." in result.output }
assertFalse(result.output) { "sentry-cli" in result.output }
}

@Test
fun `telemetry is enabled by default`() {
appBuildFile.writeText(
// language=Groovy
"""
plugins {
id "com.android.application"
id "io.sentry.android.gradle"
}
android {
namespace 'com.example'
}
""".trimIndent()
)
val result = runner
.appendArguments("app:assembleDebug", "--info")
.build()

assertTrue(result.output) { "BUILD SUCCESSFUL" in result.output }
assertTrue(result.output) { "Sentry telemetry is enabled." in result.output }
}
}

0 comments on commit afa92e8

Please sign in to comment.