@arms/rum-core
Advanced tools
Comparing version 0.0.25-beta.13 to 0.0.25-beta.14
@@ -1,2 +0,2 @@ | ||
import { IClient, IConfiguration, IContext } from '../types/client'; | ||
import { IClient, IConfiguration, IContext, IRumSession } from '../types/client'; | ||
import { RumEvent } from '../types/rum-event'; | ||
@@ -12,3 +12,3 @@ import { IProcessor } from '../types/processor'; | ||
private ctx; | ||
init(config: IConfiguration): void; | ||
init(config: IConfiguration, rumSession?: IRumSession): void; | ||
sendEvent: (payload: RumEvent) => void; | ||
@@ -15,0 +15,0 @@ setContext(ctx: IContext): void; |
@@ -9,2 +9,3 @@ "use strict"; | ||
var _context = _interopRequireDefault(require("./context")); | ||
var _is = require("../utils/is"); | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
@@ -26,5 +27,5 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
var _proto = Client.prototype; | ||
_proto.init = function init(config) { | ||
_proto.init = function init(config, rumSession) { | ||
var _this2 = this; | ||
this.ctx = new _context["default"](config); | ||
this.ctx = new _context["default"](config, rumSession); | ||
var ctx = this.ctx, | ||
@@ -34,2 +35,5 @@ collectors = this.collectors, | ||
reporter = this.reporter; | ||
processors.forEach(function (processor) { | ||
(0, _is.isFunction)(processor.setup) && processor.setup(ctx); | ||
}); | ||
@@ -36,0 +40,0 @@ // collector 收集数据统一 push 到各匹配 processor |
@@ -1,2 +0,2 @@ | ||
import { IConfiguration, IContext } from "../types/client"; | ||
import { IConfiguration, IContext, IRumSession } from "../types/client"; | ||
import { RumEvent, IViewData } from "../types/rum-event"; | ||
@@ -7,3 +7,4 @@ declare class Context implements IContext { | ||
private views; | ||
constructor(config: IConfiguration); | ||
session: IRumSession; | ||
constructor(config: IConfiguration, rumSession?: IRumSession); | ||
getConfig(): IConfiguration; | ||
@@ -10,0 +11,0 @@ setConfig(config: IConfiguration): void; |
@@ -6,6 +6,11 @@ "use strict"; | ||
var Context = /*#__PURE__*/function () { | ||
function Context(config) { | ||
function Context(config, rumSession) { | ||
this.config = config; | ||
this.rumEvent = void 0; | ||
this.views = []; | ||
this.session = void 0; | ||
if (rumSession) { | ||
this.session = rumSession; | ||
this.session.init(config); | ||
} | ||
} | ||
@@ -12,0 +17,0 @@ var _proto = Context.prototype; |
@@ -120,3 +120,5 @@ "use strict"; | ||
}); | ||
this.request(ctx, eventQueue, curView); | ||
var session = ctx.session; | ||
var sampled = session ? session.getSampled() : true; | ||
sampled && this.request(ctx, eventQueue, curView); | ||
this.eventQueue = []; | ||
@@ -123,0 +125,0 @@ } |
@@ -13,2 +13,3 @@ import { ICollector } from './collector'; | ||
export interface IContext { | ||
session: IRumSession; | ||
/** | ||
@@ -32,2 +33,17 @@ * user config | ||
} | ||
export interface SessionConfig { | ||
sampleRate?: number; | ||
maxDuration?: number; | ||
overtime?: number; | ||
} | ||
export interface IRumSession { | ||
init(config: IConfiguration): void; | ||
sessionConfig: SessionConfig; | ||
getSessionId: () => string; | ||
getSampled: () => boolean; | ||
updateSession: () => void; | ||
getEventId: () => string; | ||
getViewId: () => string; | ||
getUserId: () => string; | ||
} | ||
export interface IClient { | ||
@@ -37,3 +53,3 @@ /** | ||
*/ | ||
init: (configuration: IConfiguration) => void; | ||
init: (configuration: IConfiguration, rumSession?: IRumSession) => void; | ||
/** | ||
@@ -102,2 +118,6 @@ * 业务自定义上传数据 | ||
/** | ||
* session config | ||
*/ | ||
sessionConfig?: SessionConfig; | ||
/** | ||
* 各个 collector config | ||
@@ -104,0 +124,0 @@ */ |
@@ -5,4 +5,5 @@ import { IContext } from './client'; | ||
name: string; | ||
setup?(ctx: IContext): void; | ||
process(ctx: IContext): RumEvent; | ||
match?(ctx: IContext): boolean; | ||
} |
@@ -25,7 +25,5 @@ /** | ||
* @param sessionId {string} sessionId | ||
* @param sampled {boolean} 是否命中采样 | ||
* @param samplingType {string} 采样类型 | ||
* @return {String} | ||
*/ | ||
export declare function generateEventId(sessionId: string, sampled?: boolean, samplingType?: string): string; | ||
export declare function generateEventId(sessionId: string): string; | ||
/** | ||
@@ -32,0 +30,0 @@ * @desc 函数防抖 |
@@ -98,15 +98,7 @@ "use strict"; | ||
* @param sessionId {string} sessionId | ||
* @param sampled {boolean} 是否命中采样 | ||
* @param samplingType {string} 采样类型 | ||
* @return {String} | ||
*/ | ||
function generateEventId(sessionId, sampled, samplingType) { | ||
if (sampled === void 0) { | ||
sampled = true; | ||
} | ||
if (samplingType === void 0) { | ||
samplingType = '0'; | ||
} | ||
function generateEventId(sessionId) { | ||
var spanId = generateSpanId(); | ||
return "00-" + sessionId + "-" + spanId + "-" + samplingType + (sampled ? '1' : '0'); | ||
return "00-" + sessionId + "-" + spanId; | ||
} | ||
@@ -113,0 +105,0 @@ |
@@ -0,1 +1,5 @@ | ||
export declare const ONE_SECOND = 1000; | ||
export declare const ONE_MINUTE: number; | ||
export declare const ONE_HOUR: number; | ||
export declare const ONE_DAY: number; | ||
/** | ||
@@ -6,3 +10,2 @@ * Return true if the draw is successful | ||
export declare function performDraw(threshold: number): boolean; | ||
export declare function round(num: number, decimals: 0 | 1 | 2 | 3 | 4): number; | ||
/** | ||
@@ -9,0 +12,0 @@ * 保留指定位数的小数 |
"use strict"; | ||
exports.__esModule = true; | ||
exports.ONE_SECOND = exports.ONE_MINUTE = exports.ONE_HOUR = exports.ONE_DAY = void 0; | ||
exports.formatNumber = formatNumber; | ||
exports.performDraw = performDraw; | ||
exports.round = round; | ||
var ONE_SECOND = exports.ONE_SECOND = 1e3; | ||
var ONE_MINUTE = exports.ONE_MINUTE = 60 * ONE_SECOND; | ||
var ONE_HOUR = exports.ONE_HOUR = 60 * ONE_MINUTE; | ||
var ONE_DAY = exports.ONE_DAY = 24 * ONE_HOUR; | ||
/** | ||
@@ -14,5 +19,2 @@ * Return true if the draw is successful | ||
} | ||
function round(num, decimals) { | ||
return +num.toFixed(decimals); | ||
} | ||
@@ -19,0 +21,0 @@ /** |
{ | ||
"name": "@arms/rum-core", | ||
"version": "0.0.25-beta.13", | ||
"version": "0.0.25-beta.14", | ||
"description": "arms rum javascript sdk core", | ||
@@ -5,0 +5,0 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", |
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
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
46942
1427