How to calculate the length of a polyline across the Earth

How does one calculate the length of a polyline as a great circle distance? In this case the line only has two positions in it; i know there’s a cartesian3 distance function, but that’s a straight line distance.

I found this method, but it seems to be based on outdated and removed functions.

Created a methodology using the CallbackProperty showcase example.

This is assuming that a polyline already exists.

calculateMeasureLineLength(){
   var geodesic = new Cesium.EllipsoidGeodesic();
   let totalDistanceInKm = 0.0
   let distLine = viewer.entities.getById("examplePoly").polyline;

   if (distLine && distLine.positions) {
     let startPos = distLine.positions.getValue(JulianDate.now())[0];
     let endPos = distLine.positions.getValue(JulianDate.now())[1];

     geodesic.setEndPoints(
       Cartographic.fromCartesian(startPos),
       Cartographic.fromCartesian(endPos)
     );

     var totalDistanceInMeters = Math.round(geodesic.surfaceDistance);

     totalDistanceInKm = totalDistanceInMeters * 0.001;
   }

   return totalDistanceInKm;
}