-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSentrySetup.kt
63 lines (58 loc) · 2.06 KB
/
SentrySetup.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package sample.kmp.app
import io.sentry.kotlin.multiplatform.Attachment
import io.sentry.kotlin.multiplatform.HttpStatusCodeRange
import io.sentry.kotlin.multiplatform.OptionsConfiguration
import io.sentry.kotlin.multiplatform.PlatformOptionsConfiguration
import io.sentry.kotlin.multiplatform.Sentry
/** Configure scope applicable to all platforms */
fun configureSentryScope() {
Sentry.configureScope {
it.setContext("Custom Context", "Shared Context")
it.setTag("custom-tag", "from shared code")
it.addAttachment(
Attachment(
"This is a shared text attachment".encodeToByteArray(),
"shared.log"
)
)
}
}
/**
* Initializes Sentry with given options.
* Make sure to hook this into your native platforms as early as possible
*/
fun initializeSentry(useNativeOptions: Boolean = false) {
if (useNativeOptions) {
Sentry.initWithPlatformOptions(createPlatformOptionsConfiguration())
} else {
Sentry.init(optionsConfiguration())
}
}
expect fun createPlatformOptionsConfiguration(): PlatformOptionsConfiguration
/** Returns a shared options configuration */
private fun optionsConfiguration(): OptionsConfiguration {
return {
it.dsn = "https://[email protected]/5903800"
it.attachStackTrace = true
it.attachThreads = true
it.attachScreenshot = true
it.attachViewHierarchy = true
it.release = "[email protected]"
it.debug = true
it.failedRequestStatusCodes = listOf(HttpStatusCodeRange(400, 599))
it.failedRequestTargets = listOf("httpbin.org")
it.sessionReplay.onErrorSampleRate = 1.0
it.sessionReplay.sessionSampleRate = 1.0
it.beforeBreadcrumb = { breadcrumb ->
breadcrumb.message = "Add message before every breadcrumb"
breadcrumb
}
it.beforeSend = { event ->
if (event.environment == "test") {
null
} else {
event
}
}
}
}