Fallback for NaN values (Add field from calculation)

  • What Grafana version are you using?
    Latest Grafana Enterprise Docker Image

  • What are you trying to achieve?
    I’m trying to calculate the self time of spans for a specific trace ID.

  • How are you trying to achieve it?
    With the Add field from calculation transformation and the binary operation mode. My operation is “duration Trace - duration(sum)” or rather “duration Span - duration Children”
    TLDR:
    I have two queries with the TraceQL ${traceId). One of the queries I grouped by parentSpanID and then summed the duration to get the duration of all child spans. Than I joined the queries by parentSpanID = spanID and am now trying to calculate the self time as described above.

  • My question
    Not all spans have child spans and for these my self time is NaN. Is there any way to replace the NaN values with the value of the duration Span field of that row? Or replace the duration Children with 0 so that the calculation still works?

The best option probably would be to replace null value to 0 at the datasource level if possible.

You may also try Convert field type transformation before Add field from calculation:

1 Like