From 2a966a4044a05d561abfc585a3fd6a6f57135ac2 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 3 May 2021 17:10:01 +0200 Subject: [PATCH] Fix: sentry-android-timber package sets sentry.java.android.timber as SDK name (#1456) --- CHANGELOG.md | 2 ++ buildSrc/src/main/java/Config.kt | 1 + .../api/sentry-android-timber.api | 1 + sentry-android-timber/build.gradle.kts | 1 + .../android/timber/SentryTimberIntegration.kt | 16 +++++++++++++--- .../timber/SentryTimberIntegrationTest.kt | 13 ++++++++++++- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02af71e6db..869c1a0472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +* Fix: sentry-android-timber package sets sentry.java.android.timber as SDK name (#1456) + Breaking Changes: * Remove: Settings.Secure.ANDROID_ID in favor of generated installationId (#1455) diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index 590ec12032..b1859dc887 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -125,6 +125,7 @@ object Config { object Sentry { val SENTRY_JAVA_SDK_NAME = "sentry.java" val SENTRY_ANDROID_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.android" + val SENTRY_TIMBER_SDK_NAME = "$SENTRY_ANDROID_SDK_NAME.timber" val SENTRY_LOGBACK_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.logback" val SENTRY_JUL_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.jul" val SENTRY_LOG4J2_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.log4j2" diff --git a/sentry-android-timber/api/sentry-android-timber.api b/sentry-android-timber/api/sentry-android-timber.api index 24993f4e30..def2854341 100644 --- a/sentry-android-timber/api/sentry-android-timber.api +++ b/sentry-android-timber/api/sentry-android-timber.api @@ -2,6 +2,7 @@ public final class io/sentry/android/timber/BuildConfig { public static final field BUILD_TYPE Ljava/lang/String; public static final field DEBUG Z public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; + public static final field SENTRY_TIMBER_SDK_NAME Ljava/lang/String; public static final field VERSION_NAME Ljava/lang/String; public fun ()V } diff --git a/sentry-android-timber/build.gradle.kts b/sentry-android-timber/build.gradle.kts index 07d1e698d0..1ed0869c00 100644 --- a/sentry-android-timber/build.gradle.kts +++ b/sentry-android-timber/build.gradle.kts @@ -25,6 +25,7 @@ android { // for AGP 4.1 buildConfigField("String", "VERSION_NAME", "\"$versionName\"") + buildConfigField("String", "SENTRY_TIMBER_SDK_NAME", "\"${Config.Sentry.SENTRY_TIMBER_SDK_NAME}\"") } buildTypes { diff --git a/sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberIntegration.kt b/sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberIntegration.kt index 4ffd67f1ff..10782e3c9d 100644 --- a/sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberIntegration.kt +++ b/sentry-android-timber/src/main/java/io/sentry/android/timber/SentryTimberIntegration.kt @@ -5,6 +5,8 @@ import io.sentry.ILogger import io.sentry.Integration import io.sentry.SentryLevel import io.sentry.SentryOptions +import io.sentry.android.timber.BuildConfig.SENTRY_TIMBER_SDK_NAME +import io.sentry.android.timber.BuildConfig.VERSION_NAME import io.sentry.protocol.SdkVersion import java.io.Closeable import timber.log.Timber @@ -20,7 +22,7 @@ class SentryTimberIntegration( private lateinit var logger: ILogger override fun register(hub: IHub, options: SentryOptions) { - addPackage(options.sdkVersion) + createSdkVersion(options) logger = options.logger tree = SentryTimberTree(hub, minEventLevel, minBreadcrumbLevel) @@ -39,7 +41,15 @@ class SentryTimberIntegration( } } - private fun addPackage(sdkVersion: SdkVersion?) { - sdkVersion?.addPackage("maven:io.sentry:sentry-android-timber", BuildConfig.VERSION_NAME) + private fun createSdkVersion(options: SentryOptions): SdkVersion { + var sdkVersion = options.sdkVersion + + val name = SENTRY_TIMBER_SDK_NAME + val version = VERSION_NAME + sdkVersion = SdkVersion.updateSdkVersion(sdkVersion, name, version) + + sdkVersion.addPackage("maven:io.sentry:sentry-android-timber", VERSION_NAME) + + return sdkVersion } } diff --git a/sentry-android-timber/src/test/java/io/sentry/android/timber/SentryTimberIntegrationTest.kt b/sentry-android-timber/src/test/java/io/sentry/android/timber/SentryTimberIntegrationTest.kt index 87fe958522..19c75ab7ba 100644 --- a/sentry-android-timber/src/test/java/io/sentry/android/timber/SentryTimberIntegrationTest.kt +++ b/sentry-android-timber/src/test/java/io/sentry/android/timber/SentryTimberIntegrationTest.kt @@ -18,7 +18,7 @@ class SentryTimberIntegrationTest { private class Fixture { val hub = mock() val options = SentryOptions().apply { - sdkVersion = SdkVersion() + sdkVersion = SdkVersion("test", "1.2.3") } fun getSut( @@ -96,4 +96,15 @@ class SentryTimberIntegrationTest { it.version == BuildConfig.VERSION_NAME }) } + + @Test + fun `Integration sets SDK name and version to options`() { + val sut = fixture.getSut() + sut.register(fixture.hub, fixture.options) + + val sdkVersion = fixture.options.sdkVersion!! + + assertEquals(sdkVersion.name, "sentry.java.android.timber") + assertEquals(sdkVersion.version, BuildConfig.VERSION_NAME) + } }