Skip to content

Sub-agent internal operations lack OpenTelemetry trace spans #1430

Description

@petabridge-netclaw

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:

  1. Create child Activities in InvokeLlmAsync:

  2. Create child Activities in ExecuteToolsAsync:

  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions