Skip to content

Langfuse: message_trace generations dropped (no cost/latency) for Chatbot/Agent/Completion apps since 1.14.0 — generation created without an observation id #37824

Closed

Description

@RazmikGevorgyan

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.14.2 (root cause also present on main; latest commit to the affected file at time of writing: f15a8f02e)

Cloud or Self Hosted

Self Hosted (Docker / Kubernetes)

Steps to reproduce

  1. Self-host Dify 1.14.x.
  2. Create any non-workflow app — a Chatbot (basic or Agent mode) or a Completion app.
  3. Enable Langfuse tracing for that app (Monitoring → Tracing → Langfuse; public key, secret key, host).
  4. Send a chat message so a message record is produced.
  5. Open the resulting trace in Langfuse.

✔️ Expected Behavior

The trace contains an llm generation observation carrying model + token usage, so Langfuse computes cost and latency — the same way Workflow / Advanced-Chat (chatflow) apps do.

❌ Actual Behavior

The trace has only the top-level message node — no child generation. Token counts appear only as plain fields inside the trace input payload (message_tokens, answer_tokens), not as a generation's usage. Because there is no generation observation, Total Cost is blank and Latency shows 0.00s. Workflow / Advanced-Chat (chatflow) apps are not affected.


Root cause

File: api/providers/trace/trace-langfuse/src/dify_trace_langfuse/langfuse_trace.py

message_trace() creates the trace (with id=trace_id) and then an llm generation — but the generation is built without an id:

langfuse_generation_data = LangfuseGeneration(
    name="llm",
    trace_id=trace_id,
    start_time=trace_info.start_time,
    ...
    # <-- no id= is passed
)
self.add_generation(langfuse_generation_data)

LangfuseGeneration.id defaults to None. add_generation() then sends the event through the low-level ingestion API, and filter_none_values strips the None id:

data = filter_none_values(langfuse_generation_data.model_dump())  # drops the None "id"
body = CreateGenerationBody(id=data.get("id"), ...)               # id is None
event = IngestionEvent_GenerationCreate(body=body, ...)
self.langfuse_client.api.ingestion.batch(batch=[event])

So the generation event reaches Langfuse with no observation id and is dropped, while the trace (which has its own id) is accepted — hence "trace but no generation, no cost, 0.00s latency".

workflow_trace() is not affected because it always passes an explicit id:

node_generation_data = LangfuseGeneration(id=node_execution_id, ...)

Why it regressed

Before 1.14 (e.g. 1.13.3), add_generation() used the high-level SDK, which auto-generates a client-side observation id when none is supplied:

self.langfuse_client.generation(**format_generation_data)

The trace-provider refactor (#35144) / Langfuse v3-SDK migration switched to the raw ingestion API, which does not auto-generate an id — but message_trace was never updated to supply one. This broke generation export for every message_trace app type (Chatbot, Agent, Completion) from 1.14.0 onward, and it is still present on main.

Suggested fix

Pass an explicit id to the LangfuseGeneration created in message_trace (and to the other message-path observations in this file that currently omit it — suggested_question_trace, moderation_trace, dataset_retrieval_trace, tool_trace), e.g.:

langfuse_generation_data = LangfuseGeneration(
    id=str(uuid.uuid4()),
    name="llm",
    trace_id=trace_id,
    ...
)

Notes

  • The same MessageTraceInfo flow is shared by other trace providers (e.g. Opik), so it's worth checking whether they have the same missing-id pattern on their low-level ingestion paths.
  • Possibly related: Langfuse token counting error #35421 (incorrect token counts on the same message_trace path).

Activity

  1. mengshun2022 commented on Jul 13, 2026

    @mengshun2022

    I adopted this solution, explicitly adding id=str(uuid.uuid4()) during the creation of LangfuseGeneration and LangfuseSpan in the project source code. However, in the evaluator function of langfuse, I still cannot capture the node logs.

  2. dosubot commented on Aug 13, 2026

    @dosubot

    Hi, @RazmikGevorgyan. I'm Dosu, and I'm helping the dify team manage their backlog and am marking this issue as stale.

    Recap

    • You reported that in Dify 1.14.x, Langfuse tracing for non-workflow apps (Chatbot, Agent, Completion) no longer creates an LLM generation observation.
    • As a result, traces only show a top-level message node, with blank cost and 0.00s latency in Langfuse.
    • Workflow and advanced-chat apps do not appear to be affected.
    • The current understanding is that token usage is being recorded in the trace input payload instead of a generation object.
    • A workaround was attempted in source code by explicitly setting IDs for LangfuseGeneration and LangfuseSpan, but it did not resolve node log capture in Langfuse’s evaluator function.

    Next Steps

    • Please confirm whether this issue is still relevant on the latest version of the dify repository.
    • If it is still reproducible, you can keep the discussion open by commenting here; otherwise, this issue will be automatically closed in 15 days.

    Thanks for your understanding and contribution.

  3. added
    no-issue-activity
    and removed on Sep 4, 2026
  4. removed
    no-issue-activity
    on Sep 10, 2026
  5. brendangooden commented on Sep 17, 2026

    @brendangooden

    Hello — stepping in for @RazmikGevorgyan, I'm working with him on the same project.

    Yes, this is still live. It reproduces on Dify hotfix-1.17.0-fix.14 (plugin-daemon 0.6.10-local, Langfuse Python SDK v3) — three minor versions past 1.14.0. We believe #37833 is the right fix — can it please be reviewed, merged, and released ASAP? Adding a production repro below, plus a correction to the current scoping.

    Correction: advanced-chat / chatflow apps ARE affected. The recap here says "Workflow and advanced-chat apps do not appear to be affected." On our instance an advanced-chat (chatflow) app — agent_based = false, and it carries a workflow_run_id — emits a broken message trace on every turn. Dify traces each turn twice:

    • a workflow-run trace (has workflow_run_id; node spans + priced GENERATIONs) — correct; and
    • a message-level trace (trace id = message_id, with the same conversation_id and workflow_run_id) — 0 observations, totalCost = 0, latency = 0.

    The two are paired 1:1 by shared conversation_id + workflow_run_id. So the message_trace path is broken independently of app type — it hits any app that produces message records, chatflows included, not just Chatbot / Agent / Completion.

    Scale. In a 100-trace sample, 80 were message-level traces; 41 (51%) had totalCost = 0 and latency = 0 — the broken half of each pair.

    Mechanism (redacted empty traces). Each has status = normal, observations = 0 (no GENERATION), and token counts only as plain fields in the trace input, never as a generation's usage:

    input.message_tokens input.answer_tokens input.total_tokens cost
    1,125 5 1,130 $0
    6,773 419 7,192 $0
    — — 43,323 $0
    — — 47,843 $0

    The paired workflow-run traces price their generations correctly on the same instance, so this is not a pricing/setup problem — it is isolated to the message-level trace, which is created without a generation observation id.

    Impact. Real usage is large (tens of thousands of tokens per turn), but Langfuse reports $0 for ~half of all message traffic, so cost/latency dashboards structurally understate spend.

  6. brendangooden commented on Sep 25, 2026

    @brendangooden

    @crazywoola @appleboy Any thoughts here?

  7. 41tair commented on Nov 4, 2026

    @41tair
    Member

    Fixed in #44673.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions