@arms/rum-browser
Advanced tools
Comparing version 0.0.27-beta.9 to 0.0.27-beta.10
@@ -8,3 +8,3 @@ import { ICollector, IContext, RumEvent, RumExceptionEvent } from '@arms/rum-core'; | ||
onError(source: string, e: Error | ErrorEvent | PromiseRejectionEvent): void; | ||
errorFilter(err: Error): any; | ||
errorFilter(err: Error): boolean; | ||
} |
@@ -9,7 +9,10 @@ import { ICollector, IContext, ITracingHeaders, RumEvent } from '@arms/rum-core'; | ||
} | ||
interface PerfPayload { | ||
attr: IApiAttr; | ||
entry: PerformanceResourceTiming; | ||
} | ||
export default class ApiCollector implements ICollector { | ||
name: string; | ||
private entryTypes; | ||
private cachedEntries; | ||
private cachedApiAttrs; | ||
private entryCacheMap; | ||
private ctx; | ||
@@ -22,6 +25,9 @@ private sendEvent; | ||
hackFetch(): void; | ||
mergeDataAndSend(payload: { | ||
attr?: IApiAttr; | ||
entry?: PerformanceResourceTiming; | ||
delayHandle(payload: PerfPayload): void; | ||
mergeEntry({ attr, entry }: { | ||
attr: any; | ||
entry: any; | ||
}): void; | ||
findRealEntry(fakeEntry: PerformanceResourceTiming): PerformanceResourceTiming; | ||
} | ||
export {}; |
@@ -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")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_base=require("../../utils/base"),_global=require("../../utils/global"),_api=require("../../utils/api"),PerfObserver=_global.global.PerformanceObserver,ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=Object.values(_api.ApiType),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().collectors||{};!1===c.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({entryTypes:["resource"]})}},b.injectTracing=function injectTracing(a,b){var c,d=this.ctx.getConfig(),e=d.tracing,f=d.pid,g=d.version,h=void 0===g?"1.0.0":g,i=(0,_rumCore.parseTracingOptions)(e),j=i.enable,k=i.sample,l=i.propagatorTypes,m=i.allowedUrls,n=i.tracestate,o=i.baggage;if(j){m.push({match:function match(a){return /^https?:\/\/*/.test(a)&&(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:l});var p=(0,_rumCore.find)(m,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(p){var q=p.propagatorTypes;0===q.length&&(q=l);// skywalking | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_base=require("../../utils/base"),_global=require("../../utils/global"),_api=require("../../utils/api"),PerfObserver=_global.global.PerformanceObserver,ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=Object.values(_api.ApiType),this.entryCacheMap={},this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig().collectors||{};!1===c.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){var c=b.name;a.entryCacheMap[c]?a.entryCacheMap[c].push(b):a.entryCacheMap[c]=[b]})});b.observe({entryTypes:["resource"]})}},b.injectTracing=function injectTracing(a,b){var c,d=this.ctx.getConfig(),e=d.tracing,f=d.pid,g=d.version,h=void 0===g?"1.0.0":g,i=(0,_rumCore.parseTracingOptions)(e),j=i.enable,k=i.sample,l=i.propagatorTypes,m=i.allowedUrls,n=i.tracestate,o=i.baggage;if(j){m.push({match:function match(a){return /^https?:\/\/*/.test(a)&&(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:l});var p=(0,_rumCore.find)(m,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(p){var q=p.propagatorTypes;0===q.length&&(q=l);// skywalking | ||
var r=!1;-1<q.indexOf("sw8")&&(q=["sw8"],r=!0);var s=this.ctx.session,t=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateTraceId)(),u=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateSpanId)(),v=(0,_rumCore.performDraw)(k),w=s.getUserId(),x=s.getSessionId(),y=void 0===n||n?"rum=v2&browser&"+f+"&"+x+"&"+w:void 0,z=void 0!==o&&o?"rum=v2,appType=browser,pid="+f+",sid="+x+",uid="+w:void 0,A=(0,_rumCore.makeTracingHeaders)(t,u,v,q,{tracestate:y,baggage:z,appId:f,appVersion:h,viewName:null===(c=a.view)||void 0===c?void 0:c.name,host:_global.location.host});v&&(a.trace_id=t,a.trace_data=JSON.stringify({spanId:u,sample:k,sampled:v,headers:A})),b(A)}}// Browser 情况下一直允许同域请求的trace | ||
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!((0,_rumCore.urlMatch)(g)||"HEAD"===h)){this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},i,{url:(0,_url.fixRelativeUrl)(g),method:h})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),this.addEventListener("loadend",/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function a(){var e,f,g,h,i,j,k,l;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,(0,_rumCore.isFunction)(PerfObserver)||(j={name:c.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-d.timestamp}),!(0,_rumCore.isFunction)(i)){a.next=16;break}return a.prev=6,d.success===_rumCore.ResourceStatus.Failed&&(k=new Error(_api.ApiType.XHR+" error")),a.next=10,i(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=(0,_extends2["default"])({},c.apiAttr,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.mergeDataAndSend({attr:c.apiAttr,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=_rumCore.ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;function h(){return i.apply(this,arguments)}function i(){return i=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,(0,_rumCore.isFunction)(PerfObserver)||(g={name:o.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-o.timestamp}),!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:c},d),l,m);case 6:h=b.sent,o=(0,_extends2["default"])({},o,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.mergeDataAndSend({attr:o,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),i.apply(this,arguments)}void 0===d&&(d={});var j=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),k=(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)(j)||"HEAD"===k||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var l,m,n=a.ctx.session.getBaseEvent(),o=(0,_extends2["default"])({},n,{url:(0,_url.fixRelativeUrl)(j),type:_api.ApiType.FETCH,method:k});return a.injectTracing(o,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(function(a){l=a.clone();var b=l,c=b.status,d=b.statusText;return o.status_code=c,o.message=d,h().then(),a})["catch"](function(a){throw m=a,o.message=a+"",o.success=_rumCore.ResourceStatus.Failed,h().then(),a})}})},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.getResourceSuccessByCode)(g),j=(0,_performance.calcResourceTimingData)(c)||{duration:c.duration},k=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},a,{timing_data:JSON.stringify(c)},j,{view:h});b.sendEvent(k)},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);this.cachedEntries=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);this.cachedApiAttrs=f.filter(function(a){return a.url!==i.url}),c(i,e)}}catch(a){}},a}(); | ||
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!((0,_rumCore.urlMatch)(g)||"HEAD"===h)){this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},i,{url:(0,_url.fixRelativeUrl)(g),method:h})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),this.addEventListener("loadend",/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function a(){var e,f,g,h,i,j,k,l;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,j={name:c.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-d.timestamp},!(0,_rumCore.isFunction)(i)){a.next=16;break}return a.prev=6,d.success===_rumCore.ResourceStatus.Failed&&(k=new Error(_api.ApiType.XHR+" error")),a.next=10,i(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=(0,_extends2["default"])({},c.apiAttr,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.delayHandle({attr:d,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=_rumCore.ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;function h(){return i.apply(this,arguments)}function i(){return i=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,g={name:o.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-o.timestamp},!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:c},d),l,m);case 6:h=b.sent,o=(0,_extends2["default"])({},o,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.delayHandle({attr:o,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),i.apply(this,arguments)}void 0===d&&(d={});var j=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),k=(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)(j)||"HEAD"===k||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var l,m,n=a.ctx.session.getBaseEvent(),o=(0,_extends2["default"])({},n,{url:(0,_url.fixRelativeUrl)(j),type:_api.ApiType.FETCH,method:k});return a.injectTracing(o,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(function(a){l=a.clone();var b=l,c=b.status,d=b.statusText;return o.status_code=c,o.message=d,h().then(),a})["catch"](function(a){throw m=a,o.message=a+"",o.success=_rumCore.ResourceStatus.Failed,h().then(),a})}})},b.delayHandle=function delayHandle(a){var b=this;(0,_rumCore.delay)(function(){b.mergeEntry(a)},200)},b.mergeEntry=function mergeEntry(a){var b=a.attr,c=a.entry;c=this.findRealEntry(c);var d=this.ctx.getConfig(),e=d.parseResourceName,f=b.url,g=b.status_code,h=b.view;b.name=(0,_url.getResourceName)(f,e);var i=(0,_performance.getResourceSuccessByCode)(g),j=(0,_performance.calcResourceTimingData)(c)||{duration:c.duration},k=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},b,{timing_data:JSON.stringify(c)},j,{view:h});this.sendEvent(k)},b.findRealEntry=function findRealEntry(a){var b=a.name,c=this.entryCacheMap[b]||[],d=c.shift();return c.length||delete this.entryCacheMap[b],d||a},a}(); |
@@ -1,2 +0,2 @@ | ||
import { ICollector, IContext, RumEvent } from "@arms/rum-core"; | ||
import { ICollector, IContext, IViewData, RumEvent } from "@arms/rum-core"; | ||
interface RumPerfResTiming extends PerformanceResourceTiming { | ||
@@ -3,0 +3,0 @@ responseStatus?: number; |
@@ -1,13 +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"),_url=require("../../utils/url"),_global=require("../../utils/global"),PerfObserver=_global.global.PerformanceObserver,MAX_DELAY=600000,PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.perfObserver=void 0,this.eventCache=void 0,this.perfHandler=function(b){// if (!event) { | ||
// const view = getCurView(this.ctx); | ||
// event = this.eventCache = { | ||
// event_type: RumEventType.VIEW, | ||
// type: 'perf', | ||
// url: getCurrentURL(), | ||
// referrer: document.referrer || '', | ||
// // 异步任务,保证 view_id view_name 正确 | ||
// view | ||
// } | ||
// } | ||
for(var c=b.getEntries(),d=a.eventCache,e=0;e<c.length;e++)try{var f=c[e];switch(f.entryType){case"navigation":var g=f.fetchStart,h=f.responseEnd,j=f.domInteractive,k=f.domContentLoadedEventEnd,l=f.domComplete,m=f.loadEventEnd;d.dom_interactive=(0,_rumCore.formatNumber)(j-g),d.dom_content_loaded=(0,_rumCore.formatNumber)(k-g),d.dom_complete=(0,_rumCore.formatNumber)(l-g),d.load_event=(0,_rumCore.formatNumber)(m-g),d.first_paint=(0,_rumCore.formatNumber)(h-g),a.sendPerf();break;case"paint":"first-paint"===f.name&&f.startTime<MAX_DELAY?d.first_paint=(0,_rumCore.formatNumber)(f.startTime):"first-contentful-paint"===f.name&&f.startTime<MAX_DELAY&&(d.first_contentful_paint=(0,_rumCore.formatNumber)(f.startTime));break;// 放入 web-vitals 里面处理 与 first_input_delay 一起处理 | ||
"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"),_url=require("../../utils/url"),_global=require("../../utils/global"),_performance=require("../../utils/performance"),PerfObserver=_global.global.PerformanceObserver,MAX_DELAY=10*_rumCore.ONE_MINUTE,checkKeys=["dom_interactive","dom_content_loaded","dom_complete","load_event","first_paint","first_contentful_paint"],PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.perfObserver=void 0,this.eventCache=void 0,this.perfHandler=function(b){for(var c=b.getEntries(),d=a.eventCache,e=0;e<c.length;e++)try{var f=c[e];switch(f.entryType){case"navigation":var g=f.fetchStart,h=f.responseEnd,j=f.domInteractive,k=f.domContentLoadedEventEnd,l=f.domComplete,m=f.loadEventEnd;d.dom_interactive=(0,_rumCore.formatNumber)(j-g),d.dom_content_loaded=(0,_rumCore.formatNumber)(k-g),d.dom_complete=(0,_rumCore.formatNumber)(l-g),d.load_event=(0,_rumCore.formatNumber)(m-g),d.first_paint=(0,_rumCore.formatNumber)(h-g),a.sendPerf();break;case"paint":"first-paint"===f.name&&f.startTime<MAX_DELAY?d.first_paint=(0,_rumCore.formatNumber)(f.startTime):"first-contentful-paint"===f.name&&f.startTime<MAX_DELAY&&(d.first_contentful_paint=(0,_rumCore.formatNumber)(f.startTime));break;// 放入 web-vitals 里面处理 与 first_input_delay 一起处理 | ||
// case 'first-input': | ||
@@ -19,2 +8,2 @@ // if (entry.startTime < MAX_DELAY) { | ||
default:return}}catch(a){// console.warn('RUM-perfHandler', e) | ||
}},this.sendPerf=function(){a.eventCache&&a.perfObserver&&(a.sendEvent(a.eventCache),a.eventCache=null,a.perfObserver.disconnect(),a.perfObserver=null)}}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig().collectors||{};if(!1!==d.perf&&(this.ctx=a,this.sendEvent=b,this.sendPerf=(0,_rumCore.debounce)(this.sendPerf,200),!!(0,_rumCore.isFunction)(PerfObserver))){this.perfObserver=new PerfObserver(function(a){(0,_rumCore.delay)(c.perfHandler,200,a)}),this.perfObserver.observe({entryTypes:["navigation","paint"]});var e=this.ctx.session.getBaseEvent();this.eventCache=(0,_extends2["default"])({},e,{event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||""})}},a}();// 10分钟 | ||
}},this.sendPerf=function(){a.eventCache&&a.perfObserver&&(a.sendEvent((0,_performance.delBadMea)(a.eventCache,checkKeys)),a.eventCache=null,a.perfObserver.disconnect(),a.perfObserver=null)}}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig().collectors||{};if(!1!==d.perf&&(this.ctx=a,this.sendEvent=b,this.sendPerf=(0,_rumCore.debounce)(this.sendPerf,200),!!(0,_rumCore.isFunction)(PerfObserver))){this.perfObserver=new PerfObserver(function(a){(0,_rumCore.delay)(c.perfHandler,200,a)}),this.perfObserver.observe({entryTypes:["navigation","paint"]});var e=this.ctx.session.getBaseEvent();this.eventCache=(0,_extends2["default"])({},e,{event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||""})}},a}();// 10分钟 |
@@ -1,2 +0,2 @@ | ||
import { IContext, IProcessor } from "@arms/rum-core"; | ||
import { IContext, IProcessor, RumEvent } from "@arms/rum-core"; | ||
export default class DefaultProcessor implements IProcessor { | ||
@@ -3,0 +3,0 @@ name: string; |
@@ -7,3 +7,3 @@ import { IContext, IProcessor } from "@arms/rum-core"; | ||
update: (e?: Event) => void; | ||
process(ctx: IContext): any; | ||
process(ctx: IContext): import("@arms/rum-core").RumEvent; | ||
} |
@@ -12,3 +12,3 @@ import { Shell } from '@arms/rum-core'; | ||
init(configuration: IBrowserConfig): void; | ||
getConfig(): any; | ||
getConfig(): import("@arms/rum-core").IConfiguration; | ||
setConfig<T extends keyof IBrowserConfig>(key: T, value: IBrowserConfig[T]): void; | ||
@@ -15,0 +15,0 @@ setConfig(value: IBrowserConfig): void; |
@@ -1,1 +0,1 @@ | ||
"use strict";exports.__esModule=!0,exports.ApiType=void 0,exports.reviseApiAttr=reviseApiAttr;var _rumCore=require("@arms/rum-core"),ApiType=exports.ApiType={XHR:"xmlhttprequest",FETCH:"fetch"};function reviseApiAttr(a){if((0,_rumCore.isObject)(a)){var b={};return(0,_rumCore.isString)(a.name)&&(b.name=a.name.substring(0,1e3)),(0,_rumCore.isString)(a.message)&&(b.message=a.message.substring(0,1e3)),(0,_rumCore.isNumber)(a.success)&&-1<=a.success&&1>=a.success&&(b.success=a.success),(0,_rumCore.isNumber)(a.duration)&&0<=a.duration&&(b.duration=a.duration),(0,_rumCore.isString)(a.status_code)&&(b.status_code=a.status_code.substring(0,100)),(0,_rumCore.isNumber)(a.status_code)&&(b.status_code=a.status_code),(0,_rumCore.isString)(a.snapshots)&&(b.snapshots=a.snapshots.substring(0,5e3)),b}} | ||
"use strict";exports.__esModule=!0,exports.ApiType=void 0,exports.reviseApiAttr=reviseApiAttr;var _rumCore=require("@arms/rum-core"),ApiType=exports.ApiType={XHR:"xmlhttprequest",FETCH:"fetch"};function reviseApiAttr(a){if((0,_rumCore.isObject)(a)){var b={};return(0,_rumCore.isString)(a.name)&&(b.name=a.name.substring(0,1e3)),(0,_rumCore.isString)(a.message)&&(b.message=a.message.substring(0,1e3)),(0,_rumCore.isNumber)(a.success)&&-1<=a.success&&1>=a.success&&(b.success=a.success),(0,_rumCore.isNumber)(a.duration)&&0<=a.duration&&(b.duration=a.duration),(0,_rumCore.isString)(a.status_code)&&(b.status_code=a.status_code.substring(0,100)),(0,_rumCore.isNumber)(a.status_code)&&(b.status_code=a.status_code),(0,_rumCore.isString)(a.snapshots)&&(b.snapshots=a.snapshots.substring(0,5e3)),(0,_rumCore.isString)(a.trace_id)&&(b.trace_id=a.trace_id.substring(0,100)),b}} |
@@ -1,1 +0,1 @@ | ||
"use strict";exports.__esModule=!0,exports.location=exports.history=exports.global=exports.document=exports.VERSION=void 0;var global=exports.global=window,document=exports.document=window.document,location=exports.location=window.location,history=exports.history=window.history,VERSION=exports.VERSION='0.0.27-beta.9'; | ||
"use strict";exports.__esModule=!0,exports.location=exports.history=exports.global=exports.document=exports.VERSION=void 0;var global=exports.global=window,document=exports.document=window.document,location=exports.location=window.location,history=exports.history=window.history,VERSION=exports.VERSION='0.0.27-beta.10'; |
@@ -0,1 +1,2 @@ | ||
import { ResourceStatus } from '@arms/rum-core'; | ||
/** | ||
@@ -77,1 +78,2 @@ * Resource 事件的时间度量 | ||
export declare function getResourceType(url: string, initiatorType: string): ResourceType; | ||
export declare function delBadMea(data: any, checkKeys?: string[], scope?: number[]): object; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _rumCore=require("@arms/rum-core");exports.__esModule=!0,exports.ResourceType=exports.RESOURCE_TYPES=exports.FAKE_INITIAL_DOCUMENT=void 0,exports.calcResourceTimingData=calcResourceTimingData,exports.getResourceStatus=getResourceStatus,exports.getResourceSuccessByCode=getResourceSuccessByCode,exports.getResourceType=getResourceType;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}/** | ||
"use strict";var _rumCore=require("@arms/rum-core");exports.__esModule=!0,exports.ResourceType=exports.RESOURCE_TYPES=exports.FAKE_INITIAL_DOCUMENT=void 0,exports.calcResourceTimingData=calcResourceTimingData,exports.delBadMea=delBadMea,exports.getResourceStatus=getResourceStatus,exports.getResourceSuccessByCode=getResourceSuccessByCode,exports.getResourceType=getResourceType;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}/** | ||
* Resource 事件的时间度量 | ||
@@ -22,2 +22,2 @@ */ /** | ||
)return}// Firefox 以及其他不提供对跨原点请求的重定向计时。提供一个默认值。 | ||
h<c&&(h=c),i<c&&(i=d);var s={duration:r};return n&&(s.connect_duration=(0,_rumCore.formatNumber)(n-l)),k&&(s.dns_duration=(0,_rumCore.formatNumber)(k-j)),i&&(s.redirect_duration=(0,_rumCore.formatNumber)(i-h)),p&&(s.download_duration=(0,_rumCore.formatNumber)(q-p),s.first_byte_duration=(0,_rumCore.formatNumber)(p-o)),g&&(s.size=(0,_rumCore.formatNumber)(g)),e&&(s.transfer_size=(0,_rumCore.formatNumber)(e)),m&&(s.ssl_duration=(0,_rumCore.formatNumber)(n-m)),s}var ResourceType=exports.ResourceType=/*#__PURE__*/function(a){return a.DOCUMENT="document",a.XHR="xmlhttprequest",a.BEACON="beacon",a.FETCH="fetch",a.CSS="css",a.JS="js",a.IMAGE="image",a.FONT="font",a.MEDIA="media",a.OTHER="other",a}({}),FAKE_INITIAL_DOCUMENT=exports.FAKE_INITIAL_DOCUMENT="initial_document",RESOURCE_TYPES=exports.RESOURCE_TYPES=[[ResourceType.DOCUMENT,function(a){return FAKE_INITIAL_DOCUMENT===a}],[ResourceType.XHR,function(a){return"xmlhttprequest"===a}],[ResourceType.FETCH,function(a){return"fetch"===a}],[ResourceType.BEACON,function(a){return"beacon"===a}],[ResourceType.CSS,function(a,b){return /\.css$/i.test(b)}],[ResourceType.JS,function(a,b){return /\.js$/i.test(b)}],[ResourceType.IMAGE,function(a,b){return["image","img","icon"].includes(a)||null!==/\.(gif|jpg|jpeg|tiff|png|svg|ico)$/i.exec(b)}],[ResourceType.FONT,function(a,b){return null!==/\.(woff|eot|woff2|ttf)$/i.exec(b)}],[ResourceType.MEDIA,function(a,b){return["audio","video"].includes(a)||null!==/\.(mp3|mp4)$/i.exec(b)}]];function getResourceType(a,b){var c;try{c=new URL(a)}catch(a){return ResourceType.OTHER}for(var d,e=c.pathname,f=_createForOfIteratorHelperLoose(RESOURCE_TYPES);!(d=f()).done;){var g=d.value,h=g[0],i=g[1];if(i(b,e))return h}return ResourceType.OTHER} | ||
h<c&&(h=c),i<c&&(i=d);var s={duration:r};return n&&(s.connect_duration=(0,_rumCore.formatNumber)(n-l)),k&&(s.dns_duration=(0,_rumCore.formatNumber)(k-j)),i&&(s.redirect_duration=(0,_rumCore.formatNumber)(i-h)),p&&(s.download_duration=(0,_rumCore.formatNumber)(q-p),s.first_byte_duration=(0,_rumCore.formatNumber)(p-o)),g&&(s.size=(0,_rumCore.formatNumber)(g)),e&&(s.transfer_size=(0,_rumCore.formatNumber)(e)),m&&(s.ssl_duration=(0,_rumCore.formatNumber)(n-m)),delBadMea(s)}var ResourceType=exports.ResourceType=/*#__PURE__*/function(a){return a.DOCUMENT="document",a.XHR="xmlhttprequest",a.BEACON="beacon",a.FETCH="fetch",a.CSS="css",a.JS="js",a.IMAGE="image",a.FONT="font",a.MEDIA="media",a.OTHER="other",a}({}),FAKE_INITIAL_DOCUMENT=exports.FAKE_INITIAL_DOCUMENT="initial_document",RESOURCE_TYPES=exports.RESOURCE_TYPES=[[ResourceType.DOCUMENT,function(a){return FAKE_INITIAL_DOCUMENT===a}],[ResourceType.XHR,function(a){return"xmlhttprequest"===a}],[ResourceType.FETCH,function(a){return"fetch"===a}],[ResourceType.BEACON,function(a){return"beacon"===a}],[ResourceType.CSS,function(a,b){return /\.css$/i.test(b)}],[ResourceType.JS,function(a,b){return /\.js$/i.test(b)}],[ResourceType.IMAGE,function(a,b){return["image","img","icon"].includes(a)||null!==/\.(gif|jpg|jpeg|tiff|png|svg|ico)$/i.exec(b)}],[ResourceType.FONT,function(a,b){return null!==/\.(woff|eot|woff2|ttf)$/i.exec(b)}],[ResourceType.MEDIA,function(a,b){return["audio","video"].includes(a)||null!==/\.(mp3|mp4)$/i.exec(b)}]];function getResourceType(a,b){var c;try{c=new URL(a)}catch(a){return ResourceType.OTHER}for(var d,e=c.pathname,f=_createForOfIteratorHelperLoose(RESOURCE_TYPES);!(d=f()).done;){var g=d.value,h=g[0],i=g[1];if(i(b,e))return h}return ResourceType.OTHER}var resCheckKeys=["duration","connect_duration","ssl_duration","dns_duration","redirect_duration","first_byte_duration","download_duration"];function delBadMea(a,b,c){if(void 0===b&&(b=resCheckKeys),void 0===c&&(c=[0,_rumCore.ONE_HOUR]),!!(0,_rumCore.isObject)(a))return b.forEach(function(b){!(b in a)||(a[b]<=c[0]||a[b]>=c[1])&&delete a[b]}),a} |
@@ -19,4 +19,4 @@ import { IContext, SessionConfig, IRumSession, RumEvent } from "@arms/rum-core"; | ||
getSessionInfo(): SessionInfo; | ||
getEventId(): any; | ||
getViewId(): any; | ||
getEventId(): string; | ||
getViewId(): string; | ||
getUserId(): string; | ||
@@ -27,3 +27,5 @@ private resetSession; | ||
getBaseEvent(): RumEvent; | ||
setItem(key: string, value: string): void; | ||
getItem(key: string): string; | ||
} | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
"use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),_view=require("./view"),USER_ID="_arms_uid",RUM_SESSION="_arms_session",RumSession=exports.RumSession=/*#__PURE__*/function(){function a(){this.ctx=void 0,this.sessionConfig=void 0}var b=a.prototype;return b.init=function init(a){this.sessionConfig=this.fixSessionConfig(a.sessionConfig)},b.getSessionId=function getSessionId(){return this.getSessionInfo().sessionId},b.getSampled=function getSampled(){return this.getSessionInfo().sampled},b.checkSession=function checkSession(a){var b=this.sessionConfig,c=b.overtime,d=b.maxDuration,e=(0,_base.getCurrentTime)();return!(a.startTime+d<e||a.lastTime+c<e)},b.updateSession=function updateSession(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;localStorage.setItem(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function getSessionInfo(){var a=(localStorage.getItem(RUM_SESSION)||"").split("-"),b=a[0],c=a[1],d=a[2],e=a[3],f={sessionId:b,sampled:"0"!==c,startTime:parseInt(d||"")||0,lastTime:parseInt(e||"")||0};return this.checkSession(f)||(f=this.resetSession()),f},b.getEventId=function getEventId(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function getViewId(){return this.getUUID()},b.getUserId=function getUserId(){var a=localStorage.getItem(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),localStorage.setItem(USER_ID,a)),a},b.resetSession=function resetSession(){var a=this.sessionConfig.sampleRate,b=this.getUUID(),c=(0,_base.getCurrentTime)(),d=(0,_rumCore.performDraw)(100*a),e=b+"-"+(d?1:0)+"-"+c+"-"+c;return localStorage.setItem(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function getUUID(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function fixSessionConfig(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime;return(!(0,_rumCore.isNumber)(c)||0>c||1<c)&&(c=1),(!(0,_rumCore.isNumber)(d)||d<4*_rumCore.ONE_HOUR||d>_rumCore.ONE_DAY)&&(d=_rumCore.ONE_DAY),(!(0,_rumCore.isNumber)(e)||e>_rumCore.ONE_HOUR||e<10*_rumCore.ONE_MINUTE)&&(e=_rumCore.ONE_HOUR),{sampleRate:c,maxDuration:d,overtime:e}},b.getBaseEvent=function getBaseEvent(){var a={timestamp:(0,_base.getCurrentTime)(),session_id:this.getSessionId(),event_id:this.getEventId(),view:this.ctx?(0,_view.getCurView)(this.ctx):void 0,times:1};return a},a}();// 存储userID的键名 | ||
"use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),_view=require("./view"),_cookie=require("./cookie"),USER_ID="_arms_uid",RUM_SESSION="_arms_session",RumSession=exports.RumSession=/*#__PURE__*/function(){function a(){this.ctx=void 0,this.sessionConfig=void 0}var b=a.prototype;return b.init=function init(a){this.sessionConfig=this.fixSessionConfig(a.sessionConfig)},b.getSessionId=function getSessionId(){return this.getSessionInfo().sessionId},b.getSampled=function getSampled(){return this.getSessionInfo().sampled},b.checkSession=function checkSession(a){var b=this.sessionConfig,c=b.overtime,d=b.maxDuration,e=(0,_base.getCurrentTime)();return!(a.startTime+d<e||a.lastTime+c<e)},b.updateSession=function updateSession(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;this.setItem(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function getSessionInfo(){var a=(this.getItem(RUM_SESSION)||"").split("-"),b=a[0],c=a[1],d=a[2],e=a[3],f={sessionId:b,sampled:"0"!==c,startTime:parseInt(d||"")||0,lastTime:parseInt(e||"")||0};return this.checkSession(f)||(f=this.resetSession()),f},b.getEventId=function getEventId(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function getViewId(){return this.getUUID()},b.getUserId=function getUserId(){var a=this.getItem(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),this.setItem(USER_ID,a)),a},b.resetSession=function resetSession(){var a=this.sessionConfig.sampleRate,b=this.getUUID(),c=(0,_base.getCurrentTime)(),d=(0,_rumCore.performDraw)(100*a),e=b+"-"+(d?1:0)+"-"+c+"-"+c;return this.setItem(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function getUUID(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function fixSessionConfig(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime,f=b.storage;return(!(0,_rumCore.isNumber)(c)||0>c||1<c)&&(c=1),(!(0,_rumCore.isNumber)(d)||d<4*_rumCore.ONE_HOUR||d>_rumCore.ONE_DAY)&&(d=_rumCore.ONE_DAY),(!(0,_rumCore.isNumber)(e)||e>_rumCore.ONE_HOUR||e<10*_rumCore.ONE_MINUTE)&&(e=30*_rumCore.ONE_MINUTE),"cookie"!==f&&(f="localStorage"),{sampleRate:c,maxDuration:d,overtime:e,storage:f}},b.getBaseEvent=function getBaseEvent(){var a={timestamp:(0,_base.getCurrentTime)(),session_id:this.getSessionId(),event_id:this.getEventId(),view:this.ctx?(0,_view.getCurView)(this.ctx):void 0,times:1};return a},b.setItem=function setItem(a,b){"cookie"===this.sessionConfig.storage?(0,_cookie.setCookie)(a,b,365*_rumCore.ONE_DAY):localStorage.setItem(a,b)},b.getItem=function getItem(a){return"cookie"===this.sessionConfig.storage?(0,_cookie.getCookie)(a):void localStorage.getItem(a)},a}();// 存储userID的键名 | ||
// 存储session |
@@ -7,2 +7,2 @@ import { IContext } from "@arms/rum-core"; | ||
*/ | ||
export declare function getCurView(ctx: IContext): any; | ||
export declare function getCurView(ctx: IContext): import("@arms/rum-core").IViewData; |
{ | ||
"name": "@arms/rum-browser", | ||
"version": "0.0.27-beta.9", | ||
"version": "0.0.27-beta.10", | ||
"description": "arms rum javascript sdk for browser", | ||
@@ -22,11 +22,13 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", | ||
"build": "build-scripts build --skip-demo", | ||
"prepublishOnly": "npm run build", | ||
"test": "node ./__tests__/@arms/browser.test.js" | ||
}, | ||
"dependencies": { | ||
"@arms/rum-core": "0.0.25-beta.18", | ||
"@arms/rum-core": "0.0.25-beta.19", | ||
"web-vitals": "3.5.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/runtime": "^7.24.5", | ||
"typescript": "^4.9.4" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances 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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
221220
62
1008
2
21
+ Added@arms/rum-core@0.0.25-beta.19(transitive)
- Removed@arms/rum-core@0.0.25-beta.18(transitive)