예제 #1
0
파일: apm.py 프로젝트: cryptobuks1/mds
        def wrapped_f(*args, **kwargs):
            config = None
            result = None
            if current_app:
                config = current_app.config['ELASTIC_APM']
                apm_enabled = str(current_app.config['ELASTIC_ENABLED']) == '1'
            elif sched.app:
                config = sched.app.app_context().app.config['ELASTIC_APM']
                apm_enabled = str(sched.app.app_context().app.
                                  config['ELASTIC_ENABLED']) == '1'

            _name = name if name is not None else func.__name__

            if apm_enabled:
                client = Client(config)
                if client:
                    client.begin_transaction('registered_funcs')
                    try:
                        result = func(*args, **kwargs)
                        client.end_transaction(f'{_name} - success')
                    except Exception as e:
                        client.capture_exception()
                        client.end_transaction(f'{_name} - error')
                        raise e
                else:
                    print(
                        f'could not create ElasticAPM client... running <{_name}> without APM'
                    )
                    result = func(*args, **kwargs)
            else:
                result = func(*args, **kwargs)
            return result
예제 #2
0
        def wrapped_f(*args, **kwargs):
            client = None
            if current_app:
                client = Client(current_app.config['ELASTIC_APM'])
            elif sched.app:
                client = Client(
                    sched.app.app_context().app.config['ELASTIC_APM'])

            _name = name if name is not None else func.__name__

            # ensure client was created properly
            if client:
                client.begin_transaction('registered_funcs')
                try:
                    func(*args, **kwargs)
                    client.end_transaction(f'{_name} - success')
                except Exception as e:
                    client.capture_exception()
                    client.end_transaction(f'{_name} - error')
                    raise e
            else:
                print(
                    f'could not create ElasticAPM client... running <{_name}> without APM'
                )
                func(*args, **kwargs)
예제 #3
0
    def wrapper(*args, **kwargs):
        config = None
        result = None
        if current_app:
            config = current_app.config['ELASTIC_APM']
            apm_enabled = current_app.config['ELASTIC_ENABLED']
        elif sched.app:
            config = sched.app.app_context().app.config['ELASTIC_APM']
            apm_enabled = sched.app.app_context().app.config['ELASTIC_ENABLED']

        client = Client(config)
        if client and apm_enabled:
            client.begin_transaction('registered_funcs')
            try:
                result = func(*args, **kwargs)
                client.end_transaction(f'{func.__name__} - success')
            except Exception as e:
                client.capture_exception()
                client.end_transaction(f'{func.__name__} - error')
                raise e
        else:
            print(f'Running <{func.__name__}> without APM')
            result = func(*args, **kwargs)
        return result
예제 #4
0
        'DEBUG':
        False,
        'SERVER_URL':
        'http://apm-server-prd.apps.do-prd-okp-m0.do.viaa.be:80'
    })
    handler = LoggingHandler(client=client)
    handler.setLevel(logging.WARN)
    logging.getLogger('elasticapm').setLevel('INFO')
    LOGGER.addHandler(handler)

    try:
        formatter = logging.Formatter('%(asctime)-15s  %(levelname)-6s:'
                                      '%(message)s')
        logging.basicConfig(format=formatter, level=logging.INFO)
    except Exception:
        client.capture_exception()
    try:
        READ_WEBSOCKET_DELAY = 1  # 1 second delay reading from firehose
        if slack_client.rtm_connect():
            LOGGER.info("Bot connected and running!")
            client.capture_message('connected the bot.')

            try:
                while True:
                    command, channel = parse_slack_output(
                        slack_client.rtm_read())
                    if command and channel:
                        client.begin_transaction(transaction_type='request')
                        handle_command(command, channel)
                        #                        elasticapm.set_user_context(command=command, channel=channel)