Repository navigation
Conversation
LANGFUSE_USER_ID attributes every trace of an OpenCode process to one user, which is wrong when a single `opencode serve` hosts sessions for several people. Read `userId` from the session metadata. A non-empty string is set as `langfuse.user.id` on every span of that session and takes precedence over the process-wide user, which still applies to sessions without it. Child agent sessions inherit their parent's user. The metadata comes from OpenCode's session events. A session the plugin has not seen an event for, such as one continued after a restart, is read from OpenCode before its first span starts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
geoff-ux
marked this pull request as draft
October 1, 2026 23:32
|
|
Author
|
Closing this for now. Our own review found that the patch reads the session from OpenCode inside hooks that OpenCode waits on, which is not something telemetry should do, and we'd rather rework it than ask for your time on this version. The request itself stands in https://github.com/orgs/langfuse/discussions/18148. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A session's Langfuse user can now come from the session itself. When an OpenCode session's
metadata.userIdis a non-empty string, it is set aslangfuse.user.idon every span of that session.Idea and discussion: https://github.com/orgs/langfuse/discussions/18148
Why
LANGFUSE_USER_IDis applied to every span the process exports. Underopencode serve, one process hosts sessions for several people, so every trace is filed under one user, or under none.Behaviour
metadata.userIdkeep usingLANGFUSE_USER_ID, so existing setups are unchanged and there is no new configuration.How
src/langfuse.ts: a span processor, registered after the process-wide one, setslangfuse.user.idfrom the span's session, walking up to parent sessions. The trace state keeps one entry per known session.src/v1.ts,src/v2.ts: remember the user from session events, and read a session not yet seen before tracing its first span.src/schema.ts: the pinned@opencode-ai/pluginSessiontype omitsmetadata, which OpenCode includes in its session events, so it is decoded with a small schema.README.md: a "Per-Session User" section.Testing
pnpm run format:check,build,lint,knipandtest:integrationpass (49 tests, 14 of them new).opencode serve1.18.32 with two sessions created with differentmetadata.userId: every exported span carried its own session's user.Notes for review
session.getper session and turn at most, and none for sessions announced by an event.馃 Generated with Claude Code