@arms/rum-core 0.0.4 → 0.0.7

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.
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import Client from './model/client';
2
2
  import Context from './model/context';
3
3
  import Reporter from './model/reporter';
4
+ import Shell from './model/shell';
4
5
  export * from './types/client';
5
6
  export * from './types/collector';
6
7
  export * from './types/processor';
@@ -8,5 +9,9 @@ export * from './types/reporter';
8
9
  export * from './types/rum-event';
9
10
  export * from './types/shell';
10
11
  export * from './utils/base';
12
+ export * from './utils/polyfills';
11
13
  export * from './utils/is';
12
- export { Client, Context, Reporter };
14
+ export * from './utils/number';
15
+ export * from './utils/match';
16
+ export * from './utils/trace';
17
+ export { Client, Context, Reporter, Shell };
package/lib/index.js CHANGED
@@ -5,7 +5,8 @@ exports.__esModule = true;
5
5
  var _exportNames = {
6
6
  Client: true,
7
7
  Context: true,
8
- Reporter: true
8
+ Reporter: true,
9
+ Shell: true
9
10
  };
10
11
  var _client = _interopRequireDefault(require("./model/client"));
11
12
  exports.Client = _client["default"];
@@ -13,6 +14,8 @@ var _context = _interopRequireDefault(require("./model/context"));
13
14
  exports.Context = _context["default"];
14
15
  var _reporter = _interopRequireDefault(require("./model/reporter"));
15
16
  exports.Reporter = _reporter["default"];
17
+ var _shell = _interopRequireDefault(require("./model/shell"));
18
+ exports.Shell = _shell["default"];
16
19
  var _client2 = require("./types/client");
