UNPKG

skywalking-backend-js-netease

Version:

The NodeJS agent for Apache SkyWalking

85 lines 3.56 kB
"use strict"; /*! * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextCarrier = void 0; const tslib_1 = require("tslib"); const ID_1 = tslib_1.__importDefault(require("../../trace/ID")); const CarrierItem_1 = require("./CarrierItem"); class ContextCarrier extends CarrierItem_1.CarrierItem { constructor(traceId, segmentId, spanId, service, serviceInstance, endpoint, clientAddress, items = []) { super('sw8'); this.traceId = traceId; this.segmentId = segmentId; this.spanId = spanId; this.service = service; this.serviceInstance = serviceInstance; this.endpoint = endpoint; this.clientAddress = clientAddress; this.items = items; this.encode = (s) => { return Buffer.from(s).toString('base64'); }; this.decode = (s) => { return Buffer.from(s, 'base64').toString(); }; this.items.push(this); } get value() { var _a, _b, _c; return [ '1', this.encode(((_a = this.traceId) === null || _a === void 0 ? void 0 : _a.toString()) || ''), this.encode(((_b = this.segmentId) === null || _b === void 0 ? void 0 : _b.toString()) || ''), (_c = this.spanId) === null || _c === void 0 ? void 0 : _c.toString(), this.encode(this.service || ''), this.encode(this.serviceInstance || ''), this.encode(this.endpoint || ''), this.encode(this.clientAddress || ''), ].join('-'); } set value(val) { const parts = val.split('-'); this.traceId = new ID_1.default(this.decode(parts[1])); this.segmentId = new ID_1.default(this.decode(parts[2])); this.spanId = Number.parseInt(parts[3], 10); this.service = this.decode(parts[4]); this.serviceInstance = this.decode(parts[5]); this.endpoint = this.decode(parts[6]); this.clientAddress = this.decode(parts[7]); } isValid() { var _a, _b; return Boolean(((_a = this.traceId) === null || _a === void 0 ? void 0 : _a.rawId) && ((_b = this.segmentId) === null || _b === void 0 ? void 0 : _b.rawId) && this.spanId !== undefined && !isNaN(this.spanId) && this.service && this.endpoint && this.clientAddress !== undefined); } static from(map) { if (!map.hasOwnProperty('sw8')) return; const carrier = new ContextCarrier(); carrier.items.filter((item) => map.hasOwnProperty(item.key)).forEach((item) => (item.value = map[item.key])); return carrier; } } exports.ContextCarrier = ContextCarrier; //# sourceMappingURL=ContextCarrier.js.map