feat(run): add UserTraceContext to RunConfig for backend-agnostic trace attribution#278
Open
dev-elie wants to merge 7 commits into
Open
feat(run): add UserTraceContext to RunConfig for backend-agnostic trace attribution#278dev-elie wants to merge 7 commits into
dev-elie wants to merge 7 commits into
Conversation
…tribution
- Add UserTraceContext type { userId?, groups? } to RunConfig
- Store user on Run instance
- Use userId (falling back to configurable.user_id) in both agent and title Langfuse traces
- Append group:<name> tags from user.groups in both trace points
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…back When RunConfig.user is not provided by the host (e.g. older LibreChat versions that predate the companion PR), fall back to the user identity already present in config.configurable.user (the LibreChat safe-user object). This makes user/group attribution work end-to-end without requiring a LibreChat upgrade. - Extract resolveConfigurableUserId() helper that reads LIBRECHAT_TRACE_USER_ID_FIELD env var (email | username | name | id) to pick which field to use as the trace userId; defaults to email. - Resolve userGroups from configurable.user.groups when RunConfig.user.groups is absent. - Apply the same fallback logic to the title trace. The explicit RunConfig.user.userId / .groups values always take precedence over the configurable fallback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5abbcbd to
f7062ea
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…erId When LIBRECHAT_TRACE_USER_ID_FIELD is unset (default 'email' path) and no configurable.user object is present, rawUserId (the legacy configurable.user_id string) was silently dropped, causing userId to be undefined in propagateAttributes. All non-identity-field paths now carry rawUserId as the terminal fallback, restoring backward compat with callers that still pass user_id directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Also see: danny-avila/LibreChat#13529 (comment)
Adds
UserTraceContext { userId? }toRunConfigso hosts can pass a human-readable user identifier to all configured trace backends (Langfuse, LangSmith, OTel, etc.) from a single place, rather than each backend re-deriving the same mapping.When
RunConfig.useris not set, the SDK falls back to resolving the userId from fields already present inconfig.configurable— so the improvement works without requiring a host upgrade.Breaking Change
Traces that previously showed a raw
user_idstring (e.g. a MongoDB ObjectId) fromconfigurable.user_idwill now show the user's email by default. SetLIBRECHAT_TRACE_USER_ID_FIELD=idto preserve the old behaviour.How to test
userId(email by default) instead of a raw ObjectId.LIBRECHAT_TRACE_USER_ID_FIELD=name(orusername/id) and restart — verify the correct field appears.npm testCompanion PR
danny-avila/LibreChat#14012 — wires
buildUserTraceContext(user)intocreateRunand addstracing.userIdFieldto thelibrechat.yamlconfig schema🤖 Generated with Claude Code