skywalking-apache
Version:
The NodeJS agent for Apache SkyWalking
89 lines • 3.73 kB
JavaScript
"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;
var tslib_1 = require("tslib");
var ID_1 = tslib_1.__importDefault(require("../../trace/ID"));
var CarrierItem_1 = require("./CarrierItem");
var ContextCarrier = /** @class */ (function (_super) {
tslib_1.__extends(ContextCarrier, _super);
function ContextCarrier(traceId, segmentId, spanId, service, serviceInstance, endpoint, clientAddress, items) {
if (items === void 0) { items = []; }
var _this = _super.call(this, 'sw8') || this;
_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 = function (s) {
return Buffer.from(s).toString('base64');
};
_this.decode = function (s) {
return Buffer.from(s, 'base64').toString();
};
_this.items.push(_this);
return _this;
}
Object.defineProperty(ContextCarrier.prototype, "value", {
get: function () {
return [
'1',
this.encode(this.traceId.toString()),
this.encode(this.segmentId.toString()),
this.spanId.toString(),
this.encode(this.service),
this.encode(this.serviceInstance),
this.encode(this.endpoint),
this.encode(this.clientAddress),
].join('-');
},
set: function (val) {
var 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]);
},
enumerable: false,
configurable: true
});
ContextCarrier.prototype.isValid = function () {
return (this.traceId !== undefined &&
this.segmentId !== undefined &&
this.spanId !== undefined &&
this.service !== undefined &&
this.endpoint !== undefined &&
this.clientAddress !== undefined);
};
ContextCarrier.from = function (map) {
var carrier = new ContextCarrier();
carrier.items.filter(function (item) { return map.hasOwnProperty(item.key); }).forEach(function (item) { return (item.value = map[item.key]); });
return carrier;
};
return ContextCarrier;
}(CarrierItem_1.CarrierItem));
exports.ContextCarrier = ContextCarrier;
//# sourceMappingURL=ContextCarrier.js.map