Description
When a user sends a message to an existing session (one that was created before the current plugin process started), the session.created event never fires for that session. The sessionTotals Map — which tracks per-session agent, token, and cost metadata — therefore has no entry for that session.
The chat.message hook receives the correct input.agent from the user's request, but only mutates an existing sessionTotals entry; it does not create one when absent. As a result, all subsequent event handlers fall through to "unknown".
This affects all OTel signals that carry agent attributes:
Prometheus metrics: opencode_token_usage_tokens_total, opencode_message_count_total, opencode_model_usage_total, opencode_cache_count_total, opencode_cost_usage_total, opencode_session_token_total, opencode_session_cost_total
Loki logs: agent, agent.name, agent.type fields
Tempo traces: agent.name, agent.type span attributes
Steps to reproduce
- Start
opencode and send several messages to create a session
- Restart
opencode (or the plugin process)
- Continue the existing session by sending a new message
- Export telemetry via the plugin to any OTLP backend (e.g., Grafana Alloy + Prometheus/Loki/Tempo)
- Observe that all agent-related labels/attributes for this session's metrics, logs, and traces show "unknown" instead of the correct agent name (e.g., "build")
Expected behavior
When a user message is sent to an existing session, the agent attribute in all telemetry signals should reflect the actual agent name from the request (e.g., "build", "plan", "explore").
Actual behavior
Agent attributes are reported as "unknown" for messages sent to sessions that existed before the current plugin process started.
Plugin version
v1.2.0 (latest)
Configuration
N/A
Relevant log output
Checklist
Description
When a user sends a message to an existing session (one that was created before the current plugin process started), the
session.createdevent never fires for that session. ThesessionTotals Map— which tracks per-session agent, token, and cost metadata — therefore has no entry for that session.The
chat.messagehook receives the correctinput.agentfrom the user's request, but only mutates an existingsessionTotalsentry; it does not create one when absent. As a result, all subsequent event handlers fall through to "unknown".This affects all OTel signals that carry agent attributes:
Prometheus metrics:
opencode_token_usage_tokens_total,opencode_message_count_total,opencode_model_usage_total,opencode_cache_count_total,opencode_cost_usage_total,opencode_session_token_total,opencode_session_cost_totalLoki logs:
agent,agent.name,agent.typefieldsTempo traces:
agent.name,agent.typespan attributesSteps to reproduce
opencodeand send several messages to create a sessionopencode(or the plugin process)Expected behavior
When a user message is sent to an existing session, the
agentattribute in all telemetry signals should reflect the actual agent name from the request (e.g., "build", "plan", "explore").Actual behavior
Agent attributes are reported as "unknown" for messages sent to sessions that existed before the current plugin process started.
Plugin version
v1.2.0 (latest)
Configuration
N/A
Relevant log output
Checklist