简体   繁体   中英

Get HTTP request time in angular.js?

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);
            };
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM