Skip to content

Commit

Permalink
Merge pull request #206 from Automattic/allow-sentry-created-release-…
Browse files Browse the repository at this point in the history
…name

Allow consumers to delegate release name creation to the SDK
  • Loading branch information
wzieba authored Mar 27, 2024
2 parents c4ca5e6 + 3c5b60a commit 8818219
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface CrashLoggingDataProvider {
/**
* Provides [CrashLogging] with the name of this release.
*/
val releaseName: String
val releaseName: ReleaseName

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

typealias ExtraKnownKey = String

sealed class ReleaseName {
/**
* Sets release name attached for every event sent to Sentry. It's indented to use in debug.
*/
class SetByApplication(val name: String) : ReleaseName()

/**
* Delegates setting the release name to the Tracks library. It's indented to use in release
* builds. The crash logging framework will single-handledly set the release name based on the
* build configuration.
*/
object SetByTracksLibrary : ReleaseName()
}

sealed class PerformanceMonitoringConfig {
object Disabled : PerformanceMonitoringConfig()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.automattic.android.tracks.crashlogging.JsException
import com.automattic.android.tracks.crashlogging.JsExceptionCallback
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Disabled
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Enabled
import com.automattic.android.tracks.crashlogging.ReleaseName
import com.automattic.android.tracks.crashlogging.eventLevel
import io.sentry.Breadcrumb
import io.sentry.Sentry
Expand Down Expand Up @@ -44,7 +45,10 @@ internal class SentryCrashLogging constructor(
options.apply {
dsn = dataProvider.sentryDSN
environment = dataProvider.buildType
release = dataProvider.releaseName
release = when (val releaseName = dataProvider.releaseName) {
is ReleaseName.SetByApplication -> releaseName.name
ReleaseName.SetByTracksLibrary -> null
}
this.tracesSampleRate = tracesSampleRate
this.profilesSampleRate = profilesSampleRate
isDebug = dataProvider.enableCrashLoggingLogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SentryCrashLoggingTest {
SoftAssertions().apply {
assertThat(options.dsn).isEqualTo(dataProvider.sentryDSN)
assertThat(options.environment).isEqualTo(dataProvider.buildType)
assertThat(options.release).isEqualTo(dataProvider.releaseName)
assertThat(options.release).isEqualTo((dataProvider.releaseName as ReleaseName.SetByApplication).name)
}.assertAll()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import com.automattic.android.tracks.crashlogging.CrashLoggingUser
import com.automattic.android.tracks.crashlogging.EventLevel
import com.automattic.android.tracks.crashlogging.ExtraKnownKey
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig
import com.automattic.android.tracks.crashlogging.ReleaseName
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import java.util.Locale

class FakeDataProvider(
override val sentryDSN: String = BuildConfig.SENTRY_TEST_PROJECT_DSN,
override val buildType: String = "testBuildType",
override val releaseName: String = "testReleaseName",
override val releaseName: ReleaseName = ReleaseName.SetByApplication("testReleaseName"),
override val locale: Locale? = Locale.US,
override val enableCrashLoggingLogs: Boolean = true,
var crashLoggingEnabled: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.automattic.android.tracks.crashlogging.JsException
import com.automattic.android.tracks.crashlogging.JsExceptionCallback
import com.automattic.android.tracks.crashlogging.JsExceptionStackTraceElement
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig
import com.automattic.android.tracks.crashlogging.ReleaseName
import com.automattic.android.tracks.crashlogging.RequestFormatter
import com.automattic.android.tracks.crashlogging.performance.PerformanceMonitoringRepositoryProvider
import com.automattic.android.tracks.crashlogging.performance.PerformanceTransactionRepository
Expand Down Expand Up @@ -41,7 +42,7 @@ class MainActivity : AppCompatActivity() {
object : CrashLoggingDataProvider {
override val sentryDSN = BuildConfig.SENTRY_TEST_PROJECT_DSN
override val buildType = BuildConfig.BUILD_TYPE
override val releaseName = "test"
override val releaseName = ReleaseName.SetByApplication("test")
override val locale = Locale.US
override val enableCrashLoggingLogs = true
override val performanceMonitoringConfig = PerformanceMonitoringConfig.Enabled(sampleRate = 1.0, profilesSampleRate = 1.0)
Expand Down

0 comments on commit 8818219

Please sign in to comment.