Integration of Langfuse has bugs #5681

Closed
opened 2026-02-21 18:12:09 -05:00 by yindo · 6 comments
Owner

Originally created by @LiHongYan666 on GitHub (Sep 19, 2024).

Originally assigned to: @ZhouhaoJiang on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.12

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Monitoring the integration of external Ops tools, there are bugs in the integration of Langfuse, see details:https://github.com/langfuse/langfuse/issues/2700

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @LiHongYan666 on GitHub (Sep 19, 2024). Originally assigned to: @ZhouhaoJiang on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.12 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Monitoring the integration of external Ops tools, there are bugs in the integration of Langfuse, see details:https://github.com/langfuse/langfuse/issues/2700 ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:12:09 -05:00
yindo closed this issue 2026-02-21 18:12:09 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 19, 2024):

I found a similar unsolved discussion that might be relevant to your issue: Started with Local Source Code, made sure langSmith is connected properly, but log traces not printing upon adding to langsmith_trace.py, which was last updated on 2024-08-21 [1].

Additionally, here are some key points and steps to ensure the integration of Langfuse with Dify is correctly configured:

  1. Creating a Project in Langfuse:

    • Register and log in to Langfuse at Langfuse website.
    • Create a new project in Langfuse by clicking New on the homepage. This project will be used for data monitoring in Dify.
    • Edit a name for the project.
  2. Generating API Keys in Langfuse:

    • In the Langfuse project, navigate to Settings in the left sidebar.
    • Click Create API Keys to generate the project API credentials.
    • Copy and save the Secret Key, Public Key, and Host.
  3. Configuring Langfuse in Dify:

    • Open the Dify app and navigate to the monitoring settings of the application you want to monitor.
    • Open Monitoring in the side menu and select Tracing app performance on the page.
    • Click Configure and enter the Secret Key, Public Key, and Host obtained from Langfuse.
    • Save the configuration.
    • Once successfully saved, you can view the status on the current page. If it shows as started, it is being monitored.
  4. Viewing Monitoring Data in Langfuse:

    • After configuration, you can view the monitoring data from Dify in Langfuse. This includes debugging and production data [2][3][4].

For logging and debugging, ensure that the logger is used to log debug messages at various points in the code, such as when traces, spans, and generations are created successfully or when exceptions occur. Here are some examples from the code:

def add_trace(self, langfuse_trace_data: Optional[LangfuseTrace] = None):
    format_trace_data = filter_none_values(langfuse_trace_data.model_dump()) if langfuse_trace_data else {}
    try:
        self.langfuse_client.trace(**format_trace_data)
        logger.debug("LangFuse Trace created successfully")
    except Exception as e:
        raise ValueError(f"LangFuse Failed to create trace: {str(e)}")

def add_span(self, langfuse_span_data: Optional[LangfuseSpan] = None):
    format_span_data = filter_none_values(langfuse_span_data.model_dump()) if langfuse_span_data else {}
    try:
        self.langfuse_client.span(**format_span_data)
        logger.debug("LangFuse Span created successfully")
    except Exception as e:
        raise ValueError(f"LangFuse Failed to create span: {str(e)}")

def add_generation(self, langfuse_generation_data: Optional[LangfuseGeneration] = None):
    format_generation_data = (
        filter_none_values(langfuse_generation_data.model_dump()) if langfuse_generation_data else {}
    )
    try:
        self.langfuse_client.generation(**format_generation_data)
        logger.debug("LangFuse Generation created successfully")
    except Exception as e:
        raise ValueError(f"LangFuse Failed to create generation: {str(e)}")

