TraceIrTransformer
Rewrites the body of every function annotated with io.github.smyrgeorge.log4k.annotation.Traced so that it is executed inside a new tracing span.
The span's parent (and the tracer that creates it) is resolved from what is in scope, in order:
a
TracingContextparameter/receiver — the new span nests under its current span (as before);otherwise a
TracingEvent.Spanparameter/receiver — used directly as the parent;otherwise a
trace: Tracermember (else the class's singleTracer-typed property, whatever its name) — reused, or synthesized asprivate val _trace_ = Tracer.of(this::class)— which creates a new root span.
Given:
@Traced(name = "load")
context(_: TracingContext)
suspend fun load(id: Long): User { /* body */}the body is replaced with (conceptually):
suspend fun load(id: Long): User =
TracingContext.traced(context = ctx, parent = null, tracer = null, "load") { /* body */}TracingContext.traced is inline, so both regular and suspend functions work: the moved body is placed in an inline lambda and therefore keeps its original suspension context.