Skip to content

Commit

Permalink
feat(ddm): Add new metrics and bump sentry-sdk to 1.38.0 (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
iambriccardo authored Dec 4, 2023
1 parent 55a86e9 commit faafbba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flask/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pg8000==1.12.5
psycopg2-binary==2.9.7
python-dotenv==0.12.0
pytz==2020.4
sentry-sdk==1.37.1
sentry-sdk==1.38.0
sqlalchemy==1.3.15
11 changes: 8 additions & 3 deletions flask/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def checkout():
inventory = []
try:
with sentry_sdk.start_span(op="/checkout.get_inventory", description="function"):
inventory = get_inventory(cart)
with sentry_sdk.metrics.timing(key="checkout.get_inventory.execution_time"):
inventory = get_inventory(cart)
except Exception as err:
raise (err)

Expand All @@ -115,6 +116,7 @@ def checkout():
for inventoryItem in inventory:
print("> inventoryItem.count", inventoryItem['count'])
if (inventoryItem.count < quantities[cartItem] or quantities[cartItem] >= inventoryItem.count):
sentry_sdk.metrics.incr(key="checkout.failed")
raise Exception("Not enough inventory for product")
if len(inventory) == 0 or len(quantities) == 0:
raise Exception("Not enough inventory for product")
Expand Down Expand Up @@ -144,14 +146,17 @@ def products():

try:
with sentry_sdk.start_span(op="/products.get_products", description="function"):
rows = get_products()
with sentry_sdk.metrics.timing(key="products.get_products.execution_time"):
rows = get_products()

if RUN_SLOW_PROFILE:
start_time = time.time()
productsJSON = json.loads(rows)
descriptions = [product["description"] for product in productsJSON]
with sentry_sdk.start_span(op="/get_iterator", description="function"):
loop = get_iterator(len(descriptions) * 6)
with sentry_sdk.metrics.timing(key="products.get_iterator.execution_time"):
loop = get_iterator(len(descriptions) * 6)

for i in range(loop):
time_delta = time.time() - start_time
if time_delta > 4:
Expand Down

0 comments on commit faafbba

Please sign in to comment.