Fix tool spans not being exported to tracing backend#97
Conversation
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>
📝 WalkthroughWalkthroughAuditLogger now accepts an explicit OpenTelemetry parent context, uses it when creating ChangesAudit tracing context wiring
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@pavolloffay: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
Summary
AuditLoggerwere not appearing in Tempo/Jaegerstart_span()called without explicitcontext=parameter in async codeChanges
set_parent_context()method toAuditLoggerto store the parent contextstart_span()when creating tool spanstool.name,tool.input(truncated 300 chars),tool.output(truncated 500 chars) attributesOKon successful tool resultset_parent_context()fromquery.pyinside theagent.runspan blockResult
Tool spans are now correctly parented under
agent.run:Test plan
ghcr.io/pavolloffay/lightspeed-agentic-sandbox:tracing-fixto clustertool.name,tool.input,tool.output) are populatedBefore:

After:
🤖 Generated with Claude Code