skywalking-apache
Version:
The NodeJS agent for Apache SkyWalking
114 lines • 4.12 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 });
var tslib_1 = require("tslib");
var Component_1 = require("../Component");
var Tracing_pb_1 = require("../../proto/language-agent/Tracing_pb");
var logging_1 = require("../../logging");
var packageInfo = tslib_1.__importStar(require("../../../package.json"));
var logger = logging_1.createLogger(__filename);
var Span = /** @class */ (function () {
function Span(options) {
this.id = -1;
this.parentId = -1;
this.peer = '';
this.layer = Tracing_pb_1.SpanLayer.UNKNOWN;
this.component = Component_1.Component.UNKNOWN;
this.tags = [];
this.logs = [];
this.refs = [];
this.startTime = 0;
this.endTime = 0;
this.errored = false;
this.context = options.context;
this.operation = options.operation;
this.type = options.type;
if (options.id !== undefined)
this.id = options.id;
if (options.parentId !== undefined)
this.parentId = options.parentId;
if (options.peer)
this.peer = options.peer;
if (options.layer)
this.layer = options.layer;
if (options.component)
this.component = options.component;
}
Span.prototype.start = function () {
logger.debug("Starting span " + this.operation, this);
this.startTime = new Date().getTime();
this.context.start(this);
return this;
};
Span.prototype.stop = function () {
logger.debug("Stopping span " + this.operation, this);
this.context.stop(this);
return this;
};
Span.prototype.finish = function (segment) {
logger.debug('Finishing span', this);
this.endTime = new Date().getTime();
segment.archive(this);
return true;
};
// noinspection JSUnusedLocalSymbols
Span.prototype.extract = function () {
throw new Error("\n can only inject context carrier into ExitSpan, this may be a potential bug in the agent,\n please report this in " + packageInfo.bugs.url + " if you encounter this.\n ");
};
Span.prototype.inject = function (carrier) {
this.context.segment.relate(carrier.traceId);
return this;
};
Span.prototype.tag = function (tag) {
if (!tag.overridable) {
this.tags.push(Object.assign({}, tag));
}
var sameTags = this.tags.filter(function (it) { return it.key === tag.key; });
if (sameTags.length) {
sameTags.forEach(function (it) { return (it.val = tag.val); });
}
else {
this.tags.push(Object.assign({}, tag));
}
return this;
};
Span.prototype.error = function (error) {
this.errored = true;
this.logs.push({
timestamp: new Date().getTime(),
items: [
{
key: 'Stack',
val: error.stack,
},
],
});
return this;
};
Span.prototype.refer = function (ref) {
if (!this.refs.includes(ref)) {
this.refs.push(ref);
}
return this;
};
return Span;
}());
exports.default = Span;
//# sourceMappingURL=Span.js.map