Fearful of an expanding terrorist threat, countries that for years have relied heavily on U.S. intelligence are quickly building up their own capabilities with new technology, new laws and — in at least one case — a searing debate on how much the American government should be allowed to spy on their own citizens.

Responding to a jihadi movement that is successfully recruiting people from around the world, France and Canada are both passing laws that would dramatically ramp up their surveillance apparatus. In France, lawmakers are on the verge of approving a bill that would let the government install "black boxes" to collect metadata from every major phone and Internet company.

Canada's measures were rushed through after a two separate attacks in October 2014 on Canadian soldiers — including one that ended when the gunman stormed Parliament and was shot to death by guards and police. France's law went into high gear after the January terror attacks on the satirical weekly Charlie Hebdo and a kosher supermarket that left 20 dead, including the gunmen.

Analysts say it's not so much a question of diminishing cooperation with the U.S. — the revelations of Edward Snowden have ultimately done little to harm relationships between allies — as a push to increase domestic capacities ill-equipped to face the rising threat of Islamic State and other jihadi groups.

"These are not people coming from the outside, these are not people who are taking plane trips, they are not people who attracted notice outside our countries. These are people who come from the heart of our society," said Alain Chouet, a former  French intelligence official who recently returned from an extended trip to Canada where he debated the measures in both countries. "International cooperation in this area isn't hugely useful."

Technologically, France goes the furthest with the planned creation of a 'Made in France' mass collection of metadata that has the potential to go beyond a National Security Agency program recently struck down by a federal appeals court. Where the NSA collected landline metadata for nearly every U.S. citizen but never really got into scooping up cell data, France is pushing to essentially vacuum up and analyze everything — landline, mobile and Internet metadata.

The Canadian proposals are more measured, but would till dramatically expand domestic intelligence capabilities, legalize some collection of metadata, and allow spy services to take over recruiters' social networking accounts to "counter-message" as well as delete online material from anywhere in the world that promotes terrorism against Canadians. Unlike the French proposals, the Canadian measures began coming under strong public opposition as time went on, including an open letter from 60 executives and a Twitter campaign that included a dire warning this month from author Margaret Atwood: "See you in the slammer, kids."

France and Canada are likely to have new laws before summer, with both adding technology and manpower to surveillance systems. In Germany, the debate is just starting.

The German weekly Der Spiegel reported that the Federal Intelligence Service for years monitored telecoms traffic using filters provided by the NSA because it lacked the capacity — and the legal authority — to do so itself.  By 2008, German intelligence agents discovered that some of the filters — known as selectors — related to European arms companies and French authorities.

Neither the government nor the BND, as the intelligence service is known, would comment on reports that Germany has stopped sharing some Internet surveillance data from a German spy station with the NSA. The French appear unworried that their top officials may have been targeted: "We trust the German government," said France's chief spokesman, Stephane Le Foll.

But the Germans may be caught between a history of Nazi and East German regimes and the potential of hundreds of returning Islamic State fighters in their future.

"There is a lot of caution as to the role of intelligence and in a way, I think, for Germans over the decades it had always been a comforting situation to know we are doing this in cooperation with our allies. Because we had this sort of internal dimension of abuse of secret services," said Daniela Schwarzer, the Berlin-based head of the Europe Program, German Marshall Fund think tank.

"So it's a huge thing and we're just only starting this debate," she said.

None are actually proposing diminishing cooperation with the NSA — just beefing up their own capacities, said John "Chris," Inglis, who retired in 2014 as the NSA deputy director.

In France, he said, he sees "the law and policy catching up to what they have already been doing."

In Germany, where many are deeply opposed to government surveillance, he noted that the German government is not foreswearing cooperation with the NSA.

And Canada's role as a vital part of the "Five Eyes" intelligence-sharing program joining the U.S., Australia, Britain and New Zealand has not been called into question.

"I do not think we are seeing a trend of Europeans seeking to break away from America as much as a reaction to the increasingly global threat of domestic extremists and returning foreign fighters," said Raj De, who retired as NSA general counsel this year and is now a partner at the Mayer Brown law firm in Washington. "Europeans are having to openly confront the notion that their governments must protect their homeland independently or in continued cooperation with the U.S."

But although Chouet, the former French intelligence official, acknowledged the need, he questioned the need for the kind of technolgical dragnet proposed in France's legislation, noting that the U.S. was moving away from mass eavesdropping. The House of Representatives last week voted to shut down the NSA's program to collect Americans' phone records in bulk, potentially ending the program just as the French are beginning theirs.

        "Voila. And we are doing this 10 years late," Chouet said. "In France we have the habit of doing things 10 years later than the United States. Maybe we'll revisit this in a few years."

 ___

Dilanian reported from Washington. Associated Press John-Thor Dahlburg in Brussels contributed.