Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(
parentTracer: BasicTracer,
spanName: string,
spanContext: types.SpanContext,
kind: types.SpanKind,
parentSpanId?: string,
links: types.Link[] = [],
startTime: types.TimeInput = hrTime()
) {
this.name = spanName;
this.spanContext = spanContext;
this.parentSpanId = parentSpanId;
this.kind = kind;
this.links = links;
this.startTime = timeInputToHrTime(startTime);
this._logger = parentTracer.logger;
this._traceParams = parentTracer.getActiveTraceParams();
this._spanProcessor = parentTracer.activeSpanProcessor;
this._spanProcessor.onStart(this);
}
this._logger.warn('Dropping extra events.');
this.events.shift();
}
if (isTimeInput(attributesOrStartTime)) {
if (typeof startTime === 'undefined') {
startTime = attributesOrStartTime as types.TimeInput;
}
attributesOrStartTime = undefined;
}
if (typeof startTime === 'undefined') {
startTime = hrTime();
}
this.events.push({
name,
attributes: attributesOrStartTime as types.Attributes,
time: timeInputToHrTime(startTime),
});
return this;
}
end(endTime: types.TimeInput = hrTime()): void {
if (this._isSpanEnded()) {
this._logger.error('You can only call end() on a span once.');
return;
}
this._ended = true;
this.endTime = timeInputToHrTime(endTime);
this._duration = hrTimeDuration(this.startTime, this.endTime);
if (this._duration[0] < 0) {
this._logger.warn(
'Inconsistent start and end time, startTime > endTime',
this.startTime,
this.endTime
);
}
this._spanProcessor.onEnd(this);
}