@arms/rum-browser
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -1,3 +0,3 @@ | ||
"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;if(g){// Browser 情况下一直允许同域请求的trace | ||
var k=(0,_rumCore.generateTraceId)(),l=(0,_rumCore.generateSpanId)(),m=(0,_rumCore.performDraw)(i),n=void 0===j||j?"rum=browser&"+e+"&"+(0,_uuid.getSessionID)():"";h.push({match:function match(a){return /^https?:\/\/*/.test(a)||(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:["tracecontext"]});var o=(0,_rumCore.find)(h,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(o){var p=(0,_rumCore.makeTracingHeaders)(k,l,m,o.propagatorTypes,n);a.trace_id=k,b(p)}}},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c){var d=this,e=c+"";(0,_rumCore.urlMatch)(e)||(// 异步过程 保证 view_id view_name 正确 | ||
"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.baggage;if(g){// Browser 情况下一直允许同域请求的trace | ||
var k=(0,_rumCore.generateTraceId)(),l=(0,_rumCore.generateSpanId)(),m=(0,_rumCore.performDraw)(i);h.push({match:function match(a){return /^https?:\/\/*/.test(a)||(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:["tracecontext"]});var n=(0,_rumCore.find)(h,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(n){var o=(0,_rumCore.makeTracingHeaders)(k,l,m,n.propagatorTypes,void 0===j||j?{appType:"browser",pid:e,sid:(0,_uuid.getSessionID)()}:void 0);m&&(a.trace_id=k),b(o)}}},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c){var d=this,e=c+"";(0,_rumCore.urlMatch)(e)||(// 异步过程 保证 view_id view_name 正确 | ||
this.apiAttr={},this.apiAttr.url=(0,_url.fixRelativeUrl)(e),this.apiAttr.method=a.toUpperCase(),this.apiAttr.view=(0,_view.getCurView)(b.ctx),b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){d.setRequestHeader(b,a[b])})}))}),(0,_rumCore.interceptFunction)(a,"send",function(){var a=this;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;void 0===d&&(d={});var g=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString();if((0,_rumCore.urlMatch)(g))return b.call(global,c,d);var h={};return h.url=(0,_url.fixRelativeUrl)(g),h.method=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET",h.view=(0,_view.getCurView)(a.ctx),a.injectTracing(h,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,h.status_code=d,h.message=e,b.abrupt("return",a);case 5:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}(),function(a){throw h.message=a+"",a})["finally"](function(){a.mergeDataAndSend({attr:h})})}})},b.mergeDataAndSend=function mergeDataAndSend(a){var b=this;try{var c=function(a,c){var d=a.method,e=a.url,f=a.status_code,g=a.message,h=a.view,i=(0,_performance.getResourceStatusByCode)(f);b.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:e,name:(0,_url.getPathByURL)(e),type:c.initiatorType||c.entryType,method:d,status_code:f,message:g,success:i},(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}(); |
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _rumCore=require("@arms/rum-core"),_base=require("../../utils/base"),_url=require("../../utils/url"),_global=require("../../utils/global"),PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.sendPerf=function(){var b=performance.getEntriesByType("navigation")[0],c=b.loadEventEnd,d=b.domInteractive,e=b.domContentLoadedEventEnd,f=b.domComplete,g=performance.getEntriesByType("paint").find(function(a){var b=a.name;return"first-contentful-paint"===b})||{},h=g.startTime;a.sendEvent({event_type:_rumCore.RumEventType.VIEW,type:"perf",url:(0,_url.getCurrentURL)(),referrer:_global.document.referrer||"",loading_type:"initial_load",timing_data:JSON.stringify(b),// Measure | ||
loading_time:(0,_base.formatNumber)(c),first_contentful_paint:(0,_base.formatNumber)(h),dom_interactive:(0,_base.formatNumber)(d),dom_content_loaded:(0,_base.formatNumber)(e),dom_complete:(0,_base.formatNumber)(f)})}}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.perf||(this.ctx=a,this.sendEvent=b,_global.global.addEventListener("load",this.sendPerf))},b.destroy=function destroy(){_global.global.removeEventListener("load",this.sendPerf)},a}(); | ||
// loading_time: formatNumber(loadEventEnd), // 同FMP,基于DOM突变稳定来计算 | ||
first_contentful_paint:(0,_base.formatNumber)(h),dom_interactive:(0,_base.formatNumber)(d),dom_content_loaded:(0,_base.formatNumber)(e),dom_complete:(0,_base.formatNumber)(f),load_event:(0,_base.formatNumber)(c)})}}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.perf||(this.ctx=a,this.sendEvent=b,_global.global.addEventListener("load",this.sendPerf))},b.destroy=function destroy(){_global.global.removeEventListener("load",this.sendPerf)},a}(); |
@@ -1,3 +0,3 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_uuid=require("../utils/uuid"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f=e.pid,g=e.env,h=void 0===g?"prod":g,i=e.version,j=e.endpoint,k=e.beforeReport,l=e.user,m=void 0===l?{}:l,n={app:{id:f,env:h,version:i,type:_rumCore.AppType.broswer},user:(0,_extends2["default"])({id:(0,_uuid.getUserID)()},m),session:{id:(0,_uuid.getSessionID)()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b};if(!("function"==typeof k&&(n=k(n),!n)))try{navigator.sendBeacon(j,JSON.stringify(n))}catch(a){}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/** | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_uuid=require("../utils/uuid"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f=e.pid,g=e.env,h=void 0===g?"prod":g,i=e.version,j=e.endpoint,k=e.beforeReport,l=e.user,m=void 0===l?{}:l,n={app:{id:f,env:h,version:i,type:_rumCore.AppType.browser},user:(0,_extends2["default"])({id:(0,_uuid.getUserID)()},m),session:{id:(0,_uuid.getSessionID)()},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b};if(!("function"==typeof k&&(n=k(n),!n)))try{navigator.sendBeacon(j,JSON.stringify(n))}catch(a){}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/** | ||
* browser reporter | ||
*/ |
@@ -1,2 +0,2 @@ | ||
import { IClient, IShell, RumEvent } from '@arms/rum-core'; | ||
import { Shell, IConfiguration } from '@arms/rum-core'; | ||
import { IBrowserConfig } from "./types/client"; | ||
@@ -6,8 +6,8 @@ /** | ||
*/ | ||
export declare class ArmsRum implements IShell { | ||
client: IClient; | ||
constructor(); | ||
export declare class ArmsRum extends Shell { | ||
/** | ||
* 初始化 | ||
*/ | ||
init(configuration: IBrowserConfig): void; | ||
sendEvent(payload: RumEvent): void; | ||
getConfig(): import("@arms/rum-core").IConfiguration; | ||
getConfig(): IConfiguration; | ||
setConfig<T extends keyof IBrowserConfig>(key: T, value: IBrowserConfig[T]): void; | ||
@@ -14,0 +14,0 @@ setConfig(value: IBrowserConfig): void; |
@@ -1,3 +0,5 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=exports.ArmsRum=void 0;var _extends3=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_pv=_interopRequireDefault(require("./collector/view/pv")),_exception=_interopRequireDefault(require("./collector/exception")),_perf=_interopRequireDefault(require("./collector/view/perf")),_webvitals=_interopRequireDefault(require("./collector/view/webvitals")),_api=_interopRequireDefault(require("./collector/resource/api")),_staticResource=_interopRequireDefault(require("./collector/resource/static-resource")),_click=_interopRequireDefault(require("./collector/action/click")),_defaultProcessor=_interopRequireDefault(require("./processor/default-processor")),_sessionProcessor=_interopRequireDefault(require("./processor/session-processor")),_reporter=_interopRequireDefault(require("./reporter")),_global=require("./utils/global"),ArmsRum=exports.ArmsRum=/*#__PURE__*/function(){function a(){this.client=void 0;var a=_global.global.__rum;a&&this.init(a)}var b=a.prototype;return b.init=function init(a){this.client=new _rumCore.Client,this.client.useCollectors([new _pv["default"],new _perf["default"],new _webvitals["default"],new _exception["default"],new _api["default"],new _staticResource["default"],new _click["default"]]),this.client.useProcessors([new _defaultProcessor["default"],new _sessionProcessor["default"]]),this.client.useReporter(new _reporter["default"]),this.client.init(a)},b.sendEvent=function sendEvent(a){this.client.sendEvent(a)},b.getConfig=function getConfig(){return this.client.getContext().getConfig()},b.setConfig=function setConfig(){var a=this.client.getContext();if(2===arguments.length){var b,c=this.client.getContext(),d=c.getConfig();c.setConfig((0,_extends3["default"])({},d,(b={},b[0>=arguments.length?void 0:arguments[0]]=1>=arguments.length?void 0:arguments[1],b)))}else a.setConfig(0>=arguments.length?void 0:arguments[0])},a}(),_default=exports["default"]=new ArmsRum;/** | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=exports.ArmsRum=void 0;var _extends3=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_pv=_interopRequireDefault(require("./collector/view/pv")),_exception=_interopRequireDefault(require("./collector/exception")),_perf=_interopRequireDefault(require("./collector/view/perf")),_webvitals=_interopRequireDefault(require("./collector/view/webvitals")),_api=_interopRequireDefault(require("./collector/resource/api")),_staticResource=_interopRequireDefault(require("./collector/resource/static-resource")),_click=_interopRequireDefault(require("./collector/action/click")),_defaultProcessor=_interopRequireDefault(require("./processor/default-processor")),_sessionProcessor=_interopRequireDefault(require("./processor/session-processor")),_reporter=_interopRequireDefault(require("./reporter")),_global=require("./utils/global"),ArmsRum=exports.ArmsRum=/*#__PURE__*/function(a){function b(){return a.apply(this,arguments)||this}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=/** | ||
* 初始化 | ||
*/function init(a){this.client.useCollectors([new _pv["default"],new _perf["default"],new _webvitals["default"],new _exception["default"],new _api["default"],new _staticResource["default"],new _click["default"]]),this.client.useProcessors([new _defaultProcessor["default"],new _sessionProcessor["default"]]),this.client.useReporter(new _reporter["default"]),this.client.init(a)},c.getConfig=function getConfig(){return this.client.getContext().getConfig()},c.setConfig=function setConfig(){var a=this.client.getContext();if(2===arguments.length){var b,c=this.client.getContext(),d=c.getConfig();c.setConfig((0,_extends3["default"])({},d,(b={},b[0>=arguments.length?void 0:arguments[0]]=1>=arguments.length?void 0:arguments[1],b)))}else a.setConfig(0>=arguments.length?void 0:arguments[0])},b}(_rumCore.Shell),_default=exports["default"]=new ArmsRum(_global.global.__rum);/** | ||
* browser sdk | ||
*/ |
{ | ||
"name": "@arms/rum-browser", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "arms rum javascript sdk for browser", | ||
@@ -25,3 +25,3 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", | ||
"dependencies": { | ||
"@arms/rum-core": "^0.0.5", | ||
"@arms/rum-core": "^0.0.7", | ||
"web-vitals": "^3.4.0" | ||
@@ -28,0 +28,0 @@ }, |
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
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
36876
410
+ Added@arms/rum-core@0.0.7(transitive)
- Removed@arms/rum-core@0.0.5(transitive)
Updated@arms/rum-core@^0.0.7