Most insects are attracted to lamps because of light so they can find they way through the night but then they become confused by the light and spiral in circles around the light. But some insects are attracted to the heat so that the can stay active.
They are attracted to the warmth and most insects are able to sense light radiation which they are also attracted to