feat(observability): Implement OTel telemetry parity for agents and tools - #34633
feat(observability): Implement OTel telemetry parity for agents and tools#34633Starefossen wants to merge 3 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: I found one potentially related PR that should be reviewed: Related PR: Why it's related: This PR also covers OpenTelemetry integration. It may be addressing similar observability goals or could be an earlier approach to the same feature. You should verify whether #5245 is already merged, stale, or covers different scope than the agent/tool instrumentation in PR #34633. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Supersedes #5245
Type of change
What does this PR do?
(Note: This PR supersedes #5245. While OTel was previously implemented in the codebase, granular agent and tool metrics were still missing.)
OpenCode lacked granular observability into agent actions and tool usage compared to other popular AI clients. Without standardized metrics for these events, it was difficult to debug failing agent interactions or build robust dashboards for tool success rates.
This PR implements telemetry parity by bringing the agent and tool instrumentation in line with the official OpenTelemetry Generative AI Semantic Conventions (
gen_ai.*).Specifically, this implements:
SessionProcessorto emit theagentTurnCountmetric. It aligns with the OTel spec by capturing logicalgen_ai.operation.name="invoke_agent"turns while correctly ignoring internal context-window compactions to prevent metric inflation.tools.tsto capturetoolCallCountTotalandtoolCallDurationSeconds. This accurately tracks execution times and leverages standard OTel attributes likeerror.typeand success states, providing granular visibility into infrastructure vs. logical tool failures.How did you verify your code works?
mise checkpipeline.Screenshots / recordings
N/A (Backend / Observability change)
Checklist
Implemented with the help of Antigravity CLI (Gemini 3.1 Pro High)