1- Foreign companies usually pay more money than local ones, specially American. Obviously there are exceptions but generally speaking avoid them.
2- Outsourcing companies (the so called "cárnicas") usually are the worst places to work, for salary and for conditions in general... Usually companies where you build/maintain the product pay more.
3- For individual contributors technology matters a lot. Kubernetes pays well, crypto pays unreasonable amounts, rust in general is very well paid as well, AI, etc. Find your niche.
4- Experience matters more than education and open source contributions raise your value a lot.
I'd say those are the main factors that will determine a position's salary, so it's a matter of finding the right position and being the best candidate *for that position*.
As for the technology I've been doing kubernetes for about 8 years now (that's before 1.0 was released). For this experience my salary is not insane at all, counting bonus and stock I was making about 35% more in my previous job, but I was quite tired of being a sysadmin and moved back to programming and that involved doing a pay cut.
Realistically at Google I'd probably be an L5 or L6 software engineer so let's say I'd make somewhere around 400k USD. Working from home in Spain I make 80k euros and I cost the company around 92k euros with taxes, so let's round it up and say I cost to the company 100k USD per year.
I'm not 4 times less productive for working in a small town in the middle of nowhere in Spain, so even if I'm not in my peak productivity I'd say the company gets more for their money.