File tree Expand file tree Collapse file tree 7 files changed +84
-1
lines changed
sentry-kotlin-multiplatform/src
commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions
commonMain/kotlin/io/sentry/kotlin/multiplatform
commonMain/kotlin/sample.kmp.app
iosMain/kotlin/sample.kmp.app Expand file tree Collapse file tree 7 files changed +84
-1
lines changed Original file line number Diff line number Diff line change 44
55### Features
66
7- - Improve Objc/Swift experience with @HiddenFromObjc ([ #62 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/62 ) )
7+ - feat: configuring http client errors for Apple targets ([ #76 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/76 ) )
8+ - feat: improve Objc/Swift experience with @HiddenFromObjc ([ #62 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/62 ) )
89- feat: add view hierarchy ([ #53 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/53 ) )
910
1011### Fixes
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package io.sentry.kotlin.multiplatform.extensions
22
33import PrivateSentrySDKOnly.Sentry.PrivateSentrySDKOnly
44import cocoapods.Sentry.SentryEvent
5+ import cocoapods.Sentry.SentryHttpStatusCodeRange
56import io.sentry.kotlin.multiplatform.BuildKonfig
67import io.sentry.kotlin.multiplatform.CocoaSentryOptions
78import io.sentry.kotlin.multiplatform.SentryOptions
@@ -59,4 +60,13 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
5960 cocoaBreadcrumb?.toKmpBreadcrumb()
6061 ?.let { options.beforeBreadcrumb?.invoke(it) }?.toCocoaBreadcrumb()
6162 }
63+
64+ enableCaptureFailedRequests = options.enableCaptureFailedRequests
65+ failedRequestTargets = options.failedRequestTargets
66+ failedRequestStatusCodes = options.failedRequestStatusCodes.map {
67+ SentryHttpStatusCodeRange (
68+ min = it.min.convert(),
69+ max = it.max.convert()
70+ )
71+ }
6272}
Original file line number Diff line number Diff line change 1+ package io.sentry.kotlin.multiplatform
2+
3+ /* *
4+ * The Http status code range. Example for a range: 400 to 499, 500 to 599, 400 to 599 The range is
5+ * inclusive so the min and max is considered part of the range.
6+ *
7+ * Example for a single status code 400, 500
8+ */
9+ public data class HttpStatusCodeRange (val min : Int = DEFAULT_MIN , val max : Int = DEFAULT_MAX ) {
10+
11+ public constructor (statusCode: Int ) : this (statusCode, statusCode)
12+
13+ public fun isInRange (statusCode : Int ): Boolean {
14+ return statusCode in min.. max
15+ }
16+
17+ public companion object {
18+ public const val DEFAULT_MIN : Int = 500
19+ public const val DEFAULT_MAX : Int = 599
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -72,4 +72,28 @@ public open class SentryOptions {
7272 * This is only available on iOS and Android.
7373 */
7474 public var attachViewHierarchy: Boolean = false
75+
76+ /* *
77+ * Enables or disables the feature to automatically capture HTTP client errors.
78+ * This is enabled by default.
79+ *
80+ * Available on Apple.
81+ */
82+ public var enableCaptureFailedRequests: Boolean = true
83+
84+ /* *
85+ * A list of HTTP status code ranges indicating which client errors should be captured as errors.
86+ * By default, only HTTP client errors with a response code between 500 and 599 are captured as errors.
87+ *
88+ * Available on Apple.
89+ */
90+ public var failedRequestStatusCodes: List <HttpStatusCodeRange > = listOf (HttpStatusCodeRange ())
91+
92+ /* *
93+ * A list of HTTP request targets indicating which client errors should be captured as errors with either regex or a plain string.
94+ * By default, HTTP client errors from every target (.* regular expression) are automatically captured.
95+ *
96+ * Available on Apple.
97+ */
98+ public var failedRequestTargets: List <String > = listOf (" .*" )
7599}
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ struct ContentView: View {
1111 Button ( " Capture Exception " ) {
1212 LoginImpl ( ) . login ( username: " MyUsername " )
1313 }
14+ Button ( " Capture Http Client Error " ) {
15+ HttpClientKt . captureHttpClientError ( )
16+ }
1417 Button ( " Hard Crash " ) {
1518 LoginImpl ( ) . login ( username: nil )
1619 }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package sample.kmp.app
22
33import io.sentry.kotlin.multiplatform.Attachment
44import io.sentry.kotlin.multiplatform.Context
5+ import io.sentry.kotlin.multiplatform.HttpStatusCodeRange
56import io.sentry.kotlin.multiplatform.OptionsConfiguration
67import io.sentry.kotlin.multiplatform.Sentry
78
@@ -45,6 +46,8 @@ private fun optionsConfiguration(): OptionsConfiguration {
4546 it.attachScreenshot = true
4647 it.attachViewHierarchy = true
474849+ it.failedRequestStatusCodes = listOf (HttpStatusCodeRange (400 , 599 ))
50+ it.failedRequestTargets = listOf (" httpbin.org" )
4851 it.beforeBreadcrumb = { breadcrumb ->
4952 breadcrumb.message = " Add message before every breadcrumb"
5053 breadcrumb
Original file line number Diff line number Diff line change 1+ package sample.kmp.app
2+
3+ import platform.Foundation.NSURL
4+ import platform.Foundation.NSURLRequest
5+ import platform.Foundation.NSURLSession
6+ import platform.Foundation.dataTaskWithRequest
7+
8+ @Suppress(" Unused" ) // Called from Swift
9+ fun captureHttpClientError () {
10+ val url = NSURL (string = " https://httpbin.org/status/404" )
11+ val request = NSURLRequest (uRL = url)
12+ NSURLSession .sharedSession.dataTaskWithRequest(request) { data, response, error ->
13+ if (error != null ) {
14+ // handle error
15+ println (" error: $error " )
16+ } else {
17+ // handle successful response
18+ println (" response: $response " )
19+ }
20+ }.resume()
21+ }
You can’t perform that action at this time.
0 commit comments