Skip to content

[Question] detailed per-interaction telemetry (token counts and input composition) for opencode-model communications #2666

Closed

Description

@m1pro

I’d like opencode to provide detailed telemetry for each interaction with the model so I can see exactly what is sent and received. Specifically:
Per-request and per-response token counts.
A breakdown of the input composition (prompt/system/instructions/user messages, tool calls, agent/subagent messages, and any injected context).
Visibility into response tokens and any truncation or context-window warnings.
Option to enable/disable verbose logging and to redact sensitive user content. This will help tune agents/subagents and manage context size to reduce costs and avoid hitting token limits.
Priority: Medium — useful for debugging and cost optimization.
Possible implementation notes: expose structured logs or a debug mode that outputs a JSON telemetry object per interaction with fields such as total_tokens, prompt_tokens, completion_tokens, messages[], truncated (bool), and redaction markers.

From what I've check the current logs (even in debug mode) don't include all information.
Is this mode already supported ?

Activity

  1. github-actions commented on Sep 18, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. m1pro commented on Sep 18, 2025

    @m1pro
    Author

    I've tried to experiment with code myself for now. The payload that I dump contains for example ~11K words. the token count on the other hand that I see on opencode zen is ~20K. So if anyone can tell me what else should be added to the payload that I'm missing ....
    (i used opencode qwen3 coder model)

    here a link to the change set:
    m1pro@db15b5f

    it creates a session folder in /Users/user/.local/share/opencode/session-payloads.
    each interaction dumps the payload in a 'human-readable' markdown format and also the raw payload as json.

    would appreciate your comments.

  3. rekram1-node commented on Sep 18, 2025

    @rekram1-node
    Collaborator

    We already track tokens in, out, cached etc for every interaction we just don't show all of them currently but it makes sense to have the option

    things like that breakdown would require changes

    We do need a better way to allow people to see their sessions outside of the tui either in markdown or in json, there is a /export command to get a markdown file but it doesn't include the token data you are thinking about

  4. philipp-heinrich commented on Oct 20, 2025

    @philipp-heinrich
  5. rekram1-node commented on Oct 20, 2025

    @rekram1-node
    Collaborator

    We had it at one point but it was causing issues, there are a few more pressing items that are taking priority before adding it back again

  6. Raviguntakala commented on Nov 10, 2025

    @Raviguntakala
    Contributor

    We had it at one point but it was causing issues, there are a few more pressing items that are taking priority before adding it back again

    Hey, just wondering if this feature is planned to be implemented anytime soon or if it’s still in discussion?

  7. rekram1-node commented on Nov 10, 2025

    @rekram1-node
    Collaborator

    @Raviguntakala you need open telemetry? I don't think it is high on our priority list atm but maybe you can tell your usecase

  8. Raviguntakala commented on Nov 11, 2025

    @Raviguntakala
    Contributor

    @Raviguntakala you need open telemetry? I don't think it is high on our priority list atm but maybe you can tell your usecase

    Yeah, mainly for tracking token consumption and cost monitoring across multiple APIs. Having OpenTelemetry support would make it easier to analyze usage patterns and optimize context size when tuning agents and subagents.

  9. jeantil commented on Dec 10, 2025

    @jeantil

    PR #4978 allows to enable the AI SDK opentelemetry support but this seems to only cover spans.

    This PR seems to add metrics to AI SDK OTEL export but will need additional code on opencode's side to enable.

  10. Ray0907 commented on Dec 13, 2025

    @Ray0907

    Hey @jeantil
    Is there anything else I need to add or change on the opencode side to enable this feature? Happy to make any necessary updates.

  11. jeantil commented on Dec 13, 2025

    @jeantil

    @Ray0907 not yet on open code side, once this vercel/ai PR it will send metrics automatically if otel is enabled.
    Opencode will probably want to replicate the recordMetrics configuration flag added in ai in its own configuration. It should be possible to control what is exported by OTEL using the otel exporter environment variable but a config flag is easier to discover for newcomers. Either that or adding the a bit more information to opencode's telemetry flag documentation once ai is udpated to a version which sends metrics would be good.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions