Action Editor/Dope Sheet confuses me a lot

I have big trouble understanding Dope Sheet’s gray lines between keyframes. I thought when they appear it means that two keyframes are identical. I have two cases where It confuses me.
First case: instead of having a long gray line, I have small disconnected lines.
In the picture below you can see that the gray lines are disconnected, even though all these keyframes have same values.


Second case: I have keyframes with different rotation values but the gray line is drawn between them anyway:


Can you explain me the purpose of the gray lines in the Dope Editor. It seems not to be for what I thought it was for.