Feature: Add sessionID to experimental.chat.system.transform hook for tracing integration #3851

Open
opened 2026-02-16 17:41:41 -05:00 by yindo · 2 comments
Owner

Originally created by @ramarivera on GitHub (Dec 24, 2025).

Originally assigned to: @rekram1-node on GitHub.

Summary

When building observability plugins (e.g., Langfuse, OpenTelemetry exporters), it's valuable to capture the full system prompt for each LLM request and associate it with the correct trace/session. The experimental.chat.system.transform hook provides access to the system prompt, but currently lacks the sessionID needed to correlate it with a specific session.

Current Behavior

In packages/opencode/src/session/llm.ts line ~65:

await Plugin.trigger("experimental.chat.system.transform", {}, { system })

The input object is empty {}, so plugins cannot determine which session the system prompt belongs to.

Proposed Change

Pass the sessionID in the input:

await Plugin.trigger("experimental.chat.system.transform", { sessionID: input.sessionID }, { system })

And update the type definition in packages/plugin/src/index.ts:

"experimental.chat.system.transform"?: (
  input: { sessionID: string },
  output: { system: string[] },
) => Promise<void>

Use Case

This enables tracing plugins to:

  1. Capture the full system prompt (including environment context, file tree, custom instructions)
  2. Associate it with the correct Langfuse trace or OpenTelemetry span
  3. Provide complete observability into what context the LLM received

Additional Context

I'm building a Langfuse exporter plugin for OpenCode. Currently I can capture:

  • Session events
  • User messages with content
  • Assistant responses with token usage
  • Tool calls with input/output

But the system prompt is missing from traces, which makes debugging and analysis incomplete.


Note: Similar issues were searched before filing. This report was created with AI assistance.

Originally created by @ramarivera on GitHub (Dec 24, 2025). Originally assigned to: @rekram1-node on GitHub. ## Summary When building observability plugins (e.g., Langfuse, OpenTelemetry exporters), it's valuable to capture the full system prompt for each LLM request and associate it with the correct trace/session. The `experimental.chat.system.transform` hook provides access to the system prompt, but currently lacks the `sessionID` needed to correlate it with a specific session. ## Current Behavior In `packages/opencode/src/session/llm.ts` line ~65: ```typescript await Plugin.trigger("experimental.chat.system.transform", {}, { system }) ``` The input object is empty `{}`, so plugins cannot determine which session the system prompt belongs to. ## Proposed Change Pass the `sessionID` in the input: ```typescript await Plugin.trigger("experimental.chat.system.transform", { sessionID: input.sessionID }, { system }) ``` And update the type definition in `packages/plugin/src/index.ts`: ```typescript "experimental.chat.system.transform"?: ( input: { sessionID: string }, output: { system: string[] }, ) => Promise<void> ``` ## Use Case This enables tracing plugins to: 1. Capture the full system prompt (including environment context, file tree, custom instructions) 2. Associate it with the correct Langfuse trace or OpenTelemetry span 3. Provide complete observability into what context the LLM received ## Additional Context I'm building a Langfuse exporter plugin for OpenCode. Currently I can capture: - Session events - User messages with content - Assistant responses with token usage - Tool calls with input/output But the system prompt is missing from traces, which makes debugging and analysis incomplete. --- *Note: Similar issues were searched before filing. This report was created with AI assistance.*
Author
Owner

@github-actions[bot] commented on GitHub (Dec 24, 2025):

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

  • #219: Feature Request: Add Langfuse Tracing - This issue is about integrating Langfuse for tracing/observability in OpenCode, which is directly related to your use case of building a Langfuse exporter plugin.

Feel free to ignore if this doesn't address your specific case.

@github-actions[bot] commented on GitHub (Dec 24, 2025): This issue might be a duplicate of existing issues. Please check: - #219: Feature Request: Add Langfuse Tracing - This issue is about integrating Langfuse for tracing/observability in OpenCode, which is directly related to your use case of building a Langfuse exporter plugin. Feel free to ignore if this doesn't address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Dec 25, 2025):

sure pr welcome!

@rekram1-node commented on GitHub (Dec 25, 2025): sure pr welcome!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3851