withNewScope

inline fun <T> Tracer.withNewScope(span: Span, crossinline f: () -> T): T

Instruments a function f with a new scope. This is helpful if you need to create a new Scope for an existing Span, for example, if you are switching threads (since Scopes are not thread-safe).

tracer.traceWithSpan("thread-switching-span") {
...
thread {
tracer.withNewScope(span) { ... }
}
}