You can place a small resistor in series with the supply, and measure the voltage drop over it. From this and using Ohm's law you can calculate the current. Then the power is trivial.
There are special resistors for this purpose that are very low in resistance.
The data acquisition is kinda a bitch if you want to measure accurately over long time, small IoT device can take microamps when idle and tens of even hundred+ mA when transmitting and that's 4-5 orders of magnitude of dynamic range and that's kinda hard to deal with accuracy
https://www.joulescope.com/ handles most of that edgecases but it's a pricy piece of kit if you just want to do some measurements and are not using it to make actual product.
I wonder if you could rely on a capacitor charging over time, that you discharge every time you poll? That way you delegate the real-time "counting" to the capacitor and can read it at approximate times (as long as it's frequent enough to avoid fully charging the capacitor since it can't count beyond that)?
Pretty much. Just need to be very stable source and a lot of generic engineering around to not incur error.
Hell, that's actually very easy way to make ADC, just start counting, charge cap to pre-determined value then trigger counter stop. There are few improvements to that technique (like dual slope ADC, where you use reference voltage to discharge the cap to get the ratio between reference and input signal) but in general it can be very accurate way to measure.
There are special resistors for this purpose that are very low in resistance.