Add support for tracing script execution (#48276)

* Add support for tracing script execution

* Tweak
This commit is contained in:
Erik Montnemery 2021-03-24 17:56:22 +01:00 committed by GitHub
parent 0be6a868e0
commit 8896ae0d56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 531 additions and 391 deletions

View 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()