observeOrSkip

fun <T> observeOrSkip(registry: <Error class: unknown class>, context: () -> <Error class: unknown class>, work: () -> T): T

Run work inside an observe{} span carrying context. The span always closes — and is errored if work throws — because Observation.observe owns the scope, so no scope can leak.

No explicit no-op short-circuit is needed: Observation.createNotStarted already fast-returns a no-op observation for a no-op registry without invoking the context supplier, so the disabled-tracing path builds no context and runs work directly.

The span name is not supplied here: the registered convention names it from context (see PLACEHOLDER_NAME).

Returns exactly what work returns, including null: Observation.observe is a transparent wrapper that hands back work()'s own value, so this helper is safe for both nullable and non-null T. The unchecked cast (rather than a !!) preserves a legitimate null result instead of crashing on it.