Diagnostics
Core building blocks
Guarding a component method
from spx_sdk.components import SpxComponent
from spx_sdk.diagnostics import guard, trace, SpxFault, FaultSeverity
class HeaterDriver(SpxComponent):
@guard(prefix="heater.", http_status=503)
def start(self) -> None:
# Bubble SpxFault to surface a 503 upstream, but swallow transient network noise.
with trace(self, action="heater.connect", bubble=False, severity=FaultSeverity.WARN):
self._bus.open() # emits WARN breadcrumb on failure, continues
with trace(self, action="heater.self_test"):
ok = self._run_self_test() # crash => raises SpxFault(ERROR, bubble=True)
if not ok:
raise SpxFault(
event="self_test_failed",
action="heater.self_test",
component=self,
severity=FaultSeverity.ERROR,
extra={"last_result": ok},
http_status=422,
)
def _run_self_test(self) -> bool:
...Auto-guard lifecycle hooks
Correlation IDs in practice
Emitting events elsewhere
Working with FaultEvent payloads
Last updated

