def returner(ret):
    '''
    Log outcome to sentry. The returner tries to identify errors and report
    them as such. All other messages will be reported at info level.
    '''
    def connect_sentry(message, result):
        '''
        Connect to the Sentry server
        '''
        pillar_data = __salt__['pillar.raw']()
        grains = __salt__['grains.items']()
        sentry_data = {
            'result': result,
            'pillar': pillar_data,
            'grains': grains
        }
        data = {
            'platform': 'python',
            'culprit': ret['fun'],
            'level': 'error'
        }
        tags = {}
        if 'tags' in pillar_data['raven']:
            for tag in pillar_data['raven']['tags']:
                tags[tag] = grains[tag]

        if ret['return']:
            data['level'] = 'info'

        servers = []
        try:
            for server in pillar_data['raven']['servers']:
                servers.append(server + '/api/store/')
            client = Client(
                servers=servers,
                public_key=pillar_data['raven']['public_key'],
                secret_key=pillar_data['raven']['secret_key'],
                project=pillar_data['raven']['project'],
            )
        except __HOLE__ as missing_key:
            logger.error(
                'Sentry returner need config \'{0}\' in pillar'.format(
                    missing_key
                )
            )
        else:
            try:
                client.capture(
                    'raven.events.Message',
                    message=message,
                    data=data,
                    extra=sentry_data,
                    tags=tags
                )
            except Exception as err:
                logger.error(
                    'Can\'t send message to sentry: {0}'.format(err),
                    exc_info=True
                )

    try:
        connect_sentry(ret['fun'], ret)
    except Exception as err:
        logger.error(
            'Can\'t run connect_sentry: {0}'.format(err),
            exc_info=True
        )
dataset/ETHPy150Open saltstack/salt/salt/returners/sentry_return.py/returner