--- type: "fhirpath-function" title: "FHIRPath Function: trace" function: "trace" category: "Utility functions" section: "5.10.1" source: "fhirpath/functions.json" --- # FHIRPath Function: trace > This is a [scoped function](#scoped-functions): If no `projection` argument is provided, the input collection is logged without the need for scoping. If the `projection` argument is provided, it is evaluated for each item (setting `$this` and `$index` before each iteration) and the result logged. The input collection is returned as the result of the function.
> The `name` parameter is evaluated before the function is executed and is not re-evaluated for each iteration of the projection. Adds a String representation of the input collection to the diagnostic log, using the `name` argument as the name in the log. This log should be made available to the user in some appropriate fashion. Does not change the input, so returns the input collection as output. If the `projection` argument is used, the trace would log the result of evaluating the project expression on the input, but still return the input to the trace function unchanged. ``` fhirpath contained.where(criteria).trace('unmatched', id).empty() ``` The above example traces only the id elements of the result of the where. ## Summary - **Category**: Utility functions - **Section**: `5.10.1` - **Return Type**: `collection` - **Empty Input Result**: `empty` - **Errors on Multiple Input**: `false` ## Description Adds a String representation of the input collection to the diagnostic log, using the `name` argument as the name in the log. Does not change the input, so returns the input collection as output. ## Arguments - `name`: `String` - Name to use in the log - `projection` (optional): `Expression` - Optional expression to project for logging ## Type Mapping - `Any-Any` ## Example ```fhirpath contained.where(criteria).trace('unmatched', id).empty() ```