def _recurse_dict(d, fields):
    """Traverse a dictionary recursively looking for keys matching the list of keys in 'fields'"""
    task_metrics = {}
    for k,v in d.iteritems():
        if k in fields: task_metrics[k] = v
        if isinstance(v,dict):
            new_dict = _recurse_dict(v,fields)
            if new_dict is not None: 
                task_metrics.update(new_dict)
    return task_metrics