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)
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
async def wrapper(*args, **kwargs): try: instrument() client = Client() handler = LoggingHandler() logger = logging.getLogger() logger.addHandler(handler) client.begin_transaction(tran_category) result = await func(*args, **kwargs) client.end_transaction(tran_name, ok_status) return result except Exception as e: logging.error(e, exc_info=True) client.end_transaction(tran_name, error_status) raise
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
</body></html>""" .format(event["queryStringParameters"]['name'], event["queryStringParameters"]['country'], event["queryStringParameters"]['subject']) client = boto3.client('SENDER',region_name=AWS_REGION) response = client.send_email( Destination={'ToAddresses': [RECIPIENT]}, Message={ 'Body': {'Html': {'Data': BODY_HTML}}, 'Subject': {'Data': SUBJECT}, }, Source=SENDER ) except ClientError as e: print(e.response['Error']['Message']) else: print("Email sent! Message ID:") print(response['MessageId']) return { "statusCode": 200, "body": json.dumps({"message": "form submitted"}) } except: client.capture_exception() return { "statusCode": 500, "body": json.dumps({"message": "Internal Request failed"}) } client.end_transaction('feedback-transaction', 'success') #print(lambda_handler(event,context))
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) client.capture_message('got command') client.end_transaction('processor', 200) # client.begin_transaction('processors',transaction_type='request') time.sleep(READ_WEBSOCKET_DELAY) except KeyboardInterrupt: client.capture_exception() pass else: LOGGER.error("Connection failed. Invalid Slack token or bot ID?") client.capture_exception() finally: LOGGER.info('killing Logger and exiting bot , Bye Bye ..') client.capture_message('Closed and cleaned up') clean_up_exit()
pubsub.subscribe([redis_channel]) for item in pubsub.listen(): try: message = json.loads(str(item['data'].decode("utf-8"))) except Exception as e: log_message(e) continue if not zipkin_url or 'zipkinSpan' not in message: log_message(message) continue span_data = message['zipkinSpan'] try: with zipkin_span(service_name='log-message-processor', zipkin_attrs=ZipkinAttrs( trace_id=span_data['_traceId']['value'], span_id=generate_random_64bit_string(), parent_span_id=span_data['_spanId'], is_sampled=span_data['_sampled']['value'], flags=None), span_name='save_log', transport_handler=http_transport, sample_rate=100): client.begin_transaction('logger') log_message(message) client.end_transaction('logger') except Exception as e: print('did not send data to Zipkin: {}'.format(e)) log_message(message)