Dify (tracing)

Dify client calls are captured with respan-instrumentation-dify so model calls, workflow calls, and feedback operations can be inspected in Respan traces.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

Setup

1

Install packages

pip install respan-ai respan-instrumentation-dify dify-client
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export DIFY_CHAT_API_KEY="YOUR_DIFY_CHAT_API_KEY"
3

Initialize and send a request

import os
from dify_client import ChatClient
from respan import Respan
from respan_instrumentation_dify import DifyInstrumentor
respan = Respan(
api_key=os.environ["RESPAN_API_KEY"],
app_name="dify-tracing",
instrumentations=[DifyInstrumentor()],
)
client = ChatClient(os.environ["DIFY_CHAT_API_KEY"])
response = client.create_chat_message(
inputs={},
query="Summarize tracing in one sentence.",
user="respan-user",
response_mode="blocking",
)
response.raise_for_status()
print(response.json()["answer"])
respan.shutdown()
4

View your trace

Open the Traces page to inspect Dify request and workflow spans.