Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sentry-android-timber package sets sentry.java.android.timber as SDK name #1456

Merged
merged 4 commits into from
May 3, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions sentry-android-timber/api/sentry-android-timber.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()V
}
Expand Down
1 change: 1 addition & 0 deletions sentry-android-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SentryTimberIntegrationTest {
private class Fixture {
val hub = mock<IHub>()
val options = SentryOptions().apply {
sdkVersion = SdkVersion()
sdkVersion = SdkVersion("test", "1.2.3")
}

fun getSut(
Expand Down Expand Up @@ -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)
}
}