Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two unexpected traces sent to LangFuse #6746

Open
tianzhipeng-git opened this issue Feb 21, 2025 · 2 comments
Open

Two unexpected traces sent to LangFuse #6746

tianzhipeng-git opened this issue Feb 21, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tianzhipeng-git
Copy link
Contributor

tianzhipeng-git commented Feb 21, 2025

Bug Description

Issue:

When the LANGFUSE-related env variables are configured, executing a flow with only a single agent sends three traces to Langfuse, two of which are not controlled by Langflow code. (This is particularly problematic as I'm currently working on a PR to submit meta information like session_id/user_id in the trace.)

Image

Image

Cause Analysis:

Langfuse provides a drop-in replacement for the OpenAI package, which monkey patches OpenAI's model invocation functions and reads LANGFUSE-related environment variables.

But in Langflow, we didn't enable this feature. I traced the call stack and found that in the dspy package, the openai module is arbitrarily patched (using the drop-in trick of langfuse), causing unexpected traces to be sent to Langfuse, which aren't controlled by our src/backend/base/langflow/services/tracing/langfuse.py.

call_stack here:

Image

full traceback stack.log

Suggested Solution:

  1. Modify langflow/services/tracing/langwatch.py to prevent setup_langwatch from being called if the LANGWATCH configuration is absent (the issue stems from dspy being imported in langwatch's initialization).
  2. If Langflow doesn't require dspy (I couldn't find any usage of it in the code), why not remove it entirely?
  3. Consider submitting a modification suggestion to the maintainers of dspy, though it may not necessarily be accepted.

For option 1, I could help submit a PR. However, someone needs to confirm this solution.

Reproduction

  1. ADD LANGFUSE_HOST and keys to env
  2. create a flow with a simple agent, run
  3. three trace shows in langfuse

Expected behavior

how to solve it

Who can help?

@italojohnny

Operating System

macos

Langflow Version

1.1.4

Python Version

3.12

Screenshot

No response

Flow File

simple_agent.json

@tianzhipeng-git tianzhipeng-git added the bug Something isn't working label Feb 21, 2025
Copy link

dosubot bot commented Feb 21, 2025

The issue you're encountering seems to be related to the dspy package, which is causing unexpected traces to be sent to Langfuse due to its integration with the OpenAI package. Here are some steps you can consider to address this:

  1. Modify langwatch.py: You can adjust the langflow/services/tracing/langwatch.py file to ensure that setup_langwatch is not called if the LANGWATCH configuration is absent. This could prevent the unintended behavior caused by the dspy package during initialization.

  2. Evaluate the Necessity of dspy: If dspy is not essential for Langflow's core functionality, consider removing it from the dependencies. According to the pyproject.toml, the dspy package itself is not listed, but dspy-ai is included [1].

  3. Submit a PR: If you are confident in the solution, you can submit a pull request to implement the changes in langwatch.py. This would require confirmation from the maintainers or contributors to ensure it aligns with the project's goals.

  4. Contact dspy Maintainers: If the issue persists and is directly related to dspy, consider reaching out to its maintainers with a suggestion to modify the behavior. However, this might not be accepted, so it's a secondary option.

These steps should help mitigate the issue of unexpected traces being sent to Langfuse.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@tianzhipeng-git
Copy link
Contributor Author

tianzhipeng-git commented Feb 21, 2025

#6749
create a small pr

@italojohnny italojohnny self-assigned this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants