statful-client-javascript
Advanced tools
Comparing version 2.1.2 to 2.1.3
{ | ||
"name": "statful-client-javascript", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Statful client for Javascript applications", | ||
@@ -5,0 +5,0 @@ "main": "dist/statful.js", |
/** | ||
* statful-client-javascript 2.1.2 | ||
* statful-client-javascript 2.1.3 | ||
* Copyright 2018 Statful <https://www.statful.com/> | ||
@@ -49,2 +49,22 @@ */ | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
/* eslint-disable no-console */ | ||
@@ -88,3 +108,3 @@ var Logger = function () { | ||
this.config = {}; | ||
Object.assign(this.config, config); | ||
_extends(this.config, config); | ||
@@ -262,5 +282,5 @@ this.logger = new Logger(this.config.debug); | ||
Object.assign(tags, globalTags); | ||
Object.assign(tags, typeTags); | ||
Object.assign(tags, methodTags); | ||
_extends(tags, globalTags); | ||
_extends(tags, typeTags); | ||
_extends(tags, methodTags); | ||
@@ -435,4 +455,4 @@ if (!tags.app && app) { | ||
Object.assign(this.config, defaultConfig); | ||
Object.assign(this.config, clientConfig); | ||
_extends(this.config, defaultConfig); | ||
_extends(this.config, clientConfig); | ||
@@ -567,3 +587,3 @@ // Create Logger | ||
Object.assign(defaults$$1, options); | ||
_extends(defaults$$1, options); | ||
@@ -570,0 +590,0 @@ // Create endMark if none is set |
/** | ||
* statful-client-javascript 2.1.2 | ||
* statful-client-javascript 2.1.3 | ||
* Copyright 2018 Statful <https://www.statful.com/> | ||
*/ | ||
var statful=function(){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function i(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}}(),n=function(){function t(e){g(this,t),this.debugEnabled=e||!1}return i(t,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),t}(),a=function(){function t(e){g(this,t),this.config={},Object.assign(this.config,e),this.logger=new n(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return i(t,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",i=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var n=new XMLHttpRequest;n.open("POST",r,!0),n.timeout=this.config.timeout,n.setRequestHeader("Content-type","application/json"),n.send(i),n.onreadystatechange=function(){200==n.status||201==n.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,n.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&0<e&&(r=setInterval(function(){0<t.metricsQueue.length&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),t}(),t=["avg","count","sum","first","last","p90","p95","min","max"],s=[10,30,60,120,180,300],o=function(){function u(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},n=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{};g(this,u),this.name=e,this.type=t,this.value=r;var a=[],s=[],o=0;n[t]&&(a=n[t].tags,s=n[t].aggregations,o=n[t].aggregationFrequency),this.tags=this.buildTags(i.tags,n.tags,a,n.app),this.aggregations=this.buildAggregations(i.aggregations,n.aggregations,s),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,n.aggregationFrequency,o),this.namespace=i.namespace||n.namespace,this.sampleRate=i.sampleRate||n.sampleRate}return i(u,[{key:"buildTags",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=arguments[3],n={};return Object.assign(n,t),Object.assign(n,r),Object.assign(n,e),!n.app&&i&&(n.app=i),n}},{key:"buildAggregations",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],i=[];return i=(i=(i=i.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(i)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var i=e||r||t;return this.filterAggregationFrequency(i)}},{key:"filterAggregations",value:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return t.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return s.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),u}(),u={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function e(){g(this,e)}return i(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===e?"undefined":r(e))&&null!==e||(e={}),Object.assign(this.config,u),Object.assign(this.config,e),this.logger=new n(this.config.debug),this.util=new a(this.config);var t=document.createElement("link");t.rel="preconnect",t.href=this.config.apiAddress,document.getElementsByTagName("head")[0].appendChild(t)}},{key:"measureTimeUserTiming",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return 0<t.length?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var i={clearMarks:!1,clearMeasures:!1};Object.assign(i,r),i.endMark||(this.registerMark(e),i.endMark=e),window.performance.measure(e,i.startMark,i.endMark);var n=this.measureTimeUserTiming(e);if(n){var a=new o(t,"timer",n,i,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");i.clearMarks&&this.clearMarks([i.startMark,i.endMark]),i.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var i=new o(e,"timer",t,r,this.config);this.util.addMetric(i,!0)}},{key:"counter",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var i=new o(e,"counter",t,r,this.config);i.value=Math.abs(parseInt(i.value,10)),this.util.addMetric(i,!0)}},{key:"gauge",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var i=new o(e,"gauge",t,r,this.config);this.util.addMetric(i,!0)}},{key:"sendMetric",value:function(e,t,r){var i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},n=new o(t,e,r,i,this.config);this.util.addMetric(n,!1)}}]),e}()}(); | ||
var statful=function(){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=function(){function t(e){g(this,t),this.debugEnabled=e||!1}return n(t,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),t}(),a=function(){function t(e){g(this,t),this.config={},o(this.config,e),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return n(t,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",n=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",r,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(n),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,i.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&0<e&&(r=setInterval(function(){0<t.metricsQueue.length&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),t}(),t=["avg","count","sum","first","last","p90","p95","min","max"],s=[10,30,60,120,180,300],u=function(){function u(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{};g(this,u),this.name=e,this.type=t,this.value=r;var a=[],o=[],s=0;i[t]&&(a=i[t].tags,o=i[t].aggregations,s=i[t].aggregationFrequency),this.tags=this.buildTags(n.tags,i.tags,a,i.app),this.aggregations=this.buildAggregations(n.aggregations,i.aggregations,o),this.aggregationFrequency=this.buildAggregationFrequency(n.aggregationFrequency,i.aggregationFrequency,s),this.namespace=n.namespace||i.namespace,this.sampleRate=n.sampleRate||i.sampleRate}return n(u,[{key:"buildTags",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},n=arguments[3],i={};return o(i,t),o(i,r),o(i,e),!i.app&&n&&(i.app=n),i}},{key:"buildAggregations",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],n=[];return n=(n=(n=n.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(n)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var n=e||r||t;return this.filterAggregationFrequency(n)}},{key:"filterAggregations",value:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return t.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return s.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),u}(),l={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function e(){g(this,e)}return n(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===e?"undefined":r(e))&&null!==e||(e={}),o(this.config,l),o(this.config,e),this.logger=new i(this.config.debug),this.util=new a(this.config);var t=document.createElement("link");t.rel="preconnect",t.href=this.config.apiAddress,document.getElementsByTagName("head")[0].appendChild(t)}},{key:"measureTimeUserTiming",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return 0<t.length?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var n={clearMarks:!1,clearMeasures:!1};o(n,r),n.endMark||(this.registerMark(e),n.endMark=e),window.performance.measure(e,n.startMark,n.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new u(t,"timer",i,n,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");n.clearMarks&&this.clearMarks([n.startMark,n.endMark]),n.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var n=new u(e,"timer",t,r,this.config);this.util.addMetric(n,!0)}},{key:"counter",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var n=new u(e,"counter",t,r,this.config);n.value=Math.abs(parseInt(n.value,10)),this.util.addMetric(n,!0)}},{key:"gauge",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var n=new u(e,"gauge",t,r,this.config);this.util.addMetric(n,!0)}},{key:"sendMetric",value:function(e,t,r){var n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=new u(t,e,r,n,this.config);this.util.addMetric(i,!1)}}]),e}()}(); |
/** | ||
* statful-client-javascript 2.1.2 | ||
* statful-client-javascript 2.1.3 | ||
* Copyright 2018 Statful <https://www.statful.com/> | ||
@@ -52,2 +52,22 @@ */ | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
/* eslint-disable no-console */ | ||
@@ -91,3 +111,3 @@ var Logger = function () { | ||
this.config = {}; | ||
Object.assign(this.config, config); | ||
_extends(this.config, config); | ||
@@ -265,5 +285,5 @@ this.logger = new Logger(this.config.debug); | ||
Object.assign(tags, globalTags); | ||
Object.assign(tags, typeTags); | ||
Object.assign(tags, methodTags); | ||
_extends(tags, globalTags); | ||
_extends(tags, typeTags); | ||
_extends(tags, methodTags); | ||
@@ -438,4 +458,4 @@ if (!tags.app && app) { | ||
Object.assign(this.config, defaultConfig); | ||
Object.assign(this.config, clientConfig); | ||
_extends(this.config, defaultConfig); | ||
_extends(this.config, clientConfig); | ||
@@ -570,3 +590,3 @@ // Create Logger | ||
Object.assign(defaults$$1, options); | ||
_extends(defaults$$1, options); | ||
@@ -573,0 +593,0 @@ // Create endMark if none is set |
/** | ||
* statful-client-javascript 2.1.2 | ||
* statful-client-javascript 2.1.3 | ||
* Copyright 2018 Statful <https://www.statful.com/> | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.statful=t()}(this,function(){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}(),i=function(){function t(e){g(this,t),this.debugEnabled=e||!1}return n(t,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),t}(),a=function(){function t(e){g(this,t),this.config={},Object.assign(this.config,e),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return n(t,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",n=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",r,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(n),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,i.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&0<e&&(r=setInterval(function(){0<t.metricsQueue.length&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),t}(),t=["avg","count","sum","first","last","p90","p95","min","max"],o=[10,30,60,120,180,300],s=function(){function u(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{};g(this,u),this.name=e,this.type=t,this.value=r;var a=[],o=[],s=0;i[t]&&(a=i[t].tags,o=i[t].aggregations,s=i[t].aggregationFrequency),this.tags=this.buildTags(n.tags,i.tags,a,i.app),this.aggregations=this.buildAggregations(n.aggregations,i.aggregations,o),this.aggregationFrequency=this.buildAggregationFrequency(n.aggregationFrequency,i.aggregationFrequency,s),this.namespace=n.namespace||i.namespace,this.sampleRate=n.sampleRate||i.sampleRate}return n(u,[{key:"buildTags",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},n=arguments[3],i={};return Object.assign(i,t),Object.assign(i,r),Object.assign(i,e),!i.app&&n&&(i.app=n),i}},{key:"buildAggregations",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],n=[];return n=(n=(n=n.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(n)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var n=e||r||t;return this.filterAggregationFrequency(n)}},{key:"filterAggregations",value:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return t.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return o.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),u}(),u={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function e(){g(this,e)}return n(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===e?"undefined":r(e))&&null!==e||(e={}),Object.assign(this.config,u),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new a(this.config);var t=document.createElement("link");t.rel="preconnect",t.href=this.config.apiAddress,document.getElementsByTagName("head")[0].appendChild(t)}},{key:"measureTimeUserTiming",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return 0<t.length?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var n={clearMarks:!1,clearMeasures:!1};Object.assign(n,r),n.endMark||(this.registerMark(e),n.endMark=e),window.performance.measure(e,n.startMark,n.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new s(t,"timer",i,n,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");n.clearMarks&&this.clearMarks([n.startMark,n.endMark]),n.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var n=new s(e,"timer",t,r,this.config);this.util.addMetric(n,!0)}},{key:"counter",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var n=new s(e,"counter",t,r,this.config);n.value=Math.abs(parseInt(n.value,10)),this.util.addMetric(n,!0)}},{key:"gauge",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var n=new s(e,"gauge",t,r,this.config);this.util.addMetric(n,!0)}},{key:"sendMetric",value:function(e,t,r){var n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=new s(t,e,r,n,this.config);this.util.addMetric(i,!1)}}]),e}()}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.statful=t()}(this,function(){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=function(){function t(e){g(this,t),this.debugEnabled=e||!1}return n(t,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),t}(),a=function(){function t(e){g(this,t),this.config={},o(this.config,e),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return n(t,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",n=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",r,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(n),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,i.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&0<e&&(r=setInterval(function(){0<t.metricsQueue.length&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),t}(),t=["avg","count","sum","first","last","p90","p95","min","max"],s=[10,30,60,120,180,300],u=function(){function u(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{};g(this,u),this.name=e,this.type=t,this.value=r;var a=[],o=[],s=0;i[t]&&(a=i[t].tags,o=i[t].aggregations,s=i[t].aggregationFrequency),this.tags=this.buildTags(n.tags,i.tags,a,i.app),this.aggregations=this.buildAggregations(n.aggregations,i.aggregations,o),this.aggregationFrequency=this.buildAggregationFrequency(n.aggregationFrequency,i.aggregationFrequency,s),this.namespace=n.namespace||i.namespace,this.sampleRate=n.sampleRate||i.sampleRate}return n(u,[{key:"buildTags",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},n=arguments[3],i={};return o(i,t),o(i,r),o(i,e),!i.app&&n&&(i.app=n),i}},{key:"buildAggregations",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],n=[];return n=(n=(n=n.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(n)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var n=e||r||t;return this.filterAggregationFrequency(n)}},{key:"filterAggregations",value:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return t.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return s.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),u}(),l={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function e(){g(this,e)}return n(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===e?"undefined":r(e))&&null!==e||(e={}),o(this.config,l),o(this.config,e),this.logger=new i(this.config.debug),this.util=new a(this.config);var t=document.createElement("link");t.rel="preconnect",t.href=this.config.apiAddress,document.getElementsByTagName("head")[0].appendChild(t)}},{key:"measureTimeUserTiming",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return 0<t.length?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var n={clearMarks:!1,clearMeasures:!1};o(n,r),n.endMark||(this.registerMark(e),n.endMark=e),window.performance.measure(e,n.startMark,n.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new u(t,"timer",i,n,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");n.clearMarks&&this.clearMarks([n.startMark,n.endMark]),n.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var n=new u(e,"timer",t,r,this.config);this.util.addMetric(n,!0)}},{key:"counter",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var n=new u(e,"counter",t,r,this.config);n.value=Math.abs(parseInt(n.value,10)),this.util.addMetric(n,!0)}},{key:"gauge",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var n=new u(e,"gauge",t,r,this.config);this.util.addMetric(n,!0)}},{key:"sendMetric",value:function(e,t,r){var n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=new u(t,e,r,n,this.config);this.util.addMetric(i,!1)}}]),e}()}); |
{ | ||
"name": "statful-client-javascript", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Statful client for Javascript applications", | ||
@@ -27,2 +27,3 @@ "banner": "/**\n* <%= pkg.name %> <%= pkg.version %>\n* Copyright 2018 Statful <https://www.statful.com/>\n*/\n", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-polyfill": "^6.26.0", | ||
@@ -29,0 +30,0 @@ "babel-preset-env": "^1.6.1", |
Sorry, the diff of this file is not supported yet
112464
2297
21