Skip to content

Commit 8ae5a45

Browse files
committed
feat: allow consumer to delegate release name creation to the SDK
BREAKING CHANGE: `CrashLoggingDataProvider#releaseName` changed its type from `String` to `ReleaseName`
1 parent 73ce786 commit 8ae5a45

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

AutomatticTracks/src/main/java/com/automattic/android/tracks/crashlogging/CrashLoggingDataProvider.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface CrashLoggingDataProvider {
1717
/**
1818
* Provides [CrashLogging] with the name of this release.
1919
*/
20-
val releaseName: String
20+
val releaseName: ReleaseName
2121

2222
/**
2323
* Provides the [CrashLogging] with information about the user's current locale
@@ -80,6 +80,20 @@ interface CrashLoggingDataProvider {
8080

8181
typealias ExtraKnownKey = String
8282

83+
sealed class ReleaseName {
84+
/**
85+
* Sets release name attached for every event sent to Sentry. It's indented to use in debug.
86+
*/
87+
class SetByApplication(val name: String) : ReleaseName()
88+
89+
/**
90+
* Delegates setting the release name to the Tracks library. It's indented to use in release
91+
* builds. The crash logging framework will single-handledly set the release name based on the
92+
* build configuration.
93+
*/
94+
object SetByTracksLibrary : ReleaseName()
95+
}
96+
8397
sealed class PerformanceMonitoringConfig {
8498
object Disabled : PerformanceMonitoringConfig()
8599

AutomatticTracks/src/main/java/com/automattic/android/tracks/crashlogging/internal/SentryCrashLogging.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.automattic.android.tracks.crashlogging.JsException
99
import com.automattic.android.tracks.crashlogging.JsExceptionCallback
1010
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Disabled
1111
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Enabled
12+
import com.automattic.android.tracks.crashlogging.ReleaseName
1213
import com.automattic.android.tracks.crashlogging.eventLevel
1314
import io.sentry.Breadcrumb
1415
import io.sentry.Sentry
@@ -44,7 +45,10 @@ internal class SentryCrashLogging constructor(
4445
options.apply {
4546
dsn = dataProvider.sentryDSN
4647
environment = dataProvider.buildType
47-
release = dataProvider.releaseName
48+
release = when (val releaseName = dataProvider.releaseName) {
49+
is ReleaseName.SetByApplication -> releaseName.name
50+
ReleaseName.SetByTracksLibrary -> null
51+
}
4852
this.tracesSampleRate = tracesSampleRate
4953
this.profilesSampleRate = profilesSampleRate
5054
isDebug = dataProvider.enableCrashLoggingLogs

AutomatticTracks/src/test/java/com/automattic/android/tracks/crashlogging/SentryCrashLoggingTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class SentryCrashLoggingTest {
8080
SoftAssertions().apply {
8181
assertThat(options.dsn).isEqualTo(dataProvider.sentryDSN)
8282
assertThat(options.environment).isEqualTo(dataProvider.buildType)
83-
assertThat(options.release).isEqualTo(dataProvider.releaseName)
83+
assertThat(options.release).isEqualTo((dataProvider.releaseName as ReleaseName.SetByApplication).name)
8484
}.assertAll()
8585
}
8686
}

AutomatticTracks/src/test/java/com/automattic/android/tracks/fakes/FakeDataProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import com.automattic.android.tracks.crashlogging.CrashLoggingUser
66
import com.automattic.android.tracks.crashlogging.EventLevel
77
import com.automattic.android.tracks.crashlogging.ExtraKnownKey
88
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig
9+
import com.automattic.android.tracks.crashlogging.ReleaseName
910
import kotlinx.coroutines.flow.Flow
1011
import kotlinx.coroutines.flow.MutableStateFlow
1112
import java.util.Locale
1213

1314
class FakeDataProvider(
1415
override val sentryDSN: String = BuildConfig.SENTRY_TEST_PROJECT_DSN,
1516
override val buildType: String = "testBuildType",
16-
override val releaseName: String = "testReleaseName",
17+
override val releaseName: ReleaseName = ReleaseName.SetByApplication("testReleaseName"),
1718
override val locale: Locale? = Locale.US,
1819
override val enableCrashLoggingLogs: Boolean = true,
1920
var crashLoggingEnabled: Boolean = true,

sampletracksapp/src/main/java/com/example/sampletracksapp/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.automattic.android.tracks.crashlogging.JsException
1313
import com.automattic.android.tracks.crashlogging.JsExceptionCallback
1414
import com.automattic.android.tracks.crashlogging.JsExceptionStackTraceElement
1515
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig
16+
import com.automattic.android.tracks.crashlogging.ReleaseName
1617
import com.automattic.android.tracks.crashlogging.RequestFormatter
1718
import com.automattic.android.tracks.crashlogging.performance.PerformanceMonitoringRepositoryProvider
1819
import com.automattic.android.tracks.crashlogging.performance.PerformanceTransactionRepository
@@ -41,7 +42,7 @@ class MainActivity : AppCompatActivity() {
4142
object : CrashLoggingDataProvider {
4243
override val sentryDSN = BuildConfig.SENTRY_TEST_PROJECT_DSN
4344
override val buildType = BuildConfig.BUILD_TYPE
44-
override val releaseName = "test"
45+
override val releaseName = ReleaseName.SetByApplication("test")
4546
override val locale = Locale.US
4647
override val enableCrashLoggingLogs = true
4748
override val performanceMonitoringConfig = PerformanceMonitoringConfig.Enabled(sampleRate = 1.0, profilesSampleRate = 1.0)

0 commit comments

Comments
 (0)