feat(logging): bridge Akka logging to Serilog and copy traced runs' node-log lines into the Flow Debugger (ScadaBridge#120, #56)
#120: Akka ILoggingAdapter lines used to bypass Serilog and go to stdout only. - BuildHocon sets akka.loggers = [Host.Actors.SerilogAkkaLogger] and keeps akka.loglevel = INFO, so Akka Debug chatter is still filtered at the adapter. The INFO+ lines that used to reach stdout now go through the Serilog pipeline instead, with no extra volume. - Lines reach the file sinks with the node enrichers. SourceContext is the logging class's full name, AkkaSource is the actor path, Akka's own timestamp is kept, and format arguments become structured properties. - The Akka logger actor writes on its own thread, after the logging actor's LogContext is gone. To keep the ExecutionId, the two DCL actors log through ExecutionAwareLogging.GetLogger(Context), which records ExecutionLogContext.Current (a new AsyncLocal mirror of the pushed id) in an ExecutionTaggedLogMessage. The logger actor pushes that id again while it writes the line. #56 remainder (coordinator decision: no replicated schema change): - The host pipeline gains ExecutionLogCaptureSink. - While a run is traced, its step logger registers its ExecutionId: the site ScriptLogger from the launcher (plus each inline CallShared child id), and the central InboundScriptLogger from the executor. - Each tagged line becomes a ScriptLog row with LogSource "node" and the new ScriptTraceExtra.LogCategory. - The rows count against the existing MaxLogLinesPerRun cap, are clipped at 2 000 chars, ride the low-priority collector lane and pass the same redactor. Untraced runs cost one volatile read. - Lines are never copied twice. The step loggers' own forwards run inside ExecutionLogCapture.Suppress(), and the sink suppresses itself while it calls a target. The registration is declared inside the launcher's and executor's try, so it ends before the catch blocks log the outcome, and FlushDropped closes it. - FlowGraphBuilder lists node lines in FlowGraph.NodeLogs and never folds them onto a step. - The Flow Debugger shows them in a Node log card (FlowNodeLogPanel): grouped per execution under its run step, with an All | Warn + filter. Live and Replay both read the same rows, so site scope and role rules apply unchanged. - CLI --show-logs prints them as a trailing block. Tests: Commons ExecutionLogCaptureTests, ExecutionLogContext.Current, FlowGraphBuilder node lines. SiteRuntime NodeLogCaptureTests covers cross-actor capture via the launcher, untraced runs capturing nothing, no double capture of script and runtime lines or of the launcher failure line, the shared cap, collector redaction, shared-script child ids and FlushDropped closing capture. InboundNodeLogCaptureTests covers the central path. DCL ExecutionAwareLoggingTests covers the DataConnectionActor write-path Debug line being tagged and an uncorrelated line not being tagged. Host SerilogAkkaLoggerTests covers mapping, the ExecutionId crossing the logger hop, HOCON, ActorSystem boot and the Akka line reaching a traced run's step log end to end. Host LoggerConfigurationTests checks that the sink is wired. bUnit FlowNodeLogPanelTests and a CLI projection test cover the UI and CLI. Every new assertion was mutation-proven. Docs: step-logs design section 12, Component-SiteRuntime, CentralUI, InboundAPI, Host, CLI README, CLAUDE.md. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -16,13 +16,19 @@ public sealed record FlowEdge(Guid FromEventId, Guid ToEventId, bool CrossesBoun
|
||||
/// <param name="Truncated">True when the inline event list was capped (the audit rows remain complete — Replay shows everything).</param>
|
||||
/// <param name="LogsTruncated">True when the inline trace collector dropped low-priority log rows to keep room for the step rows — the audit rows remain complete, so Replay shows every line (design 2026-09-09 D7).</param>
|
||||
/// <param name="UnattachedLogLines">Count of log lines the builder could not place on any step (design 2026-09-09 D2).</param>
|
||||
/// <param name="NodeLogs">
|
||||
/// Node-log lines copied for the traced executions (source <c>node</c>, ScadaBridge#56), in time
|
||||
/// order. They are listed per execution, never folded onto a step: they come from other actors and
|
||||
/// threads, so no step can honestly claim them. Null or empty when there are none.
|
||||
/// </param>
|
||||
public sealed record FlowGraph(
|
||||
IReadOnlyList<FlowStep> Steps,
|
||||
IReadOnlyList<FlowEdge> Edges,
|
||||
bool Predicted,
|
||||
bool Truncated,
|
||||
bool LogsTruncated = false,
|
||||
int UnattachedLogLines = 0)
|
||||
int UnattachedLogLines = 0,
|
||||
IReadOnlyList<FlowLogLine>? NodeLogs = null)
|
||||
{
|
||||
/// <summary>An empty, non-predicted graph.</summary>
|
||||
public static FlowGraph Empty { get; } = new(Array.Empty<FlowStep>(), Array.Empty<FlowEdge>(), false, false);
|
||||
|
||||
@@ -51,6 +51,9 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Debugging;
|
||||
/// dropped and counted in <see cref="FlowGraph.UnattachedLogLines"/>. Within a step, lines are ordered
|
||||
/// by <c>OccurredAtUtc</c> then <c>Seq</c>, with a null <c>Seq</c> sorting last, so same-millisecond
|
||||
/// lines keep their emission order.</item>
|
||||
/// <item><b>Node-log lines are listed, not folded</b> (ScadaBridge#56). A <c>ScriptLog</c> row with source
|
||||
/// <c>node</c> — another actor's line the per-execution sink copied — goes to
|
||||
/// <see cref="FlowGraph.NodeLogs"/> in time order and never onto a step or into the unattached count.</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
public static class FlowGraphBuilder
|
||||
@@ -82,9 +85,13 @@ public static class FlowGraphBuilder
|
||||
|
||||
events = stepEvents.Select(e => e.Event).ToList();
|
||||
|
||||
// ScadaBridge#56: node-log lines (other actors' lines copied for a traced execution) are
|
||||
// listed per execution, not folded onto a step, so they never count as unattached either.
|
||||
var nodeLogs = TakeNodeLines(lines);
|
||||
|
||||
if (events.Count == 0)
|
||||
return new FlowGraph(Array.Empty<FlowStep>(), Array.Empty<FlowEdge>(), Predicted: false, Truncated: truncated,
|
||||
LogsTruncated: logsTruncated, UnattachedLogLines: lines.Count);
|
||||
LogsTruncated: logsTruncated, UnattachedLogLines: lines.Count, NodeLogs: nodeLogs);
|
||||
|
||||
// Arch-review F5: a step's position in the input is the only cross-node ordering we can trust —
|
||||
// central rows carry central's clock, site rows the site's, and a 1-2 s skew used to sort a whole
|
||||
@@ -268,7 +275,19 @@ public static class FlowGraphBuilder
|
||||
AttachLogLines(steps, lines, out var unattached);
|
||||
|
||||
return new FlowGraph(steps, edges, Predicted: false, Truncated: truncated,
|
||||
LogsTruncated: logsTruncated, UnattachedLogLines: unattached);
|
||||
LogsTruncated: logsTruncated, UnattachedLogLines: unattached, NodeLogs: nodeLogs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the node-log lines (source <c>node</c>, ScadaBridge#56) from <paramref name="lines"/>
|
||||
/// and returns them ordered by time, then per-run <c>Seq</c> (null last). Null when there are none.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<FlowLogLine>? TakeNodeLines(List<FlowLogLine> lines)
|
||||
{
|
||||
var node = lines.Where(l => l.IsNodeLine).ToList();
|
||||
if (node.Count == 0) return null;
|
||||
lines.RemoveAll(l => l.IsNodeLine);
|
||||
return node.OrderBy(l => l.OccurredAtUtc).ThenBy(l => l.Seq ?? int.MaxValue).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -84,12 +84,13 @@ public sealed record FlowLifecycleRow(
|
||||
/// <param name="ExecutionId">Execution the line was written in.</param>
|
||||
/// <param name="OccurredAtUtc">When the line was written.</param>
|
||||
/// <param name="Level"><c>debug</c> | <c>info</c> | <c>warn</c> | <c>error</c>.</param>
|
||||
/// <param name="Source"><c>script</c> (a <c>Log.*</c> call) | <c>runtime</c> (the context's own logger while traced).</param>
|
||||
/// <param name="Source"><c>script</c> (a <c>Log.*</c> call) | <c>runtime</c> (the context's own logger while traced) | <c>node</c> (another node-log line tagged with the execution, ScadaBridge#56).</param>
|
||||
/// <param name="Message">The logged message.</param>
|
||||
/// <param name="ExceptionMessage">Message of an attached exception, when the line carried one.</param>
|
||||
/// <param name="ExceptionDetail">Full <c>ToString()</c> of that exception.</param>
|
||||
/// <param name="StepEventId">Step the line belongs to; null = the execution's anchor step (design D2).</param>
|
||||
/// <param name="Seq">Per-run emission counter, breaking same-millisecond ties in display order.</param>
|
||||
/// <param name="Category">On a <c>node</c> line (ScadaBridge#56): the logger category that wrote it.</param>
|
||||
public sealed record FlowLogLine(
|
||||
Guid EventId,
|
||||
Guid? ExecutionId,
|
||||
@@ -100,7 +101,15 @@ public sealed record FlowLogLine(
|
||||
string? ExceptionMessage,
|
||||
string? ExceptionDetail,
|
||||
Guid? StepEventId,
|
||||
int? Seq);
|
||||
int? Seq,
|
||||
string? Category = null)
|
||||
{
|
||||
/// <summary>The <see cref="Source"/> of a node-log line copied by the per-execution sink (ScadaBridge#56).</summary>
|
||||
public const string NodeSource = "node";
|
||||
|
||||
/// <summary>True for a node-log line, which the graph lists per execution rather than on a step.</summary>
|
||||
public bool IsNodeLine => string.Equals(Source, NodeSource, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One node of the flow graph — a central-side projection of a <c>ScriptTrace</c> /
|
||||
|
||||
@@ -102,7 +102,8 @@ public static class FlowStepProjector
|
||||
ExceptionMessage: d.ErrorMessage,
|
||||
ExceptionDetail: d.ErrorDetail,
|
||||
StepEventId: x?.StepEventId,
|
||||
Seq: x?.Seq);
|
||||
Seq: x?.Seq,
|
||||
Category: x?.LogCategory);
|
||||
}
|
||||
|
||||
/// <summary>Projects one outbound audit row onto its lifecycle entry (<see cref="FlowStep.Lifecycle"/>).</summary>
|
||||
|
||||
@@ -52,9 +52,12 @@ public sealed record ScriptTraceExtra
|
||||
/// <summary>On a <c>ScriptLog</c> row: <c>debug</c> | <c>info</c> | <c>warn</c> | <c>error</c>.</summary>
|
||||
public string? LogLevel { get; init; }
|
||||
|
||||
/// <summary>On a <c>ScriptLog</c> row: <c>script</c> (a <c>Log.*</c> call) | <c>runtime</c> (the context's own logger while traced).</summary>
|
||||
/// <summary>On a <c>ScriptLog</c> row: <c>script</c> (a <c>Log.*</c> call) | <c>runtime</c> (the context's own logger while traced) | <c>node</c> (any other node-log line tagged with the execution's id, ScadaBridge#56).</summary>
|
||||
public string? LogSource { get; init; }
|
||||
|
||||
/// <summary>On a <c>node</c> <c>ScriptLog</c> row: the logger category (<c>SourceContext</c>) that wrote the line (ScadaBridge#56).</summary>
|
||||
public string? LogCategory { get; init; }
|
||||
|
||||
/// <summary>On a <c>ScriptLog</c> row: the pre-minted <c>EventId</c> of the step the line belongs to; null = the execution's anchor step (design D2).</summary>
|
||||
public Guid? StepEventId { get; init; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user