def returner(ret):
    '''
    Parse the return data and return metrics to AppOptics.

    For each state that's provided in the configuration, return tagged metrics for
    the result of that state if it's present.
    '''

    options = _get_options(ret)
    states_to_report = ['state.highstate']
    if options.get('sls_states'):
        states_to_report.append('state.sls')
    if ret['fun'] in states_to_report:
        tags = options.get('tags', {}).copy()
        tags['state_type'] = ret['fun']
        log.info("Tags for this run are %s", tags)
        matched_states = set(ret['fun_args']).intersection(
            set(options.get('sls_states', [])))
        # What can I do if a run has multiple states that match?
        # In the mean time, find one matching state name and use it.
        if matched_states:
            tags['state_name'] = sorted(matched_states)[0]
            log.debug('Found returned data from %s.', tags['state_name'])
        _state_metrics(ret, options, tags)
Parse the return data and return metrics to AppOptics.

    For each state that's provided in the configuration, return tagged metrics for
    the result of that state if it's present.