Add support for tracing script execution (#48276)
* Add support for tracing script execution * Tweak
This commit is contained in:
parent
0be6a868e0
commit
8896ae0d56
10 changed files with 531 additions and 391 deletions
23
homeassistant/components/script/trace.py
Normal file
23
homeassistant/components/script/trace.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""Trace support for script."""
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from homeassistant.components.trace import ScriptTrace, async_store_trace
|
||||
|
||||
|
||||
@contextmanager
|
||||
def trace_script(hass, item_id, config, context):
|
||||
"""Trace execution of a script."""
|
||||
trace = ScriptTrace(item_id, config, context)
|
||||
async_store_trace(hass, trace)
|
||||
|
||||
try:
|
||||
yield trace
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
if item_id:
|
||||
trace.set_error(ex)
|
||||
raise ex
|
||||
finally:
|
||||
if item_id:
|
||||
trace.finished()
|
Loading…
Add table
Add a link
Reference in a new issue