@arms/rum-core
Advanced tools
Comparing version 0.0.20 to 0.0.22
/** | ||
* 劫持函数 | ||
*/ | ||
export declare function interceptFunction(options: any, name: string, callback: Function): void; | ||
export declare function interceptFunction(target: any, name: string, callback: Function): void; | ||
/** | ||
@@ -6,0 +6,0 @@ * @description: GUID v4 |
@@ -10,11 +10,11 @@ "use strict"; | ||
*/ | ||
function interceptFunction(options, name, callback) { | ||
var registeredMethod = options[name]; | ||
options[name] = function () { | ||
function interceptFunction(target, name, callback) { | ||
var registeredMethod = target[name]; | ||
target[name] = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
callback.apply(this, args); | ||
callback.apply(target, args); | ||
if (registeredMethod) { | ||
return registeredMethod.apply(this, args); | ||
return registeredMethod.apply(target, args); | ||
} | ||
@@ -21,0 +21,0 @@ }; |
@@ -11,2 +11,3 @@ import { MatchOption } from "./match"; | ||
sample?: number | undefined; | ||
propagatorTypes?: PropagatorType[]; | ||
allowedUrls?: Array<MatchOption | TraceOption> | undefined; | ||
@@ -21,4 +22,11 @@ tracestate?: boolean; | ||
} | ||
export declare function generateTraceIdForSW8(pid: string): void; | ||
export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], tracestate?: string, baggage?: string): ITracingHeaders; | ||
export interface TraceSubOption { | ||
tracestate?: string; | ||
baggage?: string; | ||
appId?: string; | ||
appVersion?: string; | ||
viewName?: string; | ||
host?: string; | ||
} | ||
export declare function makeTracingHeaders(traceId: string, spanId: string, sampled: boolean, propagatorTypes: PropagatorType[], subOption?: TraceSubOption): ITracingHeaders; | ||
export declare function parseTracingOptions(tracingOption: boolean | ITracingOption): ITracingOption; |
@@ -6,3 +6,2 @@ "use strict"; | ||
exports.generateTraceId = generateTraceId; | ||
exports.generateTraceIdForSW8 = generateTraceIdForSW8; | ||
exports.isTraceOption = isTraceOption; | ||
@@ -14,10 +13,8 @@ exports.makeTracingHeaders = makeTracingHeaders; | ||
var _base = require("./base"); | ||
var _jsBase = require("js-base64"); | ||
function isTraceOption(option) { | ||
return option && (0, _match.isMatchOption)(option.match) && (0, _is.isArray)(option.propagatorTypes); | ||
} | ||
function generateId() { | ||
return (0, _base.generateGUID)().replace(/-/g, ''); | ||
} | ||
function generateTraceId() { | ||
var traceId = generateId(); | ||
var traceId = (0, _base.generateGUID)().replace(/-/g, ''); | ||
// 适配OpenTracing 实现(long long转成16进制最高位不能为0) | ||
@@ -33,3 +30,3 @@ if (traceId[0] === '0') { | ||
function generateSpanId() { | ||
var list = new Array(16); | ||
var list = Array(16); | ||
for (var i = 0; i < 16; i++) { | ||
@@ -42,9 +39,14 @@ list[i] = Math.floor(Math.random() * 16) + 48; | ||
} | ||
return String.fromCharCode.apply(null, list.slice(0, 16)); | ||
return String.fromCharCode.apply(null, list); | ||
} | ||
//skywalking TraceId https://github.com/apache/skywalking-client-js | ||
function generateTraceIdForSW8(pid) {} | ||
function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, tracestate, baggage) { | ||
function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, subOption) { | ||
if (subOption === void 0) { | ||
subOption = {}; | ||
} | ||
var tracingHeaders = {}; | ||
var sample = sampled ? '1' : '0'; | ||
// skywalking 标准具备排他性,如果包含sw8,则只使用sw8 | ||
if (propagatorTypes.includes('sw8')) { | ||
propagatorTypes = ['sw8']; | ||
} | ||
propagatorTypes.forEach(function (propagatorType) { | ||
@@ -65,9 +67,17 @@ switch (propagatorType) { | ||
case 'sw8': | ||
// tracingHeaders['sw8'] = `${sample}-${traceIdStr}-${segmentId}-${0}-${pid}-${app.version}-${href}-${host}`;; | ||
// https://github.com/apache/skywalking-client-js | ||
var traceIdStr = String((0, _jsBase.encode)(traceId)); | ||
var segmentId = String((0, _jsBase.encode)(spanId)); | ||
var service = String((0, _jsBase.encode)(subOption.appId)); | ||
var instance = String((0, _jsBase.encode)(subOption.appVersion)); | ||
var endpoint = String((0, _jsBase.encode)(subOption.viewName)); | ||
var peer = String((0, _jsBase.encode)(subOption.host)); | ||
tracingHeaders['sw8'] = sample + "-" + traceIdStr + "-" + segmentId + "-" + 0 + "-" + service + "-" + instance + "-" + endpoint + "-" + peer; | ||
break; | ||
case 'tracecontext': // https://www.w3.org/TR/trace-context/ | ||
case 'tracecontext': | ||
default: | ||
// https://www.w3.org/TR/trace-context/ | ||
tracingHeaders['traceparent'] = "00-" + traceId + "-" + spanId + "-0" + sample; | ||
if (tracestate) { | ||
tracingHeaders['tracestate'] = tracestate; | ||
if (subOption.tracestate) { | ||
tracingHeaders['tracestate'] = subOption.tracestate; | ||
} | ||
@@ -77,4 +87,4 @@ break; | ||
}); | ||
if (baggage) { | ||
tracingHeaders['baggage'] = baggage; | ||
if (subOption.baggage) { | ||
tracingHeaders['baggage'] = subOption.baggage; | ||
} | ||
@@ -84,2 +94,3 @@ return tracingHeaders; | ||
function parseTracingOptions(tracingOption) { | ||
var defPropagatorTypes = ['tracecontext']; | ||
if ((0, _is.isBoolean)(tracingOption) || !tracingOption) { | ||
@@ -89,2 +100,3 @@ return { | ||
sample: 100, | ||
propagatorTypes: defPropagatorTypes, | ||
allowedUrls: [], | ||
@@ -99,2 +111,4 @@ tracestate: true, | ||
sample = _tracingOption$sample === void 0 ? 100 : _tracingOption$sample, | ||
_tracingOption$propag = tracingOption.propagatorTypes, | ||
propagatorTypes = _tracingOption$propag === void 0 ? defPropagatorTypes : _tracingOption$propag, | ||
_tracingOption$allowe = tracingOption.allowedUrls, | ||
@@ -112,3 +126,3 @@ allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe, | ||
match: item, | ||
propagatorTypes: ['tracecontext'] | ||
propagatorTypes: propagatorTypes | ||
}); | ||
@@ -123,2 +137,3 @@ } else if (isTraceOption(item)) { | ||
sample: (0, _is.isNumber)(sample) ? sample : 100, | ||
propagatorTypes: propagatorTypes, | ||
allowedUrls: traceOptions, | ||
@@ -125,0 +140,0 @@ tracestate: tracestate, |
{ | ||
"name": "@arms/rum-core", | ||
"version": "0.0.20", | ||
"version": "0.0.22", | ||
"description": "arms rum javascript sdk core", | ||
@@ -25,3 +25,4 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", | ||
"dependencies": { | ||
"events": "^3.3.0" | ||
"events": "^3.3.0", | ||
"js-base64": "^3.7.7" | ||
}, | ||
@@ -28,0 +29,0 @@ "devDependencies": { |
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
40891
1204
2
+ Addedjs-base64@^3.7.7
+ Addedjs-base64@3.7.7(transitive)