Skip to content

Commit

Permalink
Merge pull request #234 from FerumFlex/better-handling-sqlalchemy-errors
Browse files Browse the repository at this point in the history
SqlAlchemy: Close segment even if error was raised
  • Loading branch information
wangzlei authored Jul 20, 2020
2 parents aed8e43 + aa75fc0 commit 969283c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions aws_xray_sdk/ext/sqlalchemy/util/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ def wrapper(*args, **kw):
subsegment = xray_recorder.begin_subsegment(sub_name, namespace='remote')
else:
subsegment = None
res = func(*args, **kw)
if subsegment is not None:
subsegment.set_sql(sql)
subsegment.put_annotation("sqlalchemy", class_name+'.'+func.__name__)
xray_recorder.end_subsegment()

try:
res = func(*args, **kw)
finally:
if subsegment is not None:
subsegment.set_sql(sql)
subsegment.put_annotation("sqlalchemy", class_name+'.'+func.__name__)
xray_recorder.end_subsegment()
return res
return wrapper
# URL Parse output
Expand Down

0 comments on commit 969283c

Please sign in to comment.