I am trying to get the duration of each HTTP request I send through Angular.js, to so I can send it to New Relic analytics. I can use transformRequest to find when any HTTP request is fired, and I can use responseInterceptors to get the completed request. But I can't find any way to link that information together.
Any suggestions to get the duration of HTTP requests? Ideally something that works with Angularjs Rails Resource: https://github.com/FineLinePrototyping/angularjs-rails-resource?
I got this code from one of the blogs for rendering overlays by default when an http request is made. I modified it a little bit to address your issue. See if this helps.
angular
.module('analytics', [])
.config(function($httpProvider) {
$httpProvider.responseInterceptors.push(function() {
return function(promise) {
// START YOUR TIMER
var callReturn = function(r) {
// END YOUR TIMER
total_time = START TIMER - END TIMER
};
return promise.then(callReturn, callReturn);
};
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With