The performance metrics are provided by the browser itself. So you don't really need to do anything.
However if you are using specific metrics, you could use the web vitals project. given below is a use case:
import {getFCP} from 'web-vitals';
// Measure and log the current FCP value,
// any time it's ready to be reported.
getFCP(console.log);
Sice it is open sourced, you can check how they use APIs' a well.