Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* This class represents a span.
*/
export class Span implements types.Span, ReadableSpan {
// Below properties are included to implement ReadableSpan for export
// purposes but are not intended to be written-to directly.
readonly spanContext: types.SpanContext;
readonly kind: types.SpanKind;
readonly parentSpanId?: string;
readonly attributes: types.Attributes = {};
readonly links: types.Link[] = [];
readonly events: types.TimedEvent[] = [];
readonly startTime: types.HrTime;
name: string;
status: types.Status = {
code: types.CanonicalCode.OK,
};
endTime: types.HrTime = [0, 0];
private _ended = false;
private _duration: types.HrTime = [-1, -1];
private readonly _logger: types.Logger;
private readonly _spanProcessor: SpanProcessor;
private readonly _traceParams: TraceParams;
/** Constructs a new Span instance. */
constructor(
parentTracer: BasicTracer,
spanName: string,
spanContext: types.SpanContext,
kind: types.SpanKind,
parentSpanId?: string,
links: types.Link[] = [],
setTag(key: string, value: unknown): this {
if (
key === opentracing.Tags.ERROR &&
(value === true || value === 'true')
) {
this._span.setStatus({ code: types.CanonicalCode.UNKNOWN });
return this;
}
this._span.setAttribute(key, value);
return this;
}
export function _toZipkinTags(
attributes: types.Attributes,
status: types.Status,
statusCodeTagName: string,
statusDescriptionTagName: string
): zipkinTypes.Tags {
const tags: { [key: string]: string } = {};
for (const key of Object.keys(attributes)) {
tags[key] = String(attributes[key]);
}
tags[statusCodeTagName] = String(types.CanonicalCode[status.code]);
if (status.message) {
tags[statusDescriptionTagName] = status.message;
}
return tags;
}