You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would allow developers to create custom transactions and spans in their code to capture information about their application's performance and behavior.
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 classSpanContext(valspan:Span) : AbstractCoroutineContextElement(SpanContext) {
companionobject Key : CoroutineContext.Key<SpanContext>
}
fun CoroutineContext.currentSpan(): Span {
return get(SpanContext)?.span ?:throwIllegalStateException("No active Span in context")
}
suspendfun <T> withTrace(
name:String,
spanName:String,
block:suspendCoroutineScope.() ->T
): T {
val trace = startTrace(name, spanName)
return withSpan(trace, block)
}
suspendfun <T> withSpan(name:String, block:suspendCoroutineScope.() ->T): T {
val span = currentCoroutineContext().currentSpan()
val childSpan = span.startChild(name)
return withSpan(childSpan, block)
}
suspendfun <T> withSpan(span:Span, block:suspendCoroutineScope.() ->T): T {
returntry {
withContext(SpanContext(span), block)
} catch (e:Throwable) {
if (e isCancellationException) {
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:
This would allow developers to create custom transactions and spans in their code to capture information about their application's performance and behavior.
At the very least support:
Transaction
Span
startTransaction()
startChild()
getSpan()
tracesSampleRate
optiontracesSampler
optionAlign implementation with:
Blocked by
The text was updated successfully, but these errors were encountered: