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

bug: Cannot trace workflow execution due to session typo #12029

Closed
5 tasks done
You-keitou opened this issue Dec 24, 2024 · 2 comments · Fixed by #12031
Closed
5 tasks done

bug: Cannot trace workflow execution due to session typo #12029

You-keitou opened this issue Dec 24, 2024 · 2 comments · Fixed by #12031
Labels
🐞 bug Something isn't working 🌊 feat:workflow Workflow related stuff.

Comments

@You-keitou
Copy link
Contributor

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.14.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Set up langfuse integration
  2. Try to trace a workflow execution
  3. The trace fails due to the typo in workflow_trace method
  4. Error occurs when trying to refresh the workflow_run object

✔️ Expected Behavior

  • Workflow execution should be properly traced
  • The workflow_run object should be refreshed successfully in the database session
  • Trace data should be available in langfuse dashboard
  • Workflow monitoring should work seamlessly

❌ Actual Behavior

  1. Trace functionality fails
@You-keitou
Copy link
Contributor Author

@dosubot dosubot bot added 🌊 feat:workflow Workflow related stuff. 🐞 bug Something isn't working labels Dec 24, 2024
Copy link

dosubot bot commented Dec 24, 2024

Hello @You-keitou! I'm here to help you with any issues, questions, or contributions you have for the Dify project. Let me know how I can assist you!

To fix the session typo in the workflow_trace method of the OpsTraceManager class in the ops_trace_manager.py file, you need to correct the misspelled sessoin to session. Here is the corrected code snippet:

def workflow_trace(self, workflow_run: WorkflowRun | None, conversation_id, user_id):
    if not workflow_run:
        raise ValueError("Workflow run not found")

    db.session.merge(workflow_run)
    db.session.refresh(workflow_run)  # Corrected typo here

    workflow_id = workflow_run.workflow_id
    tenant_id = workflow_run.tenant_id
    workflow_run_id = workflow_run.id
    workflow_run_elapsed_time = workflow_run.elapsed_time
    workflow_run_status = workflow_run.status
    workflow_run_inputs = workflow_run.inputs_dict
    workflow_run_outputs = workflow_run.outputs_dict
    workflow_run_version = workflow_run.version
    error = workflow_run.error or ""

    total_tokens = workflow_run.total_tokens

    file_list = workflow_run_inputs.get("sys.file") or []
    query = workflow_run_inputs.get("query") or workflow_run_inputs.get("sys.query") or ""

    # get workflow_app_log_id
    workflow_app_log_data = (
        db.session.query(WorkflowAppLog)
        .filter_by(tenant_id=tenant_id, app_id=workflow_run.app_id, workflow_run_id=workflow_run.id)
        .first()
    )
    workflow_app_log_id = str(workflow_app_log_data.id) if workflow_app_log_data else None
    # get message_id
    message_data = (
        db.session.query(Message.id)
        .filter_by(conversation_id=conversation_id, workflow_run_id=workflow_run_id)
        .first()
    )
    message_id = str(message_data.id) if message_data else None

    metadata = {
        "workflow_id": workflow_id,
        "conversation_id": conversation_id,
        "workflow_run_id": workflow_run_id,
        "tenant_id": tenant_id,
        "elapsed_time": workflow_run_elapsed_time,
        "status": workflow_run_status,
        "version": workflow_run_version,
        "total_tokens": total_tokens,
        "file_list": file_list,
        "triggered_form": workflow_run.triggered_from,
        "user_id": user_id,
    }

    workflow_trace_info = WorkflowTraceInfo(
        workflow_data=workflow_run.to_dict(),
        conversation_id=conversation_id,
        workflow_id=workflow_id,
        tenant_id=tenant_id,
        workflow_run_id=workflow_run_id,
        workflow_run_elapsed_time=workflow_run_elapsed_time,
        workflow_run_status=workflow_run_status,
        workflow_run_inputs=workflow_run_inputs,
        workflow_run_outputs=workflow_run_outputs,
        workflow_run_version=workflow_run_version,
        error=error,
        total_tokens=total_tokens,
        file_list=file_list,
        query=query,
        metadata=metadata,
        workflow_app_log_id=workflow_app_log_id,
        message_id=message_id,
        start_time=workflow_run.created_at,
        end_time=workflow_run.finished_at,
    )

    return workflow_trace_info

This correction ensures that the session object is used correctly for database operations, allowing the workflow execution to be properly traced [1].

To continue talking to Dosu, mention @dosu.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🌊 feat:workflow Workflow related stuff.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant