Skip to content

Commit

Permalink
Sentry: Extend capturing APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Feb 24, 2024
1 parent 35a1536 commit b31a8f2
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class SentryContext : KordExKoinComponent {
/** Capture a [SentryEvent], submitting it to Sentry with the breadcrumbs in this context. **/
public suspend fun captureEvent(
event: SentryEvent,
contexts: Map<String, Any> = mapOf(),
scopeBody: (IScope) -> Unit = {},
body: suspend SentryScopeCapture.() -> Unit,
): SentryId? {
val capture = SentryScopeCapture()
Expand All @@ -85,8 +87,11 @@ public class SentryContext : KordExKoinComponent {
Sentry.withScope {
capture.apply(it)

contexts.forEach { (key, value) -> it.setContexts(key, value) }
breadcrumbs.forEach(it::addBreadcrumb)

scopeBody(it)

id = Sentry.captureEvent(event)
}

Expand All @@ -101,6 +106,8 @@ public class SentryContext : KordExKoinComponent {
/** Capture a [Throwable] exception, submitting it to Sentry with the breadcrumbs in this context. **/
public suspend fun captureThrowable(
t: Throwable,
contexts: Map<String, Any> = mapOf(),
scopeBody: (IScope) -> Unit = {},
body: suspend (SentryExceptionCapture).() -> Unit,
): SentryId? {
val capture = SentryExceptionCapture(t)
Expand All @@ -115,8 +122,11 @@ public class SentryContext : KordExKoinComponent {
Sentry.withScope {
capture.apply(it)

contexts.forEach { (key, value) -> it.setContexts(key, value) }
breadcrumbs.forEach(it::addBreadcrumb)

scopeBody(it)

id = capture.captureThrowable()
}

Expand All @@ -131,6 +141,8 @@ public class SentryContext : KordExKoinComponent {
/** Capture a [UserFeedback] object, submitting it to Sentry with the breadcrumbs in this context. **/
public suspend fun captureFeedback(
feedback: UserFeedback,
contexts: Map<String, Any> = mapOf(),
scopeBody: (IScope) -> Unit = {},
body: suspend SentryScopeCapture.() -> Unit,
) {
val capture = SentryScopeCapture()
Expand All @@ -143,8 +155,11 @@ public class SentryContext : KordExKoinComponent {
Sentry.withScope {
capture.apply(it)

contexts.forEach { (key, value) -> it.setContexts(key, value) }
breadcrumbs.forEach(it::addBreadcrumb)

scopeBody(it)

Sentry.captureUserFeedback(feedback)
}
}
Expand All @@ -153,6 +168,8 @@ public class SentryContext : KordExKoinComponent {
/** Capture a [message] String, submitting it to Sentry with the breadcrumbs in this context. **/
public suspend fun captureMessage(
message: String,
contexts: Map<String, Any> = mapOf(),
scopeBody: (IScope) -> Unit = {},
body: suspend SentryScopeCapture.() -> Unit,
): SentryId? {
val capture = SentryScopeCapture()
Expand All @@ -167,8 +184,11 @@ public class SentryContext : KordExKoinComponent {
Sentry.withScope {
capture.apply(it)

contexts.forEach { (key, value) -> it.setContexts(key, value) }
breadcrumbs.forEach(it::addBreadcrumb)

scopeBody(it)

id = Sentry.captureMessage(message)
}

Expand Down

0 comments on commit b31a8f2

Please sign in to comment.