telemetry: move some functions to metrics library