def metrics_get_process_name(process):
    """
    Gets the name for a passed psutil Process object. This is surprisingly
    tricky -- there are a bunch of edge cases to consider in terms of delivering
    something useful
    """

    def sanitize_process_name(name):
        return name.replace(" ", "").replace("(", "").replace(")", "").replace(",", "")

    name = f"{process.pid}"

    cmdline = process.cmdline()
    if cmdline:
        for val in cmdline[:2]:
            name += f":{sanitize_process_name(val)}"
    else:
        procname = process.name()
        if procname:
            name += f":{procname}"
        if name is None:
            name += ":none"

    return name