@arms/rum-core 0.0.25-beta.16 → 0.0.25-beta.18

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/es/utils/trace.js DELETED
@@ -1,101 +0,0 @@
1
- import { isMatchOption } from "./match";
2
- import { isArray, isBoolean, isNumber } from "./is";
3
- import { encode } from "js-base64";
4
- export function isTraceOption(option) {
5
- return option && isMatchOption(option.match) && isArray(option.propagatorTypes);
6
- }
7
- export function makeTracingHeaders(traceId, spanId, sampled, propagatorTypes, subOption) {
8
- if (subOption === void 0) {
9
- subOption = {};
10
- }
11
- var tracingHeaders = {};
12
- var sample = sampled ? '1' : '0';
13
- // skywalking 标准具备排他性,如果包含sw8,则只使用sw8
14
- if (propagatorTypes.includes('sw8')) {
15
- propagatorTypes = ['sw8'];
16
- }
17
- propagatorTypes.forEach(function (propagatorType) {
18
- switch (propagatorType) {
19
- case 'jaeger':
20
- tracingHeaders['uber-trace-id'] = traceId + ":" + spanId + ":0:" + sample;
21
- break;
22
- case 'b3':
23
- // https://github.com/openzipkin/b3-propagation
24
- tracingHeaders['b3'] = traceId + "-" + spanId + "-" + sample;
25
- break;
26
- case 'b3multi':
27
- tracingHeaders['X-B3-TraceId'] = traceId;
28
- tracingHeaders['X-B3-SpanId'] = spanId;
29
- tracingHeaders['X-B3-Sampled'] = sample;
30
- break;
31
- case 'sw8':
32
- // https://github.com/apache/skywalking-client-js
33
- var traceIdStr = String(encode(traceId));
34
- var segmentId = String(encode(spanId));
35
- var service = String(encode(subOption.appId));
36
- var instance = String(encode(subOption.appVersion));
37
- var endpoint = String(encode(subOption.viewName));
38
- var peer = String(encode(subOption.host));
39
- tracingHeaders['sw8'] = sample + "-" + traceIdStr + "-" + segmentId + "-" + 0 + "-" + service + "-" + instance + "-" + endpoint + "-" + peer;
40
- break;
41
- case 'tracecontext':
42
- default:
43
- // https://www.w3.org/TR/trace-context/
44
- tracingHeaders['traceparent'] = "00-" + traceId + "-" + spanId + "-0" + sample;
45
- if (subOption.tracestate) {
46
- tracingHeaders['tracestate'] = subOption.tracestate;
47
- }
48
- break;
49
- }
50
- });
51
- if (subOption.baggage) {
52
- tracingHeaders['baggage'] = subOption.baggage;
53
- }
54
- return tracingHeaders;
55
- }
56
- export function parseTracingOptions(tracingOption) {
57
- var defPropagatorTypes = ['tracecontext'];
58
- if (isBoolean(tracingOption) || !tracingOption) {
59
- return {
60
- enable: !!tracingOption,
61
- sample: 100,
62
- propagatorTypes: defPropagatorTypes,
63
- allowedUrls: [],
64
- tracestate: true,
65
- baggage: false
66
- };
67
- }
68
- var _tracingOption$enable = tracingOption.enable,
69
- enable = _tracingOption$enable === void 0 ? true : _tracingOption$enable,
70
- _tracingOption$sample = tracingOption.sample,
71
- sample = _tracingOption$sample === void 0 ? 100 : _tracingOption$sample,
72
- _tracingOption$propag = tracingOption.propagatorTypes,
73
- propagatorTypes = _tracingOption$propag === void 0 ? defPropagatorTypes : _tracingOption$propag,
74
- _tracingOption$allowe = tracingOption.allowedUrls,
75
- allowedUrls = _tracingOption$allowe === void 0 ? [] : _tracingOption$allowe,
76
- _tracingOption$traces = tracingOption.tracestate,
77
- tracestate = _tracingOption$traces === void 0 ? true : _tracingOption$traces,
78
- _tracingOption$baggag = tracingOption.baggage,
79
- baggage = _tracingOption$baggag === void 0 ? false : _tracingOption$baggag;
80
- var traceOptions = [];
81
- if (isArray(allowedUrls) && allowedUrls.length) {
82
- allowedUrls.forEach(function (item) {
83
- if (isMatchOption(item)) {
84
- traceOptions.push({
85
- match: item,
86
- propagatorTypes: propagatorTypes
87
- });
88
- } else if (isTraceOption(item)) {
89
- traceOptions.push(item);
90
- }
91
- });
92
- }
93
- return {
94
- enable: isBoolean(enable) ? enable : true,
95
- sample: isNumber(sample) ? sample : 100,
96
- propagatorTypes: propagatorTypes,
97
- allowedUrls: traceOptions,
98
- tracestate: tracestate,
99
- baggage: baggage
100
- };
101
- }