diff --git a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/sentry/SentryContext.kt b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/sentry/SentryContext.kt index ef6e18d6da..a1ab86072e 100644 --- a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/sentry/SentryContext.kt +++ b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/sentry/SentryContext.kt @@ -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 = mapOf(), + scopeBody: (IScope) -> Unit = {}, body: suspend SentryScopeCapture.() -> Unit, ): SentryId? { val capture = SentryScopeCapture() @@ -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) } @@ -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 = mapOf(), + scopeBody: (IScope) -> Unit = {}, body: suspend (SentryExceptionCapture).() -> Unit, ): SentryId? { val capture = SentryExceptionCapture(t) @@ -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() } @@ -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 = mapOf(), + scopeBody: (IScope) -> Unit = {}, body: suspend SentryScopeCapture.() -> Unit, ) { val capture = SentryScopeCapture() @@ -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) } } @@ -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 = mapOf(), + scopeBody: (IScope) -> Unit = {}, body: suspend SentryScopeCapture.() -> Unit, ): SentryId? { val capture = SentryScopeCapture() @@ -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) }