Problem
PR #1428 added OpenTelemetry trace correlation at the spawner level (parent activity linked to parent session's trace), but sub-agent internal operations don't create their own child activities.
Current Behavior
SubAgentSpawner creates an Activity("netclaw.subagent.spawn") linked to the parent session's trace
SubAgentActor.InvokeLlmAsync — no Activity created for LLM calls
SubAgentActor.ExecuteToolsAsync — no Activity created for tool executions
In Seq/Grafana traces, the sub-agent appears as a single flat span with no sub-spans for the work it does.
Root Cause
SubAgentActor.InvokeLlmAsync and SubAgentActor.ExecuteToolsAsync don't create child activities or set their own parent trace context. They log directly without pushing a diagnostic scope.
Proposed Fix
In SubAgentActor:
-
Create child Activities in InvokeLlmAsync:
-
Create child Activities in ExecuteToolsAsync:
-
Alternatively, use Activity.CreateRootActivity for independent traces if not wanting to inherit the parent.
Impact After Fix
Sub-agent traces in Grafana/Seq will show:
- Parent session → sub-agent spawn span → per-LLM-call spans → per-tool spans
- Total time breakdown: how much time spent in LLM vs tools
- Failed tool calls appear as error spans for easy filtering
References
Problem
PR #1428 added OpenTelemetry trace correlation at the spawner level (parent activity linked to parent session's trace), but sub-agent internal operations don't create their own child activities.
Current Behavior
SubAgentSpawnercreates anActivity("netclaw.subagent.spawn")linked to the parent session's traceSubAgentActor.InvokeLlmAsync— no Activity created for LLM callsSubAgentActor.ExecuteToolsAsync— no Activity created for tool executionsIn Seq/Grafana traces, the sub-agent appears as a single flat span with no sub-spans for the work it does.
Root Cause
SubAgentActor.InvokeLlmAsyncandSubAgentActor.ExecuteToolsAsyncdon't create child activities or set their own parent trace context. They log directly without pushing a diagnostic scope.Proposed Fix
In
SubAgentActor:Create child Activities in
InvokeLlmAsync:Create child Activities in
ExecuteToolsAsync:Alternatively, use
Activity.CreateRootActivityfor independent traces if not wanting to inherit the parent.Impact After Fix
Sub-agent traces in Grafana/Seq will show:
References
SubAgentActor.cs—InvokeLlmAsync,ExecuteToolsAsyncSubAgentSpawner.cs— spawner Activity creation (existing pattern)