Telemetry

object Telemetry

Library-level telemetry: what the SDK did, how it ended, and how long it took.

Instrumentation used to stop at the HTTP boundary. A host running the embedded servers got spans, metrics and a request id, but the work underneath — resolving a DID, signing with a KMS, reading a wallet, verifying a credential — emitted nothing, so a failed verification could not be joined to a cause. This is the missing half.

It deliberately depends on nothing but the Kotlin standard library. The core modules must not acquire an OpenTelemetry or Ktor dependency because a host wants tracing; :observability bridges these events onto whatever the host actually runs.

Installing

Telemetry.install(sink)          // process-wide, typically once at startup

Nothing is recorded until a host installs a sink, and the default sink costs one volatile read per operation.

Correlating

A correlation id travels in the coroutine context, so a library event can be joined to the request that caused it without threading a parameter through every public signature:

withContext(TelemetryContext(requestId)) { credentialService.verify(credential) }

Functions

Link copied to clipboard

Replaces the process-wide sink. Returns the previous one so a host can restore it.

Link copied to clipboard

True when a host has installed something; lets hot paths skip building attributes.

Link copied to clipboard
suspend fun <T> measure(operation: Operation, attributes: Map<String, String> = emptyMap(), block: suspend () -> T): T

Times block, reports the outcome, and returns its result.

Link copied to clipboard
suspend fun rejected(operation: Operation, reason: String, attributes: Map<String, String> = emptyMap())

Reports an operation that completed normally but did not succeed — a verification that returned invalid, a resolution that returned a failure result. These never throw, so measure alone would record them as successes.

Link copied to clipboard

The installed sink. Callers normally use measure rather than this.

Link copied to clipboard

Restores the no-op sink.