@arms/rum-core 0.0.5 → 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';
@@ -13,4 +14,4 @@ export * from './utils/is';
13
14
  export * from './utils/number';
14
15
  export * from './utils/match';
15
16
  export * from './utils/trace';
16
- export { Client, Context, Reporter };
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) {
@@ -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,7 +1,7 @@
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
5
  import { ITracingOption } from '../utils/trace';
6
6
  export declare enum EventType {
7
7
  /**
@@ -9,10 +9,6 @@ export declare enum EventType {
9
9
  */
10
10
  collect = "collect"
11
11
  }
12
- export interface IViewData {
13
- id: string;
14
- name: string;
15
- }
16
12
  export interface IContext {
17
13
  /**
18
14
  * user config
@@ -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
  }({});
@@ -4,17 +4,23 @@ export type TraceOption = {
4
4
  match: MatchOption;
5
5
  propagatorTypes: PropagatorType[];
6
6
  };
7
+ export type Baggage = {
8
+ appType?: string;
9
+ pid?: string;
10
+ uid?: string;
11
+ sid?: string;
12
+ };
7
13
  export declare function isTraceOption(option: any): option is TraceOption;
8
14
  export interface ITracingOption {
9
15
  enable?: boolean;
10
16
  sample?: number | undefined;
11
17
  allowedUrls?: Array<MatchOption | TraceOption> | undefined;
12
- tracestate?: boolean;
18
+ baggage?: boolean;
13
19
  }
14
20
  export declare function generateTraceId(): any;
15
21
  export declare function generateSpanId(): any;
16
22
  export interface ITracingHeaders {
17
23
  [key: string]: string;
18
24
  }
19
- export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], tracestate?: string): ITracingHeaders;
25
+ export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], baggage?: Baggage): ITracingHeaders;
20
26
  export declare function parseTracingOptions(tracingOption: boolean | ITracingOption): ITracingOption;
@@ -38,20 +38,7 @@ function generateTraceId() {
38
38
  function generateSpanId() {
39
39
  return generateId(SPAN_ID_BYTES);
40
40
  }
41
-
42
- // export function getB3Header(traceId: string, spanId: string) {
43
- // return `${traceId}-${spanId}-1`
44
- // }
45
- //
46
- // export function getW3CTraceHeader(traceId: string, spanId: string) {
47
- // return `00-${traceId}-${spanId}-01`
48
- // }
49
- //
50
- // export function getJaegerTraceHeader(traceId: string, spanId: string) {
51
- // return `${traceId}:${spanId}:0:1`
52
- // }
53
-
54
- function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, tracestate) {
41
+ function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, baggage) {
55
42
  var tracingHeaders = {};
56
43
  var sample = sampled ? '1' : '0';
57
44
  propagatorTypes.forEach(function (propagatorType) {
@@ -71,12 +58,16 @@ function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, tracestat
71
58
  case 'tracecontext': // https://www.w3.org/TR/trace-context/
72
59
  default:
73
60
  tracingHeaders['traceparent'] = "00-" + traceId + "-" + spanId + "-0" + sample;
74
- if (tracestate) {
75
- tracingHeaders['tracestate'] = tracestate;
76
- }
77
61
  break;
78
62
  }
79
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
+ }
80
71
  return tracingHeaders;
81
72
  }
82
73
  function parseTracingOptions(tracingOption) {
@@ -85,7 +76,7 @@ function parseTracingOptions(tracingOption) {
85
76
  enable: !!tracingOption,
86
77
  sample: 100,
87
78
  allowedUrls: [],
88
- tracestate: true
79
+ baggage: true
89
80
  };
90
81
  }
91
82
  var _tracingOption$enable = tracingOption.enable,
@@ -94,8 +85,8 @@ function parseTracingOptions(tracingOption) {
94
85
  sample = _tracingOption$sample === void 0 ? 100 : _tracingOption$sample,
95
86
  _tracingOption$allowe = tracingOption.allowedUrls,
96
87
  allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe,
97
- _tracingOption$traces = tracingOption.tracestate,
98
- tracestate = _tracingOption$traces === void 0 ? true : _tracingOption$traces;
88
+ _tracingOption$baggag = tracingOption.baggage,
89
+ baggage = _tracingOption$baggag === void 0 ? true : _tracingOption$baggag;
99
90
  var traceOptions = [];
100
91
  if ((0, _is.isArray)(allowedUrls) && allowedUrls.length) {
101
92
  allowedUrls.forEach(function (item) {
@@ -113,6 +104,6 @@ function parseTracingOptions(tracingOption) {
113
104
  enable: (0, _is.isBoolean)(enable) ? enable : true,
114
105
  sample: (0, _is.isNumber)(sample) ? sample : 100,
115
106
  allowedUrls: traceOptions,
116
- tracestate: tracestate
107
+ baggage: baggage
117
108
  };
118
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arms/rum-core",
3
- "version": "0.0.5",
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",