Skip to content

Commit

Permalink
add sentry logging and error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Sep 8, 2023
1 parent 88a4c26 commit 829d52d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
13 changes: 13 additions & 0 deletions findthatpostcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import os
import re

import sentry_sdk
from flask import Flask, make_response, render_template, request
from flask_cors import CORS
from sentry_sdk.integrations.flask import FlaskIntegration
from ua_parser import user_agent_parser

from findthatpostcode import blueprints, commands, db
Expand All @@ -20,6 +22,17 @@ def get_es_url(default):


def create_app(test_config=None):
if os.environ.get("SENTRY_DSN"):
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN"),
integrations=[FlaskIntegration()],
environment=(
"development" if os.environ.get("FLASK_DEBUG") else "production"
),
traces_sample_rate=0.005,
profiles_sample_rate=0.005,
)

# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
Expand Down
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ requests-mock
blinker
sqlite-utils
ua-parser
boto3
boto3
sentry-sdk[flask]
28 changes: 26 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ attrs==22.1.0
black==22.10.0
# via -r requirements.in
blinker==1.5
# via -r requirements.in
# via
# -r requirements.in
# sentry-sdk
boto3==1.26.61
# via -r requirements.in
botocore==1.29.61
Expand All @@ -20,6 +22,7 @@ certifi==2022.12.7
# via
# elasticsearch
# requests
# sentry-sdk
chardet==4.0.0
# via requests
click==8.0.1
Expand All @@ -30,6 +33,10 @@ click==8.0.1
# sqlite-utils
click-default-group-wheel==1.2.2
# via sqlite-utils
colorama==0.4.6
# via
# click
# pytest
dictlib==1.1.5
# via -r requirements.in
elasticmock==1.8.1
Expand All @@ -38,16 +45,21 @@ elasticsearch==7.8.1
# via
# -r requirements.in
# elasticmock
exceptiongroup==1.1.3
# via pytest
flask==2.2.2
# via
# -r requirements.in
# flask-cors
# sentry-sdk
flask-cors==3.0.10
# via -r requirements.in
gunicorn==20.1.0
# via -r requirements.in
idna==2.10
# via requests
importlib-metadata==6.8.0
# via flask
iniconfig==1.1.1
# via pytest
isort==5.10.1
Expand All @@ -65,6 +77,7 @@ jmespath==1.0.1
markupsafe==2.1.1
# via
# jinja2
# sentry-sdk
# werkzeug
mypy-extensions==0.4.3
# via black
Expand Down Expand Up @@ -98,6 +111,8 @@ requests-mock==1.10.0
# via -r requirements.in
s3transfer==0.6.0
# via boto3
sentry-sdk[flask]==1.30.0
# via -r requirements.in
six==1.16.0
# via
# flask-cors
Expand All @@ -110,19 +125,28 @@ sqlite-utils==3.30
# via -r requirements.in
tabulate==0.9.0
# via sqlite-utils
tomli==2.0.1
# via
# black
# pytest
tqdm==4.61.1
# via -r requirements.in
typing-extensions==4.7.1
# via black
ua-parser==0.16.1
# via -r requirements.in
url-normalize==1.4.3
# via requests-cache
urllib3==1.26.5
urllib3==1.26.16
# via
# botocore
# elasticsearch
# requests
# sentry-sdk
werkzeug==2.2.2
# via flask
zipp==3.16.2
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools

0 comments on commit 829d52d

Please sign in to comment.