@arms/rum-browser
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -10,2 +10,3 @@ import { ICollector, IContext, IViewData, RumEvent, ITracingHeaders } from '@arms/rum-core'; | ||
trace_data?: string; | ||
duration?: number; | ||
} | ||
@@ -15,2 +16,3 @@ declare global { | ||
apiAttr: IApiAttr; | ||
_start_time?: number; | ||
} | ||
@@ -17,0 +19,0 @@ } |
@@ -1,4 +0,4 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_base=require("../../utils/base"),_global=require("../../utils/global"),_uuid=require("../../utils/uuid"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=["xmlhttprequest","fetch"],this.cachedEntries=[],this.cachedApiAttrs=[],this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.api||(this.sendEvent=b,this.ctx=a,this.perfObserver(),this.hackXhr(),this.hackFetch())},b.perfObserver=function perfObserver(){var a=this,b=new PerformanceObserver(function(b){var c=b.getEntries().filter(function(b){return a.entryTypes.includes(b.initiatorType)});c&&c.length&&c.forEach(function(b){a.mergeDataAndSend({entry:b})})});b.observe({type:"resource",buffered:!0})},b.injectTracing=function injectTracing(a,b){var c=this.ctx.getConfig(),d=c.tracing,e=c.pid,f=(0,_rumCore.parseTracingOptions)(d),g=f.enable,h=f.allowedUrls,i=f.sample,j=f.tracestate,k=f.baggage;if(g){// Browser 情况下一直允许同域请求的trace | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_base=require("../../utils/base"),_global=require("../../utils/global"),_uuid=require("../../utils/uuid"),PerfObserver=_global.global.PerformanceObserver,ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=["xmlhttprequest","fetch"],this.cachedEntries=[],this.cachedApiAttrs=[],this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;!1===e.api||(this.sendEvent=b,this.ctx=a,this.perfObserver(),this.hackXhr(),this.hackFetch())},b.perfObserver=function perfObserver(){var a=this;if((0,_rumCore.isFunction)(PerfObserver)){var b=new PerformanceObserver(function(b){var c=b.getEntries().filter(function(b){return a.entryTypes.includes(b.initiatorType)});c&&c.length&&c.forEach(function(b){a.mergeDataAndSend({entry:b})})});b.observe({type:"resource",buffered:!0})}},b.injectTracing=function injectTracing(a,b){var c=this.ctx.getConfig(),d=c.tracing,e=c.pid,f=(0,_rumCore.parseTracingOptions)(d),g=f.enable,h=f.allowedUrls,i=f.sample,j=f.tracestate,k=f.baggage;if(g){// Browser 情况下一直允许同域请求的trace | ||
var l=(0,_rumCore.generateTraceId)(),m=(0,_rumCore.generateSpanId)(),n=(0,_rumCore.performDraw)(i),o=(0,_uuid.getSessionID)(),p=void 0===j||j?"rum=v2&browser&"+e+"&"+o:void 0,q=void 0!==k&&k?"rum=v2,appType=browser,pid="+e+",sid="+o:void 0;h.push({match:function match(a){return /^https?:\/\/*/.test(a)&&(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:["tracecontext"]});var r=(0,_rumCore.find)(h,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(r){var s=(0,_rumCore.makeTracingHeaders)(l,m,n,r.propagatorTypes,p,q);n&&(a.trace_id=l,a.trace_data=JSON.stringify({spanId:m,sampled:n,headers:s})),b(s)}}},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c){var d=c+"",e=a.toUpperCase();(0,_rumCore.urlMatch)(d)||"HEAD"===e||(// 异步过程 保证 view_id view_name 正确 | ||
this.apiAttr={},this.apiAttr.url=(0,_url.fixRelativeUrl)(d),this.apiAttr.method=e,this.apiAttr.view=(0,_view.getCurView)(b.ctx))}),(0,_rumCore.interceptFunction)(a,"send",function(){var a=this;this.apiAttr&&b.injectTracing(this.apiAttr,function(b){Object.keys(b).forEach(function(c){a.setRequestHeader(c,b[c])})}),this.addEventListener("loadend",function(){if(a.apiAttr){var c=a.status,d=a.statusText,e=a.response;a.apiAttr.status_code=c,a.apiAttr.message=d,b.mergeDataAndSend({attr:a.apiAttr})}})})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(global,"fetch",function(b){return function(c,d){var e,f,g;void 0===d&&(d={});var h=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),i=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听 | ||
if((0,_rumCore.urlMatch)(h)||"HEAD"===i||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(global,c,d);var j={};return j.url=(0,_url.fixRelativeUrl)(h),j.method=i,j.view=(0,_view.getCurView)(a.ctx),a.injectTracing(j,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(global,c,d).then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.clone(),d=c.status,e=c.statusText,j.status_code=d,j.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw j.message=a+"",a})["finally"](function(){a.mergeDataAndSend({attr:j})})}})},b.mergeDataAndSend=function mergeDataAndSend(a){var b=this;try{var c=function(a,c){var d=b.ctx.getConfig(),e=d.parseResourceName,f=a.url,g=a.status_code,h=a.view,i=(0,_performance.getResourceStatusByCode)(g);b.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},a,(0,_performance.calcResourceTimingData)(c),{view:h}))},d=a.attr,e=a.entry,f=this.cachedApiAttrs,g=this.cachedEntries;if(d){var h=g.find(function(a){return a.name===d.url});if(!h)return void f.push(d);g=g.filter(function(a){return a.name!==h.name}),c(d,h)}if(e){var i=f.find(function(a){return a.url===e.name});if(!i)return void g.push(e);f=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}(); | ||
this.apiAttr={},this.apiAttr.url=(0,_url.fixRelativeUrl)(d),this.apiAttr.method=e,this.apiAttr.view=(0,_view.getCurView)(b.ctx),this._start_time=(0,_base.getCurrentTime)())}),(0,_rumCore.interceptFunction)(a,"send",function(){var a=this;this.apiAttr&&b.injectTracing(this.apiAttr,function(b){Object.keys(b).forEach(function(c){a.setRequestHeader(c,b[c])})}),this.addEventListener("loadend",function(){if(a.apiAttr){var c,d=a.status,e=a.statusText,f=a.response;a.apiAttr.status_code=d,a.apiAttr.message=e,(0,_rumCore.isFunction)(PerfObserver)||(c={name:a.apiAttr.url,entryType:"xmlhttprequest",duration:(0,_base.getCurrentTime)()-a._start_time}),b.mergeDataAndSend({attr:a.apiAttr,entry:c})}})})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;void 0===d&&(d={});var h=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),i=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听 | ||
if((0,_rumCore.urlMatch)(h)||"HEAD"===i||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var j=(0,_base.getCurrentTime)(),k={};return k.url=(0,_url.fixRelativeUrl)(h),k.method=i,k.view=(0,_view.getCurView)(a.ctx),a.injectTracing(k,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return c=a.clone(),d=c.status,e=c.statusText,k.status_code=d,k.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw k.message=a+"",a})["finally"](function(){var b;(0,_rumCore.isFunction)(PerfObserver)||(b={name:k.url,entryType:"fetch",duration:(0,_base.getCurrentTime)()-j}),a.mergeDataAndSend({attr:k,entry:b})})}})},b.mergeDataAndSend=function mergeDataAndSend(a){var b=this;try{var c=function(a,c){var d=b.ctx.getConfig(),e=d.parseResourceName,f=a.url,g=a.status_code,h=a.view,i=(0,_performance.getResourceStatusByCode)(g);b.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},a,(0,_performance.calcResourceTimingData)(c),{view:h}))},d=a.attr,e=a.entry;if(d&&e)return void c(d,e);var f=this.cachedApiAttrs,g=this.cachedEntries;if(d){var h=g.find(function(a){return a.name===d.url});if(!h)return void f.push(d);g=g.filter(function(a){return a.name!==h.name}),c(d,h)}if(e){var i=f.find(function(a){return a.url===e.name});if(!i)return void g.push(e);f=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}(); |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_global=require("../../utils/global");function _createForOfIteratorHelperLoose(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(c)return(c=c.call(a)).next.bind(c);if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0;return function(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}var StaticResourceCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="static-resource-collector",this.entryTypes=["audio","video","track","script","css","img","image","link","other"],this.cachedErrors=[],this.WAIT_FOR_ERROR_TIME=1e3}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig(),e=d.collectors,f=void 0===e?{}:e;if(!1!==f.staticResource){_global.document.addEventListener("error",function(a){c.cachedErrors.push(a)},!0),new PerformanceObserver(function(b){var d=b.getEntries().filter(function(a){return c.entryTypes.includes(a.initiatorType)});if(d&&d.length){var e=(0,_view.getCurView)(a);d.forEach(function(a){setTimeout(function(){g(a,e)},c.WAIT_FOR_ERROR_TIME)})}}).observe({type:"resource",buffered:!0});var g=function(d,e){// responseStatus 若为 0,则先设成 200 | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_view=require("../../utils/view"),_global=require("../../utils/global");function _createForOfIteratorHelperLoose(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(c)return(c=c.call(a)).next.bind(c);if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0;return function(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}var PerfObserver=_global.global.PerformanceObserver,StaticResourceCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="static-resource-collector",this.entryTypes=["audio","video","track","script","css","img","image","link","other"],this.cachedErrors=[],this.WAIT_FOR_ERROR_TIME=1e3}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig(),e=d.collectors,f=void 0===e?{}:e;if(!1!==f.staticResource&&(0,_rumCore.isFunction)(PerfObserver)){_global.document.addEventListener("error",function(a){c.cachedErrors.push(a)},!0),new PerfObserver(function(b){var d=b.getEntries().filter(function(a){return c.entryTypes.includes(a.initiatorType)});if(d&&d.length){var e=(0,_view.getCurView)(a);d.forEach(function(a){setTimeout(function(){g(a,e)},c.WAIT_FOR_ERROR_TIME)})}}).observe({type:"resource",buffered:!0});var g=function(d,e){// responseStatus 若为 0,则先设成 200 | ||
// @ts-ignore | ||
@@ -3,0 +3,0 @@ for(var f,g=a.getConfig(),h=g.parseResourceName,i=d.responseStatus||200,j=d.name,k=d.initiatorType||d.entryType,l=(0,_performance.getResourceStatusByCode)(i),m=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:j,name:(0,_url.getResourceName)(j,h),type:k,method:"GET",status_code:i,success:l},(0,_performance.calcResourceTimingData)(d),{// 异步任务,保证 view_id view_name 正确 |
@@ -12,3 +12,3 @@ "use strict";exports.__esModule=!0,exports.ResourceStatus=void 0,exports.calcResourceTimingData=calcResourceTimingData,exports.getResourceStatusByCode=getResourceStatusByCode;var _base=require("./base"),ResourceStatus=exports.ResourceStatus=/*#__PURE__*/function(a){return a[a.Failed=0]="Failed",a[a.Success=1]="Success",a}({});/** | ||
* @param pt 通过 performance API 获取的性能对象 | ||
*/function calcResourceTimingData(a){var b=a.decodedBodySize,c=a.redirectStart,d=a.redirectEnd,e=a.domainLookupStart,f=a.domainLookupEnd,g=a.connectStart,h=a.secureConnectionStart,i=a.connectEnd,j=a.requestStart,k=a.responseStart,l=a.responseEnd,m=a.duration,n={duration:(0,_base.formatNumber)(m),size:(0,_base.formatNumber)(b),redirect_duration:(0,_base.formatNumber)(d-c),dns_duration:(0,_base.formatNumber)(f-e),connect_duration:(0,_base.formatNumber)(i-g),first_byte_duration:(0,_base.formatNumber)(k-j),download_duration:(0,_base.formatNumber)(l-k),timing_data:JSON.stringify(a)};// 只有最后一个请求通过 HTTPS 连接才会有该属性 | ||
return h&&(n.ssl_duration=(0,_base.formatNumber)(i-h)),n} | ||
*/function calcResourceTimingData(a){var b=a.decodedBodySize,c=a.redirectStart,d=a.redirectEnd,e=a.domainLookupStart,f=a.domainLookupEnd,g=a.connectStart,h=a.secureConnectionStart,i=a.connectEnd,j=a.requestStart,k=a.responseStart,l=a.responseEnd,m=a.duration,n=(0,_base.formatNumber)(d-c),o=(0,_base.formatNumber)(f-e),p=(0,_base.formatNumber)(i-g),q=(0,_base.formatNumber)(k-j),r=(0,_base.formatNumber)(l-k),s={duration:(0,_base.formatNumber)(m),size:(0,_base.formatNumber)(b),redirect_duration:isNaN(n)?void 0:n,dns_duration:isNaN(o)?void 0:o,connect_duration:isNaN(p)?void 0:p,first_byte_duration:isNaN(q)?void 0:q,download_duration:isNaN(r)?void 0:r,timing_data:JSON.stringify(a)};// 只有最后一个请求通过 HTTPS 连接才会有该属性 | ||
return h&&(s.ssl_duration=(0,_base.formatNumber)(i-h)),s} |
{ | ||
"name": "@arms/rum-browser", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "arms rum javascript sdk for browser", | ||
@@ -5,0 +5,0 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38364
426