Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arms/rum-browser

Package Overview
Dependencies
Maintainers
5
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arms/rum-browser - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

4

lib/collector/resource/api.js
"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
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=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=b.ctx.getConfig(),e=d.parseResourceName,f=a.method,g=a.url,h=a.status_code,i=a.message,j=a.view,k=(0,_performance.getResourceStatusByCode)(h);b.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:g,name:(0,_url.getResourceName)(g,e),type:c.initiatorType||c.entryType,method:f,status_code:h,message:i,success:k},(0,_performance.calcResourceTimingData)(c),{view:j}))},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}();
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+"";(0,_rumCore.urlMatch)(d)||(// 异步过程 保证 view_id view_name 正确
this.apiAttr={},this.apiAttr.url=(0,_url.fixRelativeUrl)(d),this.apiAttr.method=a.toUpperCase(),this.apiAttr.view=(0,_view.getCurView)(b.ctx))}),(0,_rumCore.interceptFunction)(a,"send",function(){var a=this;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;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=b.ctx.getConfig(),e=d.parseResourceName,f=a.method,g=a.url,h=a.status_code,i=a.message,j=a.view,k=(0,_performance.getResourceStatusByCode)(h);b.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:g,name:(0,_url.getResourceName)(g,e),type:c.initiatorType||c.entryType,method:f,status_code:h,message:i,success:k},(0,_performance.calcResourceTimingData)(c),{view:j}))},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}();
{
"name": "@arms/rum-browser",
"version": "0.0.8",
"version": "0.0.9",
"description": "arms rum javascript sdk for browser",

@@ -21,3 +21,2 @@ "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"

@@ -24,0 +23,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc