langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
50.79k stars 7.3k forks source link

Add Tracing from custom tools from used workflow #8126

Closed FrancisVarga closed 1 week ago

FrancisVarga commented 1 month ago

Self Checks

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Created custom tools to manage easier complex workflows.

2. Additional context or comments

There is no tracing from the current workflow into the tools workflow

3. Can you help us with this feature?

dosubot[bot] commented 1 month ago

You can add tracing from the current workflow into the custom tools workflow using the LangFuseDataTrace class. Here's how you can do it:

  1. Instantiate LangFuseDataTrace:

    langfuse_data_trace = LangFuseDataTrace(langfuse_config)
  2. Create a ToolTraceInfo object with the necessary information:

    tool_trace_info = ToolTraceInfo(
       tool_name="custom_tool_name",
       tool_inputs={"input_key": "input_value"},
       tool_outputs={"output_key": "output_value"},
       message_id="unique_message_id",
       start_time=datetime.now(),
       end_time=datetime.now() + timedelta(seconds=5),
       metadata={"additional": "metadata"},
       error=None  # or provide an error message if there was an error
    )
  3. Call the tool_trace method to add the trace:

    langfuse_data_trace.tool_trace(tool_trace_info)

This will add a trace for the custom tool execution within the workflow. The tool_trace method constructs a LangfuseSpan object with the provided information and calls self.add_span to add the span to the trace [1].

For more detailed steps and visual aids, you can refer to the Langfuse integration guide which provides comprehensive instructions on setting up and using Langfuse for monitoring and tracing in Dify [2][3].

To continue talking to Dosu, mention @dosu.