From f6273afe7b14fbeefc9254896c46679c7c52e0a8 Mon Sep 17 00:00:00 2001 From: Torma Date: Mon, 19 Oct 2020 23:31:40 +0200 Subject: [PATCH] add more transactions to sentry --- src/resources.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/resources.py b/src/resources.py index 40c0340..eb3a0a5 100644 --- a/src/resources.py +++ b/src/resources.py @@ -4,11 +4,12 @@ from xeger import Xeger from flask_restful import Resource from flask import request, current_app import requests +from sentry_sdk import start_transaction +import pika from db import db from models import SampleMetadata from schemas import SampleSchema, SampleMetadataSchema from config import * -import pika """ Flask Restful endpoints @@ -76,20 +77,21 @@ class SampleResource(Resource): soundfile, soundfile.content_type, {'Content-Length': soundfile.content_length})}).raise_for_status() - credentials = pika.PlainCredentials(current_app.config['FLASK_PIKA_PARAMS']['username'], - current_app.config['FLASK_PIKA_PARAMS']['password']) - connection = pika.BlockingConnection( - pika.ConnectionParameters(host=current_app.config['FLASK_PIKA_PARAMS']['host'], - credentials=credentials, - heartbeat=0, - socket_timeout=5)) - channel = connection.channel() - channel.exchange_declare(exchange=current_app.config['FLASK_PIKA_PARAMS']['EXCHANGE_NAME'], - exchange_type='fanout') - channel.basic_publish(exchange=current_app.config['FLASK_PIKA_PARAMS']['EXCHANGE_NAME'], - routing_key='feature', - body=json.dumps({'tag': generated_tag}).encode('UTF-8')) - connection.close() + with start_transaction(op="rabbitmq-send", name="rabbitmq-connect-and-publish"): + credentials = pika.PlainCredentials(current_app.config['FLASK_PIKA_PARAMS']['username'], + current_app.config['FLASK_PIKA_PARAMS']['password']) + connection = pika.BlockingConnection( + pika.ConnectionParameters(host=current_app.config['FLASK_PIKA_PARAMS']['host'], + credentials=credentials, + heartbeat=0, + socket_timeout=5)) + channel = connection.channel() + channel.exchange_declare(exchange=current_app.config['FLASK_PIKA_PARAMS']['EXCHANGE_NAME'], + exchange_type='fanout') + channel.basic_publish(exchange=current_app.config['FLASK_PIKA_PARAMS']['EXCHANGE_NAME'], + routing_key='feature', + body=json.dumps({'tag': generated_tag}).encode('UTF-8')) + connection.close() except Exception as e: current_app.logger.exception(e) db.session.rollback()