WASHINGTON — It was not obvious to the National Security Agency a dozen years ago that Angela Merkel, a rising star as the leader of the Christian Democratic Union, was a future chancellor of Germany.

But that did not matter.

The N.S.A., in a practice that dates back to the depths of the Cold War and that has never ended, was recording her conversations and those of a range of leaders in Germany and elsewhere, storing them in databases that could be searched later, if the need arose. It is unclear how often they searched the databases for her conversations, if at all.

But once she became the country’s leader, everything she talked about on her personal cellphone — like her support of the Afghan war, the efforts of European allies to halt Iran’s nuclear program, and Germany’s central role in quelling the European financial crisis — took on greater importance for the American eavesdroppers.

How the N.S.A. continued to track Ms. Merkel as she ascended to the top of Germany’s political apparatus illuminates previously undisclosed details about the way the secret spy agency casts a drift net to gather information from America’s closest allies. The phone monitoring is hardly limited to the leaders of countries like Germany, and also includes their top aides and the heads of opposing parties. It is all part of a comprehensive effort to gain an advantage over other nations, both friend and foe.