Skip to content

agent-chat app mode missing app_id in trace metadata (Langfuse/OTLP integrations can't identify the app) #38795

Open

Description

@rainbow0432-dev

Summary

Traces from agent-chat apps don't include app_id in their metadata, while advanced-chat apps do. This breaks third-party tracing integrations (Langfuse, LangSmith, Opik, etc.) that rely on app_id to identify which Dify app generated a trace.

Environment

  • Dify version: 1.13.3
  • App mode: agent-chat (Agent)
  • Tracing provider: Langfuse

Reproduction

  1. Create two apps — one advanced-chat, one agent-chat
  2. Enable Langfuse tracing for both (identical config)
  3. Send a chat request to each app
  4. Inspect the trace metadata in Langfuse

Expected: Both traces contain app_id in metadata.

Actual: Only the advanced-chat trace has app_id. The agent-chat trace is missing it.

Root cause

In api/core/ops/ops_trace_manager.py, the WorkflowTraceInfo metadata (used for advanced-chat) explicitly includes app_id:

metadata = {
    ...
    "app_id": workflow_run.app_id,  # ← present
}

But the MessageTraceInfo metadata (used for agent-chat) does not:

metadata = {
    "conversation_id": message_data.conversation_id,
    "ls_provider": message_data.model_provider,
    "ls_model_name": message_data.model_id,
    "status": message_data.status,
    "from_end_user_id": message_data.from_end_user_id,
    "from_account_id": message_data.from_account_id,
    "agent_based": message_data.agent_based,
    "workflow_run_id": message_data.workflow_run_id,
    "from_source": message_data.from_source,
    "message_id": message_id,
    # ← no app_id
}

The code already queries the Conversation table for mode — the fix extends this to also fetch app_id:

# Before:
conversation_mode_stmt = select(Conversation.mode).where(Conversation.id == message_data.conversation_id)

# After:
conversation_mode_stmt = select(Conversation.mode, Conversation.app_id).where(Conversation.id == message_data.conversation_id)

And adds app_id to the metadata:

metadata = {
    "app_id": conversation_app_id,  # ← add this
    "conversation_id": message_data.conversation_id,
    ...
}

Impact

Any tracing integration that uses app_id from trace metadata to identify the source app will fail for agent-chat apps. This affects all trace providers that read app_id from trace_info.metadata (LangSmith, Opik, Weave, Tencent, Arize Phoenix all have this pattern in their trace implementations).

Suggested fix

Add app_id to the MessageTraceInfo metadata by fetching it from the Conversation table (which already has an app_id column). The conversation is already queried for mode — just extend the query.

Activity

  1. dosubot commented on Jul 12, 2026

    @dosubot

    Hi @rainbow0432-dev! I'm Dosu and I'm helping the Dify team.

    I looked into the current code in api/core/ops/ops_trace_manager.py and it appears that app_id is already included in the MessageTraceInfo metadata. Specifically, it's sourced from message_data.app_id (the Message model has a direct app_id field) [1]. The WorkflowTraceInfo metadata similarly includes app_id from workflow_run.app_id [2].

    There doesn't appear to be any conditional logic that would exclude app_id for agent-chat vs advanced-chat — the metadata construction is uniform for all app types [3].

    A few possibilities to investigate:

    1. Version mismatch — This fix may have already been applied after 1.13.3. Could you check which exact commit/tag you're running? The current main branch appears to include app_id in MessageTraceInfo.
    2. Message record issue — It's possible that for agent-chat apps, the Message record's app_id field isn't being populated correctly at creation time in your version.
    3. Trace provider implementation — Some trace providers (Langfuse, LangSmith, etc.) have their own trace methods that might selectively read fields from trace_info.metadata. It's worth checking whether the provider-specific implementation in your version passes through app_id.

    Could you confirm whether you're running the latest code or a specific release? If you're on an older version, this may already be resolved upstream.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about dify with Dosu

  2. added
    no-issue-activity
    and removed on Sep 4, 2026
  3. removed
    no-issue-activity
    on Sep 6, 2026
  4. rdydygin commented on Oct 27, 2026

    @rdydygin

    This appears to be resolved on current main: TraceTask.message_trace in api/core/ops/ops_trace_manager.py, which builds traces for agent-chat and the other message-based modes, now includes "app_id": message_data.app_id in the metadata, next to tenant_id, app_name and workspace_name. It was added in #33138. Message.app_id is a required column, so it is always set. The PR linked here (#39163) was closed only for merge conflicts. If you still see a missing app_id on a current build, a trace example would help; otherwise this can probably be closed.

  5. added
    1.13.3
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.13.3project#dify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions