Skip to content

Commit 08dbf7b

Browse files
committed
minor simplification
1 parent 388728d commit 08dbf7b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/service-library/src/servicelib/tracing.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:
7171
span_name = f"{func.__module__}.{func.__qualname__}"
7272

7373
with tracer.start_as_current_span(span_name) as span:
74+
profiler = pyinstrument.Profiler(async_mode="enabled")
75+
profiler.start()
76+
7477
try:
75-
profiler = pyinstrument.Profiler(async_mode="enabled")
76-
profiler.start()
77-
78-
try:
79-
return await func(*args, **kwargs)
80-
finally:
81-
profiler.stop()
82-
span.set_attribute(
83-
_PROFILE_ATTRIBUTE_NAME,
84-
profiler.output_text(unicode=True, color=False, show_all=True),
85-
)
78+
return await func(*args, **kwargs)
8679

8780
except Exception as e:
8881
span.record_exception(e)
89-
span.set_status(trace.Status(trace.StatusCode.ERROR, str(e)))
82+
span.set_status(trace.Status(trace.StatusCode.ERROR, f"{e}"))
9083
raise
9184

85+
finally:
86+
profiler.stop()
87+
span.set_attribute(
88+
_PROFILE_ATTRIBUTE_NAME,
89+
profiler.output_text(unicode=True, color=False, show_all=True),
90+
)
91+
9292
return wrapper

0 commit comments

Comments
 (0)