trace
inline fun <T> OpenTelemetryClient.trace(name: String, kind: String = SpanKind.INTERNAL, attributes: Map<String, Any> = emptyMap(), block: () -> T): T
Times block and records it as a span: SpanStatus.OK on success, SpanStatus.ERROR (with ERROR_TYPE_ATTRIBUTE) when it throws. Cancellation is recorded as SpanStatus.UNSET, since a cancelled operation did not fail. The exception is always rethrown. Sink failures are ignored so recording cannot change the result or replace the original exception. The inline block also supports suspending calls from a coroutine.
val lessons = telemetry.trace("load_lessons", SpanKind.CLIENT, mapOf("course" to courseId)) {
api.fetchLessons(courseId)
}Content copied to clipboard