TraceSink

Port that receives TraceEvents. Backends (logging, ring buffers, platform tracers) implement it.

Contract every sink must follow:

  1. emit must not throw; callers also catch and drop, so a faulty sink never breaks dispatch.

  2. emit must be cheap and must not suspend or block; heavy work goes behind the sink's own buffer.

  3. emit can be called concurrently from many threads.

  4. Ordering is guaranteed per thread only, not globally. Correlate the three lifecycle events of one dispatched runnable by their non-zero dispatchId, not by adjacency or span id.

  5. A sink may ignore unknown event subtypes (new ones can be added in later releases).

isEnabled is consulted before an event is built, so a disabled level costs no allocation.

Example:

val sink = TraceSink { event -> println(event) }

Requires opting in to ExperimentalStructuredCoroutines.

See also

Inheritors

Types

Link copied to clipboard
object Companion

Constants for TraceSink.

Functions

Link copied to clipboard
abstract fun emit(event: TraceEvent)

Receives one event. See the contract in the type documentation.

Link copied to clipboard
open fun isEnabled(level: TraceLevel): Boolean

Whether this sink wants events of level. Defaults to true for every level.