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

Allow consumers to delegate release name creation to the SDK #206

Merged
merged 4 commits into from
Mar 27, 2024
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
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
Loading