Skip to content

Fix tool spans not being exported to tracing backend#97

Open
pavolloffay wants to merge 2 commits into
openshift:mainfrom
pavolloffay:fix-tool-span-parenting
Open

Fix tool spans not being exported to tracing backend#97
pavolloffay wants to merge 2 commits into
openshift:mainfrom
pavolloffay:fix-tool-span-parenting

Conversation

@pavolloffay

@pavolloffay pavolloffay commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Tool spans created in AuditLogger were not appearing in Tempo/Jaeger
  • Root cause: start_span() called without explicit context= parameter in async code
  • OTEL context is not automatically propagated when spans are created inside async generators

Changes

  • Add set_parent_context() method to AuditLogger to store the parent context
  • Pass explicit context to start_span() when creating tool spans
  • Add tool.name, tool.input (truncated 300 chars), tool.output (truncated 500 chars) attributes
  • Set span status to OK on successful tool result
  • Call set_parent_context() from query.py inside the agent.run span block

Result

Tool spans are now correctly parented under agent.run:

proposal.lifecycle
└── proposal.analyze
    └── agent.run
        └── tool.exec_command  (now properly nested)

Test plan

  • Deployed image ghcr.io/pavolloffay/lightspeed-agentic-sandbox:tracing-fix to cluster
  • Created test proposals with tool calls
  • Verified tool spans appear in Tempo with correct parent-child relationships
  • Verified span attributes (tool.name, tool.input, tool.output) are populated

Before:
image

After:

image

🤖 Generated with Claude Code

Tool spans created in AuditLogger were not appearing in Tempo because
start_span() was called without an explicit context parameter. In Python
async code, OTEL context is not automatically propagated when spans are
created inside async generators.

Changes:
- Add set_parent_context() method to AuditLogger to store the parent context
- Pass explicit context to start_span() when creating tool spans
- Add tool.name, tool.input (300 chars), tool.output (500 chars) attributes
- Set span status to OK on successful tool result
- Call set_parent_context() from query.py inside the agent.run span block

This ensures tool spans are correctly parented under agent.run:

proposal.lifecycle
└── proposal.analyze
    └── agent.run
        └── tool.exec_command  (now properly nested)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

AuditLogger now accepts an explicit OpenTelemetry parent context, uses it when creating tool.* spans, and records tool input/output with span status updates. The query route now passes the active OpenTelemetry context into the audit logger during agent.run.

Changes

Audit tracing context wiring

Layer / File(s) Summary
Logger context and tool span attributes
src/lightspeed_agentic/audit.py
Imports Context and StatusCode, initializes _parent_context, emits audit.agent.started, adds set_parent_context(ctx), and records tool input/output plus span status on tool.* spans.
Route context handoff
src/lightspeed_agentic/routes/query.py
Imports opentelemetry.context and calls audit_logger.set_parent_context(otel_context.get_current()) inside the agent.run span.

Sequence Diagram(s)

sequenceDiagram
  participant QueryRoute
  participant AuditLogger
  participant Tracer

  QueryRoute->>Tracer: start agent.run span
  QueryRoute->>AuditLogger: set_parent_context(current context)
  AuditLogger->>Tracer: emit audit.agent.started
  AuditLogger->>Tracer: start tool.* span with parent context
  AuditLogger->>Tracer: add tool.name, tool.input, tool.output
  AuditLogger->>Tracer: set StatusCode.OK
  AuditLogger->>Tracer: end tool span
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: fixing tool span export by adding explicit parent context.
Description check ✅ Passed The description aligns with the code changes and explains the tracing fix, attributes, and parent context.

Comment @coderabbitai help to get the list of available commands.

@openshift-ci openshift-ci Bot requested review from joshuawilson and raptorsun July 6, 2026 16:09
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xrajesh for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown

@pavolloffay: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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