def escape_metric_name(s: str) -> str:
    """Escapes the metric name and puts it in quotes iff the name does not
    conform to the legacy Prometheus character set.
    """
    if _is_valid_legacy_metric_name(s):
        return s
    return '"{}"'.format(_escape(s))
Escapes the metric name and puts it in quotes iff the name does not
conform to the legacy Prometheus character set.
prometheus_client/openmetrics/exposition.py