Skip to content

feat: add OpenTelemetry task and operation IDs to agent telemetry spans - #261

Merged
l50 merged 2 commits into
mainfrom
feat/telemetry-agent-loop-span
May 8, 2026
Merged

l50 merged 2 commits into
mainfrom
feat/telemetry-agent-loop-span

Conversation

@l50

@l50 l50 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Key Changes:

  • Added op.id and task.id fields to all agent-related telemetry spans for improved correlation and traceability
  • Updated agent loop and tool execution logic to propagate and emit these identifiers
  • Refactored span builder and helper functions to support the new identifiers throughout the codebase

Added:

  • op.id and task.id span attributes to all relevant agent, decision, tool call, discovery, and milestone telemetry spans for OpenTelemetry compatibility and enhanced query/filter capabilities
  • task_id field to the AgentSpanBuilder struct and corresponding builder method for consistent span construction
  • Internal helper function resolve_operation_id_from_env in agent loop runner to reliably extract operation ID from environment variables

Changed:

  • Refactored agent loop runner (ares-llm/src/agent_loop/runner.rs) to nest all agent task execution under a parent span containing op.id and task.id

  • Updated span creation in milestones, tool execution, and decision-making to include both operation and task identifiers

  • Modified span builder and helper functions (ares-core/src/telemetry/spans/builder.rs, helpers.rs) to accept and propagate the new identifiers as needed

  • Updated test cases in span module to verify presence of new attributes in spans

  • Updated GitHub Actions workflows to use the latest versions of actions/upload-artifact and actions/setup-go

  • Updated Semgrep workflow to use a new container image version for improved security and compatibility

The runner emitted no parent span for an agent loop run, so tool spans
landed as orphan siblings in Tempo: a single failing task could not be
recovered as one trace, only as a fan of unrelated spans. Worse, four
call sites passed `task_id` into the helpers' `operation_id` parameter
(runner.rs:311 et al.), so the `attack_operation_id` field on tool
spans actually held a task ID — silently breaking any dashboard that
filtered by operation.

- Open `agent.loop` once at the top of run_agent_loop, carrying op.id,
  task.id, agent.role, agent.model. Move the existing body into
  run_agent_loop_inner and instrument the future with that span; every
  child span now inherits the parent.
- Add `task_id` to AgentSpanBuilder + the four trace_* helpers and
  emit `op.id` / `task.id` alongside the existing
  `attack_operation_id` field for back-compat with current dashboards.
- Fix the four runner.rs sites that were passing task_id where
  operation_id was expected, and pass real op.id and task.id to the
  worker discovery span and the orchestrator domain-admin span.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.02326% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.13%. Comparing base (60b2915) to head (ab76033).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
ares-llm/src/agent_loop/runner.rs 94.00% 3 Missing ⚠️
ares-core/src/telemetry/spans/helpers.rs 84.61% 2 Missing ⚠️
ares-cli/src/worker/tool_executor.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #261      +/-   ##
==========================================
+ Coverage   75.10%   75.13%   +0.02%     
==========================================
  Files         383      383              
  Lines       81465    81570     +105     
==========================================
+ Hits        61187    61286      +99     
- Misses      20278    20284       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

**Changed:**

- Updated function calls in run_agent_loop_inner to pass op_id as a value (Some(op_id)) instead of as a reference (Some(&op_id)) to match expected parameter types and avoid potential lifetime or type mismatch issues in agent_loop/runner.rs
@l50
l50 merged commit 8ab805f into main May 8, 2026
11 checks passed
@l50
l50 deleted the feat/telemetry-agent-loop-span branch May 8, 2026 03:30
l50 added a commit that referenced this pull request May 9, 2026
…ns (#261)

**Key Changes:**

- Added `op.id` and `task.id` fields to all agent-related telemetry
spans for improved correlation and traceability
- Updated agent loop and tool execution logic to propagate and emit
these identifiers
- Refactored span builder and helper functions to support the new
identifiers throughout the codebase

**Added:**

- `op.id` and `task.id` span attributes to all relevant agent, decision,
tool call, discovery, and milestone telemetry spans for OpenTelemetry
compatibility and enhanced query/filter capabilities
- `task_id` field to the `AgentSpanBuilder` struct and corresponding
builder method for consistent span construction
- Internal helper function `resolve_operation_id_from_env` in agent loop
runner to reliably extract operation ID from environment variables

**Changed:**

- Refactored agent loop runner (`ares-llm/src/agent_loop/runner.rs`) to
nest all agent task execution under a parent span containing `op.id` and
`task.id`
- Updated span creation in milestones, tool execution, and
decision-making to include both operation and task identifiers
- Modified span builder and helper functions
(`ares-core/src/telemetry/spans/builder.rs`, `helpers.rs`) to accept and
propagate the new identifiers as needed
- Updated test cases in span module to verify presence of new attributes
in spans

- Updated GitHub Actions workflows to use the latest versions of
`actions/upload-artifact` and `actions/setup-go`
- Updated Semgrep workflow to use a new container image version for
improved security and compatibility

---------
l50 added a commit that referenced this pull request May 9, 2026
…ns (#261)

**Key Changes:**

- Added `op.id` and `task.id` fields to all agent-related telemetry
spans for improved correlation and traceability
- Updated agent loop and tool execution logic to propagate and emit
these identifiers
- Refactored span builder and helper functions to support the new
identifiers throughout the codebase

**Added:**

- `op.id` and `task.id` span attributes to all relevant agent, decision,
tool call, discovery, and milestone telemetry spans for OpenTelemetry
compatibility and enhanced query/filter capabilities
- `task_id` field to the `AgentSpanBuilder` struct and corresponding
builder method for consistent span construction
- Internal helper function `resolve_operation_id_from_env` in agent loop
runner to reliably extract operation ID from environment variables

**Changed:**

- Refactored agent loop runner (`ares-llm/src/agent_loop/runner.rs`) to
nest all agent task execution under a parent span containing `op.id` and
`task.id`
- Updated span creation in milestones, tool execution, and
decision-making to include both operation and task identifiers
- Modified span builder and helper functions
(`ares-core/src/telemetry/spans/builder.rs`, `helpers.rs`) to accept and
propagate the new identifiers as needed
- Updated test cases in span module to verify presence of new attributes
in spans

- Updated GitHub Actions workflows to use the latest versions of
`actions/upload-artifact` and `actions/setup-go`
- Updated Semgrep workflow to use a new container image version for
improved security and compatibility

---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant