diff --git a/Makefile b/Makefile index f751164..f96416b 100644 --- a/Makefile +++ b/Makefile @@ -17,4 +17,6 @@ associate_commits: sentry-cli releases -o $(SENTRY_ORG) -p $(SENTRY_PROJECT) set-commits --auto $(VERSION) run_flask: - VERSION=$(VERSION) FLASK_APP=app.py FLASK_ENV=development flask run -p 3001 + # VERSION=$(VERSION) FLASK_APP=app.py FLASK_ENV=development flask run -p 3001 + VERSION=$(VERSION) FLASK_APP=app.py flask run -p 3001 + diff --git a/README.md b/README.md index 583476d..919cffe 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,5 @@ make deploy ``` ## GIF +based on 0.7.10 ![Alt Text](flask-demo.gif) diff --git a/app.py b/app.py index 75b5cd2..36be022 100644 --- a/app.py +++ b/app.py @@ -5,10 +5,14 @@ import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration +# sentry_sdk 0.13.5 +# >= 0.11.2 is needed sentry_sdk.init( dsn="https://2ba68720d38e42079b243c9c5774e05c@sentry.io/1316515", + traces_sample_rate=1.0, integrations=[FlaskIntegration()], - release=os.environ.get("VERSION") + release=os.environ.get("VERSION"), + environment="prod" ) app = Flask(__name__) @@ -26,8 +30,12 @@ def handled_exception(): @app.route('/unhandled', methods=['GET']) def unhandled_exception(): + with sentry_sdk.start_span(op="http", description="GET /unhandled") as span: + span.set_tag("http.status_code", 200) + span.set_data("http.foobarsessionid", 123456) + span.finish() obj = {} - obj['keyDoesntExist'] + obj['keyDoesntExist1'] Inventory = { 'wrench': 1, @@ -65,6 +73,10 @@ def sentry_event_context(): @app.route('/checkout', methods=['POST']) def checkout(): + with sentry_sdk.start_span(op="http", description="POST /checkout") as span: + span.set_tag("http.status_code", 200) + span.set_data("http.foobarsessionid", 987654) + span.finish() order = json.loads(request.data) print "Processing order for: " + order["email"] @@ -72,4 +84,4 @@ def checkout(): process_order(cart) - return 'Success' + return 'Success' \ No newline at end of file diff --git a/generate_events.sh b/generate_events.sh index efbb73b..eeb8cd6 100644 --- a/generate_events.sh +++ b/generate_events.sh @@ -10,6 +10,6 @@ run_curl () { NAME=flask RANDOM_STRING=`openssl rand -base64 8` -run_curl https://sentry-demos-$NAME.herokuapp.com/handled -run_curl https://sentry-demos-$NAME.herokuapp.com/unhandled -run_curl -X POST https://sentry-demos-$NAME.herokuapp.com/checkout -H "Content-Type: application/json" -H "X-Session-ID: _${RANDOM_STRING}" -H "X-Transaction-ID: _${RANDOM_STRING}" -d "{\"email\":\"$X@yahoo.com\", \"cart\":[{\"id\":\"wrench\", \"name\":\"Wrench\", \"price\":500}]}" \ No newline at end of file +run_curl https://will-flask-demo.herokuapp.com/handled +run_curl https://will-flask-demo.herokuapp.com/unhandled +run_curl -X POST https://will-flask-demo.herokuapp.com/checkout -H "Content-Type: application/json" -H "X-Session-ID: _${RANDOM_STRING}" -H "X-Transaction-ID: _${RANDOM_STRING}" -d "{\"email\":\"$X@yahoo.com\", \"cart\":[{\"id\":\"wrench\", \"name\":\"Wrench\", \"price\":500}]}" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index cafdfdc..c28aeea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ flask==1.0.2 -sentry-sdk[flask]==0.9.5 +sentry-sdk[flask]==0.13.5 flask-cors==3.0.7 gunicorn==0.14.2