Before You Start
You need:- An endpoint for OpenTelemetry traces over HTTP: an OpenTelemetry Collector, or a backend that accepts OpenTelemetry directly. Dify sends traces in the OpenTelemetry Protocol (OTLP) over HTTP, not gRPC. On a Collector, that’s the HTTP receiver, usually on port 4318.
- A public address: Dify sends traces from its own servers, which can’t reach a private network or your computer.
-
Credentials as HTTP headers, if the endpoint needs them, such as an
Authorizationheader or a vendor’s API-key header.
Connect Dify to Your Endpoint
Configuring an app’s tracing requires the Owner or Admin role, or the Editor role on an app you created. For an Agent, you need the Editor role or above.
- In the Monitoring page of your app or Agent, click Tracing app performance.
-
Click Config and fill in the form:
-
Endpoint: the URL that receives your traces. Dify adds
/v1/tracesto a bare address such ashttps://otel.example.comand uses any other path as is. Leave credentials and?queries out of the URL, and put credentials in HTTP headers (JSON) instead. -
HTTP headers (JSON): the headers your endpoint needs, such as
{"Authorization":"Bearer <token>"}. Leave out transport headers such asContent-Type,Host,Accept, andContent-Encoding, even if your backend’s setup guide lists them. Dify never shows saved headers again and clears them when you change Endpoint, so keep your own copy. -
Service name: the name your backend groups traces under (
service.name). It’sdifyunless you change it. Give each app and Agent its own name, so you can find their traces later. -
Resource attributes (JSON): labels added to every trace from this app, such as
{"deployment.environment.name":"production"}. Setservice.namein Service name.
-
Endpoint: the URL that receives your traces. Dify adds
- Click Save & Enable. Dify tests the endpoint before saving.
If Save Fails
The tracing configuration could not be verified.: Dify couldn’t reach the endpoint, or the endpoint refused the test. Check the URL’s path and port, that the endpoint is reachable from the public internet, and the header names and values your backend expects.The tracing configuration is invalid.: a field breaks one of the rules above, such as a JSON typo, a transport header, or a?query in Endpoint.
Check That Traces Arrive
Run the whole app once, in the editor or as a user, then search your backend for its service name. Testing a single node doesn’t send the app’s trace. This run is also the real test of your credentials. Some collectors accept Save’s test without checking them. If the trace isn’t there yet, wait a few minutes. A trace that Dify is retrying can take five minutes or more to arrive. If it still doesn’t arrive, check the header names and values your backend expects. If you send through a Collector, also check that it forwards traces to your backend. Agent runs also show their delivery status in Dify, in the External tracing row of their log details.Read the Traces in Your Backend
How the spans in a trace nest depends on the app type:-
Workflow:
workflowat the root, then one span per node, named<node type>_<node title>, such asllm_LLM. Each node’s span sits under the node that ran before it, so a straight workflow forms a staircase:Each span still covers only its own node’s time. -
Chatflow:
messageat the root,workflowunder it, then the node spans as in a Workflow app. -
Chatbot, Text Generator, and legacy Agent apps:
messageat the root. Under it sit anllmspan and one span for each other step, such as knowledge retrieval or a tool call. Thellmspan lasts as long as the whole message, not just the model call. -
Agents:
messageat the root, with the Agent’s own steps under it. See Trace Agent Runs.
Attributes to Filter On
Filter and group traces by these span attributes, for example to chart token use per model fromgen_ai.request.model and gen_ai.usage.total_tokens:
Token counts and cost appear as attributes only on LLM spans, so summing them leaves out Question Classifier, Parameter Extractor, and other nodes that call a model.
For a run’s full token count, read
total_tokens in the dify.metadata of its workflow span. Each node’s span carries its own total_tokens and total_price in the same place. In Agent runs with Capture content off, dify.metadata leaves these out, though LLM spans still carry their token and cost attributes.
Find a Particular Run
Start by narrowing to the app with the service name you gave it. If several apps share a name, filter ondify.app_id instead. It’s the ID in the app’s URL in Dify (/app/<app ID>/…), and most of the app’s spans carry it.
Agents need a service name of their own, because their spans carry a different app ID from the one in the Agent’s URL.
Within the app, filter on the ID you have, as the API returns it, dashes included:
- A Workflow run started through the API:
dify.workflow_run_id, from the response’sworkflow_run_id. - A message sent through the API to a Chatbot, Text Generator, or legacy Agent app:
dify.message_id, from the response’smessage_id. - A conversation in a Chatbot, Chatflow, legacy Agent app, or Agent:
gen_ai.session.id, from the response’sconversation_idor the Conversation ID in the app’s logs. The logs show that ID in capitals, so copy it with its copy button. - Any other run: the time it started.
X-Trace-Session-Id header when you start the run through the API. Dify then stores it in gen_ai.session.id instead of the conversation or run ID, so a tagged conversation can no longer be found by its conversation ID. Agents ignore this header.
Join API Runs to Your Service’s Trace
Workflow and Chatflow runs started through the API can join your own service’s trace, so you can follow a request from your service into Dify. Runs of workflows with a new Agent node always get a trace of their own instead. If your service’s HTTP client sends the W3Ctraceparent header, as OpenTelemetry’s HTTP instrumentation does, the run joins with no change on your side. Otherwise, send your trace ID in the X-Trace-Id header, or as trace_id in the query string or request body.
Dify handles the ID by its form:
- 32 hexadecimal characters or a UUID: the run joins your trace. OpenTelemetry trace IDs take the first form.
- Up to 128 letters, digits,
-, and_, such asorder-123: the run doesn’t join your trace. Dify computes a trace ID from the value, so every run sent with that value lands in the same trace. - Any other value, such as
order:123: Dify ignores it, and the run gets a trace of its own.
Trace Agent Runs
An Agent’s traces include its own model and tool calls, grouped underAgent attempt <n> spans. In an Agent’s own runs, these spans sit under the root message span. In a workflow, they sit under the agent_<node title> span of the new Agent node.
These runs differ from other traces:
- Content: inputs and outputs arrive empty until you turn on Capture content. In a workflow with a new Agent node, that covers every node, not only the Agent.
- Your trace ID: each run gets a trace of its own, even when you send your trace ID through the API.
- Capture Agent internals: turn it off to show each Agent as a single step. The Agent’s model names, token counts, and cost are then left out too, so leave it on if you track usage.
- Capture content: turn it on to see what each step received and returned. Until then, Dify also replaces error text with a generic message, such as
Application execution failed. Model names, token counts, and cost arrive either way.
If Your Endpoint Is Down or Refuses a Trace
When Dify can’t connect to the endpoint, or the endpoint answers that it’s overloaded or failing, Dify keeps trying for about five minutes, or about 10 minutes for Agent runs. During an outage, you can send pending traces to a standby endpoint. Change Endpoint, enter the headers again even if they’re the same, and save. Dify’s next try goes to the new endpoint. Agent runs already under way don’t follow, since they keep the settings they started with. Dify drops a trace without trying again in two common cases:- The endpoint refuses the trace for another reason, such as a wrong path, rejected credentials, or a size it doesn’t accept. Fix the path or credentials in the tracing settings. For a trace that’s too large, raise the endpoint’s request size limit.
- The endpoint takes more than 30 seconds to answer, or the connection breaks after Dify sent the trace. If your backend is slow to answer, send to an OpenTelemetry Collector in front of it, which answers as soon as it has the trace.