feat(logging): stamp ExecutionId/InstanceName/ScriptName on the Serilog LogContext per run (ScadaBridge#56)

The site script and alarm on-trigger launchers push the run identity onto LogContext for the
run's lifetime and the host now enables Enrich.FromLogContext(), so log lines written on the
run's own async call chain carry the id. Bounded part only: LogContext does not cross an Akka
message hop, so Instance Actor/DCL/S&F lines and a site_events execution-id column remain open
(documented in the step-logs design doc section 9).

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 14:20:02 -05:00
parent 5ef27fd9a3
commit 7f479f3a5c
7 changed files with 144 additions and 2 deletions
@@ -288,6 +288,7 @@ internal static class ScriptRunLauncher
var workerSlot = ScriptExecutionScheduler.CurrentWorkerSlot;
var workerRunStamp = workerSlot is { } slot ? executionScheduler.CurrentRunStamp(slot) : 0L;
IDisposable? logScope = null;
var completed = 0;
ArmStuckScriptWatchdog(
cts, options, logger, siteEventLogger, executionScheduler,
@@ -412,6 +413,9 @@ internal static class ScriptRunLauncher
// Script file access (design 2026-09-28): the Files global's host reader.
fileReader: fileReader);
// ScadaBridge#56: stamp the run identity on the LogContext for the rest of the run.
logScope = ScriptRunLogScope.Push(context.ExecutionId, instanceName, scriptName);
var globals = new ScriptGlobals
{
Instance = context,
@@ -533,6 +537,7 @@ internal static class ScriptRunLauncher
// Mark the body finished so the stuck-script watchdog (registered on
// cts.Token above) treats a timely cancellation as NOT stuck.
Interlocked.Exchange(ref completed, 1);
logScope?.Dispose();
// Dispose the DI scope (and scoped services) after script execution completes
serviceScope?.Dispose();
cts.Dispose();
@@ -709,6 +714,7 @@ internal static class ScriptRunLauncher
var workerSlot = ScriptExecutionScheduler.CurrentWorkerSlot;
var workerRunStamp = workerSlot is { } slot ? executionScheduler.CurrentRunStamp(slot) : 0L;
IDisposable? logScope = null;
var completed = 0;
ArmStuckScriptWatchdog(
cts, options, logger, siteEventLogger, executionScheduler,
@@ -766,6 +772,8 @@ internal static class ScriptRunLauncher
// Script file access (design 2026-09-28): the Files global's host reader.
fileReader: services?.GetService<IScriptFileReader>());
logScope = ScriptRunLogScope.Push(context.ExecutionId, instanceName, scriptName);
var globals = new ScriptGlobals
{
Instance = context,
@@ -811,6 +819,7 @@ internal static class ScriptRunLauncher
// Mark the body finished so the stuck-script watchdog (registered on
// cts.Token above) treats a timely cancellation as NOT stuck.
Interlocked.Exchange(ref completed, 1);
logScope?.Dispose();
cts.Dispose();
}
}