def key_of(msg, group_by, depth):
    """ get the msg's attribute to be used as key for grouping """
    if group_by == 'path':
        key = msg.path if depth == 0 else msg.parent_path(depth)
    elif group_by == 'type':
        key = msg.name
    elif group_by == 'client':
        key = msg.client
    else:
        raise ValueError('Unknown group: %s' % group_by)
    return key
