Skip to content

Span

interface Span

A span represents a period of time during which an event is taking place.

Properties

parent

abstract val parent: Span?

The parent of this span.

If this span has no parent, this method returns null.

Implementations are not required to support this method. If they don't, this method should return null.

Functions

debug

inline fun Span.debug(values: SentierValues = SentierValues.Empty, message: () -> String)

Logs an event at level LogLevel.Debug in this span.

error

inline fun Span.error(values: SentierValues = SentierValues.Empty, message: () -> String)

Logs an event at level LogLevel.Error in this span.

fatal

inline fun Span.fatal(values: SentierValues = SentierValues.Empty, message: () -> String)

Logs an event at level LogLevel.Fatal in this span.

forceEnd

abstract fun forceEnd(values: SentierValues)

Logs the end of an event.

This method should be called on every span created by forceStart.

Example

val createUserSpan = span.forceStart(
    SentierValues
        .with(Message) { "Creating user…" }
        .with(EventTime.Start) { Clock.System.now() }
)

// …do the work of creating the user…

createUserSpan.forceEnd(
    SentierValues
        .with(EventTime.End) { Clock.System.now() }
)

forceEvent

abstract fun forceEvent(values: SentierValues)

Log an atomic event.

Example

span.forceEvent(
    SentierValues
        .with(Message) { "Hello, world!" }
        .with(EventTime) { Clock.System.now() }
)

forceStart

abstract fun forceStart(values: SentierValues): Span

Logs the start of an event.

Because the event is expected to take some time before it ends, a new Span instance is returned. Once the event is finished, the returned Span instance should be finalized using forceEnd.

Example

val createUserSpan = span.forceStart(
    SentierValues
        .with(Message) { "Creating user…" }
        .with(EventTime.Start) { Clock.System.now() }
)

// …do the work of creating the user…

createUserSpan.forceEnd(
    SentierValues
        .with(EventTime.End) { Clock.System.now() }
)

info

inline fun Span.info(values: SentierValues = SentierValues.Empty, message: () -> String)

Logs an event at level LogLevel.Info in this span.

log

inline fun Span.log(
    level: LogLevel = LogLevel.Info, 
    values: SentierValues = SentierValues.Empty, 
    message: () -> String
)

task

inline fun <T> Span.task(
    message: () -> String, 
    values: SentierValues = SentierValues.Empty, 
    block: context(Span) () -> T
): T

Tracks the progress of block in a child Span.

trace

inline fun Span.trace(values: SentierValues = SentierValues.Empty, message: () -> String)

Logs an event at level LogLevel.Trace in this span.

warn

inline fun Span.warn(values: SentierValues = SentierValues.Empty, message: () -> String)

Logs an event at level LogLevel.Warning in this span.