Skip to content
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

feat(ddm): Add new metrics and bump sentry-sdk to 1.38.0 #355

Merged
merged 2 commits into from
Dec 4, 2023
Merged
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
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 @@ -102,7 +102,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 @@ -114,6 +115,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 @@ -143,14 +145,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
Loading