Add traceIf function for conditional tracing.