{% macro _header_row(headers) %}
    <tr>
        {% for header in headers %}
            <th>{{ header }}</th>
        {% endfor %}
    </tr>
{% endmacro %}


{% macro _trace_row(trace, fields) %}
    <tr class="trace">
        {% for field in fields %}
            {% set value = trace.get(field) %}
            {% if value is not none %}
                <td>{{ value }}</td>
            {% else %}
                {# treat a missing value (literal None) as a special case, enable user-styling #}
                <td class="no-value" />
            {% endif %}
        {% endfor %}
    </tr>
{% endmacro %}


{% macro traces_table(traces, fields) %}
    <table class="traces">
        <thead>
            {{ _header_row(fields) }}
        </thead>
        <tbody>
            {% for trace in traces %}
                {{ _trace_row(trace, fields) }}
            {% endfor %}
        </tbody>
    </table>
{% endmacro %}
