io.sentry.kotlin.SentryContext.kt Maven / Gradle / Ivy
package io.sentry.kotlin
import io.sentry.IHub
import io.sentry.Sentry
import kotlinx.coroutines.ThreadContextElement
import kotlin.coroutines.AbstractCoroutineContextElement
import kotlin.coroutines.CoroutineContext
/**
* Sentry context element for [CoroutineContext].
*/
public class SentryContext : ThreadContextElement, AbstractCoroutineContextElement(Key) {
private companion object Key : CoroutineContext.Key
private val hub: IHub = Sentry.getCurrentHub().clone()
override fun updateThreadContext(context: CoroutineContext): IHub {
val oldState = Sentry.getCurrentHub()
Sentry.setCurrentHub(hub)
return oldState
}
override fun restoreThreadContext(context: CoroutineContext, oldState: IHub) {
Sentry.setCurrentHub(oldState)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy