withSpan

inline fun <T> withSpan(name: String, attributes: Map<String, Any?> = emptyMap(), block: (Span) -> T): T(source)

Executes the given block within a manually created tracing span.

This function provides a convenient API for manual tracing, handling span creation, activation, and closing (including in the presence of exceptions).

It is especially useful when annotation-based tracing is not available, such as in Java code, or when fine-grained control over tracing is needed.

Return

the result of block

Parameters

name

the name of the created span

attributes

optional attributes to attach to the span

block

the code to execute within the span's context