These log messages and the detailed monitoring data can help in identifying and diagnosing issues with the Langfuse integration [5][3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 19, 2024): <!-- Answer --> I found a similar unsolved discussion that might be relevant to your issue: [Started with Local Source Code, made sure langSmith is connected properly, but log traces not printing upon adding to langsmith_trace.py](https://github.com/langgenius/dify/discussions/7462), which was last updated on 2024-08-21 <sup>[[1]](https://github.com/langgenius/dify/discussions/7462)</sup>. Additionally, here are some key points and steps to ensure the integration of Langfuse with Dify is correctly configured: 1. **Creating a Project in Langfuse**: - Register and log in to Langfuse at [Langfuse website](https://langfuse.com/). - Create a new project in Langfuse by clicking **New** on the homepage. This project will be used for data monitoring in Dify. - Edit a name for the project. 2. **Generating API Keys in Langfuse**: - In the Langfuse project, navigate to **Settings** in the left sidebar. - Click **Create API Keys** to generate the project API credentials. - Copy and save the `Secret Key`, `Public Key`, and `Host`. 3. **Configuring Langfuse in Dify**: - Open the Dify app and navigate to the monitoring settings of the application you want to monitor. - Open **Monitoring** in the side menu and select **Tracing app performance** on the page. - Click **Configure** and enter the `Secret Key`, `Public Key`, and `Host` obtained from Langfuse. - Save the configuration. - Once successfully saved, you can view the status on the current page. If it shows as started, it is being monitored. 4. **Viewing Monitoring Data in Langfuse**: - After configuration, you can view the monitoring data from Dify in Langfuse. This includes debugging and production data <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/jp/guides/monitoring/integrate-external-ops-tools/integrate-langfuse.md)</sup><sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/monitoring/integrate-external-ops-tools/integrate-langfuse.md)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/en/guides/monitoring/integrate-external-ops-tools/integrate-langfuse.md)</sup>. For logging and debugging, ensure that the `logger` is used to log debug messages at various points in the code, such as when traces, spans, and generations are created successfully or when exceptions occur. Here are some examples from the code: ```python def add_trace(self, langfuse_trace_data: Optional[LangfuseTrace] = None): format_trace_data = filter_none_values(langfuse_trace_data.model_dump()) if langfuse_trace_data else {} try: self.langfuse_client.trace(**format_trace_data) logger.debug("LangFuse Trace created successfully") except Exception as e: raise ValueError(f"LangFuse Failed to create trace: {str(e)}") def add_span(self, langfuse_span_data: Optional[LangfuseSpan] = None): format_span_data = filter_none_values(langfuse_span_data.model_dump()) if langfuse_span_data else {} try: self.langfuse_client.span(**format_span_data) logger.debug("LangFuse Span created successfully") except Exception as e: raise ValueError(f"LangFuse Failed to create span: {str(e)}") def add_generation(self, langfuse_generation_data: Optional[LangfuseGeneration] = None): format_generation_data = ( filter_none_values(langfuse_generation_data.model_dump()) if langfuse_generation_data else {} ) try: self.langfuse_client.generation(**format_generation_data) logger.debug("LangFuse Generation created successfully") except Exception as e: raise ValueError(f"LangFuse Failed to create generation: {str(e)}") ``` These log messages and the detailed monitoring data can help in identifying and diagnosing issues with the Langfuse integration <sup>[[5]](https://github.com/langgenius/dify/blob/main/api/core/ops/langfuse_trace/langfuse_trace.py)</sup><sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/monitoring/integrate-external-ops-tools/integrate-langfuse.md)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/en/guides/monitoring/integrate-external-ops-tools/integrate-langfuse.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@ZhouhaoJiang commented on GitHub (Sep 22, 2024):

@LiHongYan666 Please update the latest Dify version, this problem has been fixed in #7306 .

@ZhouhaoJiang commented on GitHub (Sep 22, 2024): @LiHongYan666 Please update the latest Dify version, this problem has been fixed in #7306 .
Author
Owner

@zolgear commented on GitHub (Sep 23, 2024):

Last week, I confirmed that the cost for Azure OpenAI GPT-4o was not being properly counted in the latest version. I believe we need to investigate the cause.

Dify v0.8.2
Langfuse v2.79.0

@zolgear commented on GitHub (Sep 23, 2024): Last week, I confirmed that the cost for Azure OpenAI GPT-4o was not being properly counted in the latest version. I believe we need to investigate the cause. Dify v0.8.2 Langfuse v2.79.0
Author
Owner

@marcklingen commented on GitHub (Sep 23, 2024):

-- Langfuse maintainer here

I'm happy to help figure this out. Generally token counts can be logged to langfuse directly which makes cost analysis the most reliable in langfuse. see docs page here for details: https://langfuse.com/docs/model-usage-and-cost

@marcklingen commented on GitHub (Sep 23, 2024): -- Langfuse maintainer here I'm happy to help figure this out. Generally token counts can be logged to langfuse directly which makes cost analysis the most reliable in langfuse. see docs page here for details: https://langfuse.com/docs/model-usage-and-cost
Author
Owner

@zolgear commented on GitHub (Sep 23, 2024):

Sorry, the cost was being counted correctly!
(Dify 0.8.2 / Langufuse 2.81.0)

Tokens are counted immediately.
The cost could be confirmed on the Langufuse dashboard after 24 hours.

@zolgear commented on GitHub (Sep 23, 2024): Sorry, the cost was being counted correctly! (Dify 0.8.2 / Langufuse 2.81.0) Tokens are counted immediately. The cost could be confirmed on the Langufuse dashboard after 24 hours.
Author
Owner

@marcklingen commented on GitHub (Nov 4, 2024):

great, thanks for confirming!

@marcklingen commented on GitHub (Nov 4, 2024): great, thanks for confirming!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5681