Skip to content

✨ feat(langfuse): add LANGFUSE_TRACE_DATA support for trace field map…#13375

Open
WindSpiritSR wants to merge 1 commit intolobehub:canaryfrom
WindSpiritSR:feat/langfuse-custom-trace-payload
Open

✨ feat(langfuse): add LANGFUSE_TRACE_DATA support for trace field map…#13375
WindSpiritSR wants to merge 1 commit intolobehub:canaryfrom
WindSpiritSR:feat/langfuse-custom-trace-payload

Conversation

@WindSpiritSR
Copy link
Copy Markdown
Contributor

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

Related to observability and Langfuse trace metadata customization.

🔀 Description of Change

This PR adds support for LANGFUSE_TRACE_DATA to control how user fields are mapped into Langfuse trace fields.

  • Added LANGFUSE_TRACE_DATA parsing in Langfuse env config
  • Added mapping support for userId field values
    • userId:userId (default)
    • userId:email
  • Updated docs
    • Langfuse observability setup
    • analytics environment variable reference
    • documented format, defaults, and examples for LANGFUSE_TRACE_DATA

🧪 How to Test

Validation scenarios:

  • Default behavior without LANGFUSE_TRACE_DATA uses userId:userId

  • LANGFUSE_TRACE_DATA=userId:email maps trace userId to user email when available

  • Invalid values (for example userId:unknown_field) fall back to userId:userId

  • Tested locally

  • Added/updated tests

  • No tests needed

📸 Screenshots / Videos

Before After
image image

📝 Additional Information

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

@WindSpiritSR is attempting to deploy a commit to the LobeHub OSS Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@lobehubbot
Copy link
Copy Markdown
Member

@nekomeowww @tjx666 - This PR adds LANGFUSE_TRACE_DATA support for Langfuse trace field mapping, touching backend API, env config, trace module, and self-hosting docs. Please coordinate on review.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cdbbef9a3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

};

const originalUserId = traceData?.userId ?? tracePayload?.userId;
const traceUserId = traceDataMap[LANGFUSE_TRACE_DATA.userId] ?? originalUserId;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fallback to original userId when mapped value is empty

When LANGFUSE_TRACE_DATA is set to map userId from email, the expression traceDataMap[LANGFUSE_TRACE_DATA.userId] ?? originalUserId treats an empty string as a valid value. In deployments with legacy or imported users that have email: '', this sends a blank Langfuse userId instead of falling back to the original ID, which breaks trace attribution and contradicts the documented "empty value falls back" behavior.

Useful? React with 👍 / 👎.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 76.59574% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.95%. Comparing base (966f943) to head (0cdbbef).
⚠️ Report is 1 commits behind head on canary.

Additional details and impacted files
@@           Coverage Diff           @@
##           canary   #13375   +/-   ##
=======================================
  Coverage   66.94%   66.95%           
=======================================
  Files        1903     1903           
  Lines      153684   153724   +40     
  Branches    15534    15539    +5     
=======================================
+ Hits       102889   102927   +38     
- Misses      50675    50677    +2     
  Partials      120      120           
Flag Coverage Δ
app 58.53% <76.59%> (+0.01%) ⬆️
database 96.66% <ø> (ø)
packages/agent-runtime 89.61% <ø> (ø)
packages/context-engine 86.47% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 66.68% <ø> (ø)
packages/model-bank 99.85% <ø> (ø)
packages/model-runtime 84.44% <ø> (ø)
packages/prompts 67.76% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.41% <ø> (ø)
packages/web-crawler 88.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 67.29% <ø> (ø)
Services 49.30% <ø> (ø)
Server 67.26% <9.09%> (-0.01%) ⬇️
Libs 51.03% <ø> (ø)
Utils 91.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants