Comments (1)
Please also provide withTrace
and withSpan
kotlin extensions which make it easy to instrument code with an concise and kotin idomatic syntax. These extensions should also support kotlin coroutines and propagate context in coroutines correctly. I started an implementation my self, here is what I did sofar:
data class SpanContext(val span: Span) : AbstractCoroutineContextElement(SpanContext) {
companion object Key : CoroutineContext.Key<SpanContext>
}
fun CoroutineContext.currentSpan(): Span {
return get(SpanContext)?.span ?: throw IllegalStateException("No active Span in context")
}
suspend fun <T> withTrace(
name: String,
spanName: String,
block: suspend CoroutineScope.() -> T
): T {
val trace = startTrace(name, spanName)
return withSpan(trace, block)
}
suspend fun <T> withSpan(name: String, block: suspend CoroutineScope.() -> T): T {
val span = currentCoroutineContext().currentSpan()
val childSpan = span.startChild(name)
return withSpan(childSpan, block)
}
suspend fun <T> withSpan(span: Span, block: suspend CoroutineScope.() -> T): T {
return try {
withContext(SpanContext(span), block)
} catch (e: Throwable) {
if (e is CancellationException) {
span.setStatus("cancelled")
} else {
span.setThrowable(e)
span.setStatus("error")
}
throw e
} finally {
span.finish()
}
}
This allows to add the context to the coroutine context, which ensures it is propagates in suspend code with structured concurrency. This means the child span must no be propagated manually. The extension functions allow to instrument code as follows:
suspend fun getData(): String {
return withSpan("getData") {
delay(1000)
"foo"
}
}
from sentry-kotlin-multiplatform.
Related Issues (20)
- Does My iOS KMM Library Need to Be Static For dSYM to Work Properly? HOT 7
- Performance monitoring support in Ktor Client
- [Gradle Plugin] Add support for creating a dynamic library when using SPM and Cocoapods (not kotlin cocoapods) HOT 1
- Issue When Archiving Build for Apple App Store Release HOT 2
- Add getting started docs (onboarding docs, onboarding wizard) for KMP HOT 1
- Streamline and align the "Getting Started" docs to fit in the new structure HOT 1
- Avoid needing the Android Context in Sentry.init(..) common code HOT 1
- Add Codecov
- Regular framework support (use without CocoaPods) HOT 10
- support sentry-cocoa v8.8.0 HOT 4
- java.util.UnknownFormatConversionException: Conversion = ';' HOT 1
- IOS crash while handling event HOT 3
- Filename guidelines to expect/actual and platform specific implementations HOT 3
- Automatically disable `io.sentry.auto-init`
- Remove docs from github and refer to sentry-docs as source of truth HOT 2
- Enable minification, obfuscation with Proguard on Android release builds HOT 2
- Compilation failed: linking globals named when integrate sentry multiplatform HOT 10
- Set up repo and project HOT 2
- beforeSend is not called for Fatal Exceptions on Android HOT 11
- Breadcrumbs Don't Seem to Work Right on iOS HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentry-kotlin-multiplatform.