Skip to content

APM Tracing alpha #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ make deploy
```

## GIF
based on 0.7.10
![Alt Text](flask-demo.gif)
18 changes: 15 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]/1316515",
traces_sample_rate=1.0,
integrations=[FlaskIntegration()],
release=os.environ.get("VERSION")
release=os.environ.get("VERSION"),
environment="prod"
)

app = Flask(__name__)
Expand All @@ -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,
Expand Down Expand Up @@ -65,11 +73,15 @@ 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"]
cart = order["cart"]

process_order(cart)

return 'Success'
return 'Success'
6 changes: 3 additions & 3 deletions generate_events.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\":\"[email protected]\", \"cart\":[{\"id\":\"wrench\", \"name\":\"Wrench\", \"price\":500}]}"
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\":\"[email protected]\", \"cart\":[{\"id\":\"wrench\", \"name\":\"Wrench\", \"price\":500}]}"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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