TraceContext

class TraceContext(val traceId: String, val spanId: String) : AbstractCoroutineContextElement

The ids of a span in the coroutine context. An OtlpObserver puts one in the context of each node, with the span of the node. Read it with currentCoroutineContext()[TraceContext], for example to log the trace id next to a message, or let the Traceparent plugin send it with each request.

The app can put one around a run too, and the OtlpObserver records the run inside that span. A server continues the trace of the request that started the run:

val trace = TraceContext.parse(call.request.headers["traceparent"])
withContext(trace ?: EmptyCoroutineContext) { graph.invoke(ticket, config) }

A run started inside a node traced by an OtlpObserver, such as a graph that a tool runs, is in the span of that node without anything more.

Throws

if traceId or spanId is not such an id.

Constructors

Link copied to clipboard
constructor(traceId: String, spanId: String)

Types

Link copied to clipboard

The key of TraceContext in a coroutine context.

Properties

Link copied to clipboard
open override val key: CoroutineContext.Key<*>
Link copied to clipboard

the id of the span, 16 lowercase hex digits, not all zero.

Link copied to clipboard

the id of the trace, 32 lowercase hex digits, not all zero.

Link copied to clipboard

The ids as the traceparent header of W3C Trace Context.

Functions

Link copied to clipboard
open override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R
Link copied to clipboard
open operator override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E?
Link copied to clipboard
open override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext
Link copied to clipboard
open operator fun plus(context: CoroutineContext): CoroutineContext
Link copied to clipboard
open override fun toString(): String