fn:trace() behavior

The fn:trace() function is useful for debugging XQuery modules. It wraps an expression and writes its value to an implementation-defined log. In the Dgraph, output generated by calls to fn:trace() is sent to the Dgraph log file, or to stdout, if the Dgraph is run from a shell.

fn:trace() takes two arguments: the expression you are tracing and a label. The XQuery evaluator serializes the value of the expression (that is, turns a typed value into a string) and returns the same value again, so you can transparently annotate your query.

The following example illustrates fn:trace() usage:
trace(<parent><child1/><child2/></parent>/*, "my_label")
dgraph log output:
Request: 1 - trace(<child1/><child2/>, my_label)
Note: An XQuery processor is only required to evaluate as much of a query as is necessary to compute the final result. That means that unused sub-expressions are not guaranteed to be evaluated, so their values may not be directed to the log. For more information, see the topic "Endeca XQuery evaluator expression-skipping behavior."