I think this last 'k' should be 'key':

    self.publish(metric_name, metrics[key])