Skip to content

Commit aa75fc0

Browse files
committed
Close segment even if error was raised
1 parent aed8e43 commit aa75fc0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

aws_xray_sdk/ext/sqlalchemy/util/decorators.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ def wrapper(*args, **kw):
5858
subsegment = xray_recorder.begin_subsegment(sub_name, namespace='remote')
5959
else:
6060
subsegment = None
61-
res = func(*args, **kw)
62-
if subsegment is not None:
63-
subsegment.set_sql(sql)
64-
subsegment.put_annotation("sqlalchemy", class_name+'.'+func.__name__)
65-
xray_recorder.end_subsegment()
61+
62+
try:
63+
res = func(*args, **kw)
64+
finally:
65+
if subsegment is not None:
66+
subsegment.set_sql(sql)
67+
subsegment.put_annotation("sqlalchemy", class_name+'.'+func.__name__)
68+
xray_recorder.end_subsegment()
6669
return res
6770
return wrapper
6871
# URL Parse output

0 commit comments

Comments
 (0)