@arms/rum-miniapp 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ interface IApiAttr {
9
9
  startTime: number;
10
10
  method: string;
11
11
  trace_id?: string;
12
+ trace_data?: string;
12
13
  }
13
14
  interface Options {
14
15
  url: string;
@@ -30,6 +31,7 @@ export default class ApiCollector implements ICollector {
30
31
  hackRequest(key: any): void;
31
32
  rebuildRequestOptions(options: Options): Options;
32
33
  sendApi(apiAttr: any, resp: any, success: any): void;
34
+ private getResourceName;
33
35
  /**
34
36
  * 解析小程序的性能数据
35
37
  * 参考:https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
@@ -1,5 +1,5 @@
1
- "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"),_platform=_interopRequireDefault(require("../../utils/platform")),_url=require("../../utils/url"),_base=require("../../utils/base"),_view=require("../../utils/view"),_uuid=require("../../utils/uuid"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.ctx=void 0,this.sendEvent=void 0,this.origin={request:_platform["default"].request,httpRequest:_platform["default"].httpRequest}}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;!1===f.api||(this.ctx=a,this.sendEvent=b,Object.keys(this.origin).forEach(function(a){return c.hackRequest(a)}))},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){var k=(0,_rumCore.generateTraceId)(),l=(0,_rumCore.generateSpanId)(),m=(0,_rumCore.performDraw)(i),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.hackRequest=function hackRequest(a){var b=this;a in _platform["default"]&&Object.defineProperty(_platform["default"],a,{configurable:!0,enumerable:!0,writable:!0,value:function value(){for(var c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return d[0]=b.rebuildRequestOptions(d[0]),b.origin[a].apply(this,d)}})},b.rebuildRequestOptions=function rebuildRequestOptions(a){var b=this,c=a.url,d=a.success,e=a.fail,f=(0,_base.getCurrentTime)();// SDK自己的请求不监控 & 过滤不需要监控的url
2
- if((0,_url.isEndpoint)(this.ctx,c)||(0,_rumCore.urlMatch)(c))return a;var g=(0,_extends2["default"])({},a),h={view:(0,_view.getCurView)(this.ctx),startTime:f,url:c,name:(0,_url.getPathByURL)(c),method:a.method||"GET"};return this.injectTracing(h,function(a){g.headers=(0,_extends2["default"])({},g.headers,a)}),g.success=function(){for(var a=arguments.length,c=Array(a),e=0;e<a;e++)c[e]=arguments[e];b.sendApi(h,c[0],!0),d&&d.apply(this,c)},g.fail=function(){for(var a=arguments.length,c=Array(a),d=0;d<a;d++)c[d]=arguments[d];b.sendApi(h,c[0],!1),e&&e.apply(this,c)},g},b.sendApi=function sendApi(a,b,c){var d,e,f=(0,_view.getCurView)(this.ctx),g=b.statusCode,h=b.status,i=b.errMsg,j=b.errorMessage,k=b.message,l=b.profile;l&&(d=this.parseProfile(l),e=JSON.stringify(l)),this.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE},a,{type:"api",status_code:h||g,message:j||i||k,view:f,success:c,duration:(0,_base.getCurrentTime)()-a.startTime},d,{times:1,timing_data:e}))}/**
1
+ "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"),_platform=_interopRequireDefault(require("../../utils/platform")),_url=require("../../utils/url"),_base=require("../../utils/base"),_view=require("../../utils/view"),_uuid=require("../../utils/uuid"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.ctx=void 0,this.sendEvent=void 0,this.origin={request:_platform["default"].request,httpRequest:_platform["default"].httpRequest}}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;!1===f.api||(this.ctx=a,this.sendEvent=b,Object.keys(this.origin).forEach(function(a){return c.hackRequest(a)}))},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){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,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,sample:i,headers:s})),b(s)}}},b.hackRequest=function hackRequest(a){var b=this;a in _platform["default"]&&Object.defineProperty(_platform["default"],a,{configurable:!0,enumerable:!0,writable:!0,value:function value(){for(var c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return d[0]=b.rebuildRequestOptions(d[0]),b.origin[a].apply(this,d)}})},b.rebuildRequestOptions=function rebuildRequestOptions(a){var b=this,c=a.url,d=a.success,e=a.fail,f=(0,_base.getCurrentTime)();// SDK自己的请求不监控 & 过滤不需要监控的url
2
+ if((0,_url.isEndpoint)(this.ctx,c)||(0,_rumCore.urlMatch)(c))return a;var g=(0,_extends2["default"])({},a),h={view:(0,_view.getCurView)(this.ctx),startTime:f,url:c,name:this.getResourceName(c),method:a.method||"GET"};return this.injectTracing(h,function(a){g.headers=(0,_extends2["default"])({},g.headers,a)}),g.success=function(){for(var a=arguments.length,c=Array(a),e=0;e<a;e++)c[e]=arguments[e];b.sendApi(h,c[0],!0),d&&d.apply(this,c)},g.fail=function(){for(var a=arguments.length,c=Array(a),d=0;d<a;d++)c[d]=arguments[d];b.sendApi(h,c[0],!1),e&&e.apply(this,c)},g},b.sendApi=function sendApi(a,b,c){var d,e,f=(0,_view.getCurView)(this.ctx),g=b.statusCode,h=b.status,i=b.errMsg,j=b.errorMessage,k=b.message,l=b.profile;l&&(d=this.parseProfile(l),e=JSON.stringify(l)),this.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE},a,{type:"api",status_code:h||g,message:j||i||k,view:f,success:c,duration:(0,_base.getCurrentTime)()-a.startTime},d,{times:1,timing_data:e}))},b.getResourceName=function getResourceName(a){var b=this.ctx.getConfig(),c=b.parseResourceName,d=a;return(0,_rumCore.isFunction)(c)&&(d=c(a)),d||(d=(0,_url.getPathByURL)(a)),d}/**
3
3
  * 解析小程序的性能数据
4
4
  * 参考:https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
5
5
  * https://opendocs.alipay.com/mini/api/owycmh?pathHash=c91640f8
package/lib/shell.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { IConfiguration, Shell } from '@arms/rum-core';
1
+ import { Shell } from '@arms/rum-core';
2
+ import { IMiniappConfig } from "./types/client";
2
3
  /**
3
4
  * 对外导出 shell 层, 所有 shell 层模型的 API 设计约定:
4
5
  * 1. API 命名空间按照 variables / functions / events 来组织
@@ -9,13 +10,13 @@ export declare class ArmsRum extends Shell {
9
10
  /**
10
11
  * 初始化
11
12
  */
12
- init(configuration: IConfiguration): void;
13
+ init(configuration: IMiniappConfig): void;
13
14
  updateNetType: (type: string) => void;
14
15
  /**
15
16
  * set config
16
17
  */
17
- setConfig<T extends keyof IConfiguration>(key: T, value: IConfiguration[T]): void;
18
- setConfig(value: IConfiguration): void;
18
+ setConfig<T extends keyof IMiniappConfig>(key: T, value: IMiniappConfig[T]): void;
19
+ setConfig(value: IMiniappConfig): void;
19
20
  }
20
21
  declare const _default: ArmsRum;
21
22
  export default _default;
@@ -0,0 +1,15 @@
1
+ import { IConfiguration, ITracingOption } from "@arms/rum-core";
2
+ export interface IMiniappConfig extends IConfiguration {
3
+ /**
4
+ * view.name 解析
5
+ */
6
+ parseViewName?(url: string): string;
7
+ /**
8
+ * resource.name 解析
9
+ */
10
+ parseResourceName?(url: string): string;
11
+ /**
12
+ * tracing 配置 'tracecontext' | 'b3' | 'b3multi' | 'jaeger';
13
+ */
14
+ tracing?: boolean | ITracingOption;
15
+ }
@@ -0,0 +1 @@
1
+ "use strict";exports.__esModule=!0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arms/rum-miniapp",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "arms rum javascript sdk for miniapp",
5
5
  "author": "guangli.fj <guangli.fj@alibaba-inc.com>",
6
6
  "license": "ISC",
@@ -22,10 +22,10 @@
22
22
  "test": "node ./__tests__/@arms/miniapp.test.js"
23
23
  },
24
24
  "dependencies": {
25
- "@arms/rum-core": "^0.0.7"
25
+ "@arms/rum-core": "^0.0.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "typescript": "^4.9.4"
29
29
  },
30
- "homepage": "https://unpkg.com/@arms/rum-miniapp@0.0.7/build/index.html"
30
+ "homepage": "https://unpkg.com/@arms/rum-miniapp@0.0.8/build/index.html"
31
31
  }