with Trace Span
Runs block inside a new TraceSpan named name. Its parent is the span already in the current context, or none (a root span) when there is no span.
Example:
withTraceSpan("load-profile") { api.loadProfile(userId) }Content copied to clipboard
The span applies through withContext, so it is inherited by coroutines launched from block and ends when block returns. Cancellation and exceptions from block propagate unchanged.
Requires opting in to ExperimentalStructuredCoroutines.
Return
the value returned by block.
Parameters
name
low-cardinality label of the span.
block
the work to run inside the span.