17
20
  Object.keys(_client2).forEach(function (key) {
18
21
  if (key === "default" || key === "__esModule") return;
@@ -48,12 +51,12 @@ Object.keys(_rumEvent).forEach(function (key) {
48
51
  if (key in exports && exports[key] === _rumEvent[key]) return;
49
52
  exports[key] = _rumEvent[key];
50
53
  });
51
- var _shell = require("./types/shell");
52
- Object.keys(_shell).forEach(function (key) {
54
+ var _shell2 = require("./types/shell");
55
+ Object.keys(_shell2).forEach(function (key) {
53
56
  if (key === "default" || key === "__esModule") return;
54
57
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
55
- if (key in exports && exports[key] === _shell[key]) return;
56
- exports[key] = _shell[key];
58
+ if (key in exports && exports[key] === _shell2[key]) return;
59
+ exports[key] = _shell2[key];
57
60
  });
58
61
  var _base = require("./utils/base");
59
62
  Object.keys(_base).forEach(function (key) {
@@ -62,10 +65,38 @@ Object.keys(_base).forEach(function (key) {
62
65
  if (key in exports && exports[key] === _base[key]) return;
63
66
  exports[key] = _base[key];
64
67
  });
68
+ var _polyfills = require("./utils/polyfills");
69
+ Object.keys(_polyfills).forEach(function (key) {
70
+ if (key === "default" || key === "__esModule") return;
71
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
72
+ if (key in exports && exports[key] === _polyfills[key]) return;
73
+ exports[key] = _polyfills[key];
74
+ });
65
75
  var _is = require("./utils/is");
66
76
  Object.keys(_is).forEach(function (key) {
67
77
  if (key === "default" || key === "__esModule") return;
68
78
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
69
79
  if (key in exports && exports[key] === _is[key]) return;
70
80
  exports[key] = _is[key];
81
+ });
82
+ var _number = require("./utils/number");
83
+ Object.keys(_number).forEach(function (key) {
84
+ if (key === "default" || key === "__esModule") return;
85
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
86
+ if (key in exports && exports[key] === _number[key]) return;
87
+ exports[key] = _number[key];
88
+ });
89
+ var _match = require("./utils/match");
90
+ Object.keys(_match).forEach(function (key) {
91
+ if (key === "default" || key === "__esModule") return;
92
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
93
+ if (key in exports && exports[key] === _match[key]) return;
94
+ exports[key] = _match[key];
95
+ });
96
+ var _trace = require("./utils/trace");
97
+ Object.keys(_trace).forEach(function (key) {
98
+ if (key === "default" || key === "__esModule") return;
99
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
100
+ if (key in exports && exports[key] === _trace[key]) return;
101
+ exports[key] = _trace[key];
71
102
  });
@@ -41,7 +41,6 @@ var Client = /*#__PURE__*/function () {
41
41
  return true;
42
42
  };
43
43
  }
44
- ;
45
44
  if (processor.match(ctx)) {
46
45
  var res = processor.process(ctx);
47
46
  if (res) {
@@ -1,5 +1,5 @@
1
- import { IConfiguration, IContext, IViewData } from "../types/client";
2
- import { RumEvent } from "../types/rum-event";
1
+ import { IConfiguration, IContext } from "../types/client";
2
+ import { RumEvent, IViewData } from "../types/rum-event";
3
3
  declare class Context implements IContext {
4
4
  private config;
5
5
  private rumEvent;
@@ -1,5 +1,5 @@
1
- import { IContext, IViewData } from '../types/client';
2
- import { RumEvent } from '../types/rum-event';
1
+ import { IContext } from '../types/client';
2
+ import { RumEvent, IViewData } from '../types/rum-event';
3
3
  export default abstract class Reporter {
4
4
  name: string;
5
5
  /**
@@ -4,6 +4,7 @@ exports.__esModule = true;
4
4
  exports["default"] = void 0;
5
5
  var _rumEvent = require("../types/rum-event");
6
6
  var _exception = require("../utils/exception");
7
+ // import { IReporter } from '../types/reporter';
7
8
  var Reporter = exports["default"] = /*#__PURE__*/function () {
8
9
  function Reporter() {
9
10
  this.name = 'reporter';
@@ -0,0 +1,25 @@
1
+ import { IClient, IConfiguration } from "../types/client";
2
+ import { RumEvent } from "../types/rum-event";
3
+ import { IShell } from "../types/shell";
4
+ export default abstract class Shell implements IShell {
5
+ client: IClient;
6
+ constructor(config?: IConfiguration);
7
+ /**
8
+ * 初始化
9
+ */
10
+ abstract init(configuration: IConfiguration): void;
11
+ sendEvent(payload: RumEvent): void;
12
+ /**
13
+ * get config
14
+ */
15
+ getConfig(): IConfiguration;
16
+ /**
17
+ * set config
18
+ */
19
+ abstract setConfig<T extends keyof IConfiguration>(key: T, value: IConfiguration[T]): void;
20
+ abstract setConfig(value: IConfiguration): void;
21
+ /**
22
+ * 自定义上传数据
23
+ */
24
+ sendCustom(payload: RumEvent): void;
25
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports["default"] = void 0;
6
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
+ var _rumEvent = require("../types/rum-event");
8
+ var _rumCore = require("@arms/rum-core");
9
+ var Shell = exports["default"] = /*#__PURE__*/function () {
10
+ function Shell(config) {
11
+ this.client = void 0;
12
+ this.client = new _rumCore.Client();
13
+ if (config && this.init) {
14
+ this.init(config);
15
+ }
16
+ }
17
+
18
+ /**
19
+ * 初始化
20
+ */
21
+ var _proto = Shell.prototype;
22
+ _proto.sendEvent = function sendEvent(payload) {
23
+ if (this.client) {
24
+ this.client.sendEvent(payload);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * get config
30
+ */;
31
+ _proto.getConfig = function getConfig() {
32
+ if (this.client) {
33
+ return this.client.getContext().getConfig();
34
+ }
35
+ }
36
+
37
+ /**
38
+ * set config
39
+ */;
40
+ /**
41
+ * 自定义上传数据
42
+ */
43
+ _proto.sendCustom = function sendCustom(payload) {
44
+ if (!payload.name || !payload.type) {
45
+ return;
46
+ }
47
+ var data = (0, _extends2["default"])({}, payload, {
48
+ event_type: _rumEvent.RumEventType.CUSTOM
49
+ });
50
+ this.sendEvent(data);
51
+ };
52
+ return Shell;
53
+ }();
@@ -1,17 +1,14 @@
1
1
  import { ICollector } from './collector';
2
2
  import { IProcessor } from './processor';
3
3
  import { IReporter } from './reporter';
4
- import { RumEvent, RumEventBundle } from './rum-event';
4
+ import { RumEvent, RumEventBundle, IViewData } from './rum-event';
5
+ import { ITracingOption } from '../utils/trace';
5
6
  export declare enum EventType {
6
7
  /**
7
8
  * 收集数据
8
9
  */
9
10
  collect = "collect"
10
11
  }
11
- export interface IViewData {
12
- id: string;
13
- name: string;
14
- }
15
12
  export interface IContext {
16
13
  /**
17
14
  * user config
@@ -95,5 +92,9 @@ export interface IConfiguration {
95
92
  * 各个 collector config
96
93
  */
97
94
  collectors?: any;
95
+ /**
96
+ * tracing 配置 'tracecontext' | 'b3' | 'b3multi' | 'jaeger';
97
+ */
98
+ tracing?: boolean | ITracingOption;
98
99
  [key: string]: any;
99
100
  }
@@ -1,5 +1,5 @@
1
- import { IContext, IViewData } from './client';
2
- import { RumEvent } from './rum-event';
1
+ import { IContext } from './client';
2
+ import { RumEvent, IViewData } from './rum-event';
3
3
  export interface IReporter {
4
4
  name: string;
5
5
  init(ctx: IContext): void;
@@ -6,22 +6,22 @@ export declare enum RumEventType {
6
6
  ACTION = "action",
7
7
  CUSTOM = "custom"
8
8
  }
9
- export type BaseObjectKey = string | number;
10
- export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
11
- export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[];
12
9
  export interface BaseObject {
13
- [key: BaseObjectKey]: BaseObjectValue;
10
+ [key: string]: BaseObjectValue;
11
+ }
12
+ export interface IViewData {
13
+ id: string;
14
+ name: string;
14
15
  }
16
+ export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
17
+ export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData;
15
18
  export interface RumBaseEvent {
16
- event_type: RumEventType;
19
+ event_type?: RumEventType;
17
20
  event_id?: string;
18
21
  timestamp?: number;
19
22
  times?: number;
20
- view?: {
21
- id: string;
22
- name: string;
23
- };
24
- [key: `$attr.${string}`]: BaseObjectValue;
23
+ view?: IViewData;
24
+ [key: string]: BaseObjectValue;
25
25
  }
26
26
  export interface RumViewEvent extends RumBaseEvent {
27
27
  loading_type?: 'initial_load' | 'route_change';
@@ -34,6 +34,7 @@ export interface RumViewEvent extends RumBaseEvent {
34
34
  dom_interactive?: number;
35
35
  dom_content_loaded?: number;
36
36
  dom_complete?: number;
37
+ load_event?: number;
37
38
  referrer?: string;
38
39
  url?: string;
39
40
  timing_data?: string;
@@ -56,7 +57,7 @@ export interface RumResourceEvent extends RumBaseEvent {
56
57
  first_byte_duration?: number;
57
58
  download_duration?: number;
58
59
  url: string;
59
- timing_data?: PerformanceResourceTiming;
60
+ timing_data?: string;
60
61
  }
61
62
  export interface RumExceptionEvent extends RumBaseEvent {
62
63
  source?: string;
@@ -85,13 +86,14 @@ export interface RumActionEvent extends RumBaseEvent {
85
86
  snapshots?: string;
86
87
  }
87
88
  export interface RumCustomEvent extends RumBaseEvent {
88
- id: string;
89
89
  type: string;
90
- [key: BaseObjectKey]: BaseObjectValue;
90
+ name: string;
91
+ group?: string;
92
+ value: number;
91
93
  }
92
94
  export type RumEvent = RumViewEvent | RumResourceEvent | RumExceptionEvent | RumActionEvent | RumCustomEvent;
93
95
  export declare enum AppType {
94
- broswer = "browser",
96
+ browser = "browser",
95
97
  miniapp = "miniapp"
96
98
  }
97
99
  export interface RumEventBundle {
@@ -12,7 +12,7 @@ var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
12
12
  return RumEventType;
13
13
  }({});
14
14
  var AppType = exports.AppType = /*#__PURE__*/function (AppType) {
15
- AppType["broswer"] = "browser";
15
+ AppType["browser"] = "browser";
16
16
  AppType["miniapp"] = "miniapp";
17
17
  return AppType;
18
18
  }({});
@@ -3,12 +3,14 @@
3
3
  */
4
4
  export declare function interceptFunction(options: any, name: string, callback: Function): void;
5
5
  /**
6
- * GUID v4
7
- * from https://gist.github.com/jed/982883
6
+ * @description: GUID v4
7
+ * @from https://gist.github.com/jed/982883
8
+ * @param placeholder {String}
9
+ * @return {String}
8
10
  */
9
11
  export declare function generateGUID(placeholder?: string): string;
10
12
  /**
11
- * 唯一的字符串 universe unique id
13
+ * @description: 唯一的字符串 universe unique id
12
14
  * @param len {String}
13
15
  * @return {String}
14
16
  */
package/lib/utils/base.js CHANGED
@@ -21,8 +21,10 @@ function interceptFunction(options, name, callback) {
21
21
  }
22
22
 
23
23
  /**
24
- * GUID v4
25
- * from https://gist.github.com/jed/982883
24
+ * @description: GUID v4
25
+ * @from https://gist.github.com/jed/982883
26
+ * @param placeholder {String}
27
+ * @return {String}
26
28
  */
27
29
  function generateGUID(placeholder) {
28
30
  return placeholder ?
@@ -31,7 +33,7 @@ function generateGUID(placeholder) {
31
33
  }
32
34
 
33
35
  /**
34
- * 唯一的字符串 universe unique id
36
+ * @description: 唯一的字符串 universe unique id
35
37
  * @param len {String}
36
38
  * @return {String}
37
39
  */
package/lib/utils/is.d.ts CHANGED
@@ -6,3 +6,5 @@ export declare const isString: IsFnHelper<string>;
6
6
  export declare function isToString<T = unknown>(value: unknown, type: string): value is T;
7
7
  export declare const isArray: IsFnHelper<unknown[]>;
8
8
  export declare const isRegExp: IsFnHelper<string>;
9
+ export declare const isBoolean: IsFnHelper<boolean>;
10
+ export declare const isNumber: IsFnHelper<number | bigint>;
package/lib/utils/is.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.isString = exports.isRegExp = exports.isFunction = exports.isArray = void 0;
4
+ exports.isString = exports.isRegExp = exports.isNumber = exports.isFunction = exports.isBoolean = exports.isArray = void 0;
5
5
  exports.isToString = isToString;
6
6
  exports.isTypeof = isTypeof;
7
7
  exports.isUndefined = void 0;
@@ -25,4 +25,10 @@ var isArray = exports.isArray = function isArray(value) {
25
25
  };
26
26
  var isRegExp = exports.isRegExp = function isRegExp(value) {
27
27
  return isToString(value, 'RegExp');
28
+ };
29
+ var isBoolean = exports.isBoolean = function isBoolean(value) {
30
+ return isTypeof(value, 'boolean');
31
+ };
32
+ var isNumber = exports.isNumber = function isNumber(value) {
33
+ return isTypeof(value, 'number') && !isNaN(value) || isTypeof(value, 'bigint');
28
34
  };
@@ -0,0 +1,7 @@
1
+ export type MatchOption = string | RegExp | ((value: string) => boolean);
2
+ export declare function isMatchOption(item: unknown): item is MatchOption;
3
+ /**
4
+ * 如果值有一个选项匹配,则返回true。在比较字符串时,useStartsWith: true时将把值与选项的开始进行比较,而不是要求精确匹配。
5
+ */
6
+ export declare function matchList(list: MatchOption[], value: string, useStartsWith?: boolean): boolean;
7
+ export declare function urlMatch(url: string, list?: MatchOption[]): boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.isMatchOption = isMatchOption;
5
+ exports.matchList = matchList;
6
+ exports.urlMatch = urlMatch;
7
+ var _is = require("./is");
8
+ var _polyfills = require("./polyfills");
9
+ function isMatchOption(item) {
10
+ return (0, _is.isString)(item) || (0, _is.isFunction)(item) || (0, _is.isRegExp)(item);
11
+ }
12
+
13
+ /**
14
+ * 如果值有一个选项匹配,则返回true。在比较字符串时,useStartsWith: true时将把值与选项的开始进行比较,而不是要求精确匹配。
15
+ */
16
+ function matchList(list, value, useStartsWith) {
17
+ if (useStartsWith === void 0) {
18
+ useStartsWith = false;
19
+ }
20
+ return list.some(function (item) {
21
+ try {
22
+ if (typeof item === 'function') {
23
+ return item(value);
24
+ } else if (item instanceof RegExp) {
25
+ return item.test(value);
26
+ } else if (typeof item === 'string') {
27
+ return useStartsWith ? (0, _polyfills.startsWith)(value, item) : item === value;
28
+ }
29
+ } catch (e) {}
30
+ return false;
31
+ });
32
+ }
33
+ function urlMatch(url, list) {
34
+ if (list === void 0) {
35
+ list = [];
36
+ }
37
+ try {
38
+ var rules = [/https?:\/\/.*rum|retcode\.aliyuncs\.com/, /https?:\/\/.*log-global\.aliyuncs\.com/, /https?:\/\/.*\.mmstat\.com/].concat(list);
39
+ return matchList(rules, url);
40
+ } catch (e) {
41
+ return false;
42
+ }
43
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Return true if the draw is successful
3
+ * @param threshold between 0 and 100
4
+ */
5
+ export declare function performDraw(threshold: number): boolean;
6
+ export declare function round(num: number, decimals: 0 | 1 | 2 | 3 | 4): number;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.performDraw = performDraw;
5
+ exports.round = round;
6
+ /**
7
+ * Return true if the draw is successful
8
+ * @param threshold between 0 and 100
9
+ */
10
+ function performDraw(threshold) {
11
+ return threshold !== 0 && Math.random() * 100 <= threshold;
12
+ }
13
+ function round(num, decimals) {
14
+ return +num.toFixed(decimals);
15
+ }
@@ -0,0 +1,7 @@
1
+ export declare function find<T, S extends T>(array: ArrayLike<T>, predicate: (item: T, index: number) => item is S): S | undefined;
2
+ export declare function find<T>(array: ArrayLike<T>, predicate: (item: T, index: number) => boolean): T | undefined;
3
+ export declare function startsWith(candidate: string, search: string): boolean;
4
+ export declare function endsWith(candidate: string, search: string): boolean;
5
+ export declare function assign<T, U>(target: T, source: U): T & U;
6
+ export declare function assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
7
+ export declare function assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.assign = assign;
5
+ exports.endsWith = endsWith;
6
+ exports.find = find;
7
+ exports.startsWith = startsWith;
8
+ function find(array, predicate) {
9
+ for (var i = 0; i < array.length; i += 1) {
10
+ var _item = array[i];
11
+ if (predicate(_item, i)) {
12
+ return _item;
13
+ }
14
+ }
15
+ return undefined;
16
+ }
17
+ function startsWith(candidate, search) {
18
+ return candidate.slice(0, search.length) === search;
19
+ }
20
+ function endsWith(candidate, search) {
21
+ return candidate.slice(-search.length) === search;
22
+ }
23
+ function assign(target) {
24
+ for (var _len = arguments.length, toAssign = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
25
+ toAssign[_key - 1] = arguments[_key];
26
+ }
27
+ toAssign.forEach(function (source) {
28
+ for (var _key2 in source) {
29
+ if (Object.prototype.hasOwnProperty.call(source, _key2)) {
30
+ target[_key2] = source[_key2];
31
+ }
32
+ }
33
+ });
34
+ return target;
35
+ }
@@ -0,0 +1,26 @@
1
+ import { MatchOption } from "./match";
2
+ export type PropagatorType = 'tracecontext' | 'b3' | 'b3multi' | 'jaeger';
3
+ export type TraceOption = {
4
+ match: MatchOption;
5
+ propagatorTypes: PropagatorType[];
6
+ };
7
+ export type Baggage = {
8
+ appType?: string;
9
+ pid?: string;
10
+ uid?: string;
11
+ sid?: string;
12
+ };
13
+ export declare function isTraceOption(option: any): option is TraceOption;
14
+ export interface ITracingOption {
15
+ enable?: boolean;
16
+ sample?: number | undefined;
17
+ allowedUrls?: Array<MatchOption | TraceOption> | undefined;
18
+ baggage?: boolean;
19
+ }
20
+ export declare function generateTraceId(): any;
21
+ export declare function generateSpanId(): any;
22
+ export interface ITracingHeaders {
23
+ [key: string]: string;
24
+ }
25
+ export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], baggage?: Baggage): ITracingHeaders;
26
+ export declare function parseTracingOptions(tracingOption: boolean | ITracingOption): ITracingOption;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.generateSpanId = generateSpanId;
5
+ exports.generateTraceId = generateTraceId;
6
+ exports.isTraceOption = isTraceOption;
7
+ exports.makeTracingHeaders = makeTracingHeaders;
8
+ exports.parseTracingOptions = parseTracingOptions;
9
+ var _match = require("./match");
10
+ var _is = require("./is");
11
+ var SPAN_ID_BYTES = 8;
12
+ var TRACE_ID_BYTES = 16;
13
+ var SHARED_CHAR_CODES_ARRAY = Array(32);
14
+ function isTraceOption(option) {
15
+ return option && (0, _match.isMatchOption)(option.match) && Array.isArray(option.propagatorTypes);
16
+ }
17
+ function generateId(bytes) {
18
+ for (var i = 0; i < bytes * 2; i++) {
19
+ SHARED_CHAR_CODES_ARRAY[i] = Math.floor(Math.random() * 16) + 48;
20
+ // valid hex characters in the range 48-57 and 97-102
21
+ if (SHARED_CHAR_CODES_ARRAY[i] >= 58) {
22
+ SHARED_CHAR_CODES_ARRAY[i] += 39;
23
+ }
24
+ }
25
+ return String.fromCharCode.apply(null, SHARED_CHAR_CODES_ARRAY.slice(0, bytes * 2));
26
+ }
27
+ function generateTraceId() {
28
+ var traceId = generateId(TRACE_ID_BYTES);
29
+ // 适配OpenTracing 实现(long long转成16进制最高位不能为0)
30
+ if (traceId[0] === '0') {
31
+ traceId = '1' + traceId.substring(1);
32
+ }
33
+ if (traceId[16] === '0') {
34
+ traceId = traceId.substring(0, 16) + '1' + traceId.substring(17);
35
+ }
36
+ return traceId;
37
+ }
38
+ function generateSpanId() {
39
+ return generateId(SPAN_ID_BYTES);
40
+ }
41
+ function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, baggage) {
42
+ var tracingHeaders = {};
43
+ var sample = sampled ? '1' : '0';
44
+ propagatorTypes.forEach(function (propagatorType) {
45
+ switch (propagatorType) {
46
+ case 'jaeger':
47
+ tracingHeaders['uber-trace-id'] = traceId + ":" + spanId + ":0:" + sample;
48
+ break;
49
+ case 'b3':
50
+ // https://github.com/openzipkin/b3-propagation
51
+ tracingHeaders['b3'] = traceId + "-" + spanId + "-" + sample;
52
+ break;
53
+ case 'b3multi':
54
+ tracingHeaders['X-B3-TraceId'] = traceId;
55
+ tracingHeaders['X-B3-SpanId'] = spanId;
56
+ tracingHeaders['X-B3-Sampled'] = sample;
57
+ break;
58
+ case 'tracecontext': // https://www.w3.org/TR/trace-context/
59
+ default:
60
+ tracingHeaders['traceparent'] = "00-" + traceId + "-" + spanId + "-0" + sample;
61
+ break;
62
+ }
63
+ });
64
+ if (baggage) {
65
+ var bagValList = ['rum=v2'];
66
+ Object.keys(baggage).forEach(function (key) {
67
+ bagValList.push(key + "=" + baggage[key]);
68
+ });
69
+ bagValList.length && (tracingHeaders['baggage'] = bagValList.join(','));
70
+ }
71
+ return tracingHeaders;
72
+ }
73
+ function parseTracingOptions(tracingOption) {
74
+ if ((0, _is.isBoolean)(tracingOption) || !tracingOption) {
75
+ return {
76
+ enable: !!tracingOption,
77
+ sample: 100,
78
+ allowedUrls: [],
79
+ baggage: true
80
+ };
81
+ }
82
+ var _tracingOption$enable = tracingOption.enable,
83
+ enable = _tracingOption$enable === void 0 ? true : _tracingOption$enable,
84
+ _tracingOption$sample = tracingOption.sample,
85
+ sample = _tracingOption$sample === void 0 ? 100 : _tracingOption$sample,
86
+ _tracingOption$allowe = tracingOption.allowedUrls,
87
+ allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe,
88
+ _tracingOption$baggag = tracingOption.baggage,
89
+ baggage = _tracingOption$baggag === void 0 ? true : _tracingOption$baggag;
90
+ var traceOptions = [];
91
+ if ((0, _is.isArray)(allowedUrls) && allowedUrls.length) {
92
+ allowedUrls.forEach(function (item) {
93
+ if ((0, _match.isMatchOption)(item)) {
94
+ traceOptions.push({
95
+ match: item,
96
+ propagatorTypes: ['tracecontext']
97
+ });
98
+ } else if (isTraceOption(item)) {
99
+ traceOptions.push(item);
100
+ }
101
+ });
102
+ }
103
+ return {
104
+ enable: (0, _is.isBoolean)(enable) ? enable : true,
105
+ sample: (0, _is.isNumber)(sample) ? sample : 100,
106
+ allowedUrls: traceOptions,
107
+ baggage: baggage
108
+ };
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arms/rum-core",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "arms rum javascript sdk core",
5
5
  "author": "guangli.fj <guangli.fj@alibaba-inc.com>",
6
6
  "license": "ISC",