Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startSpan(name: string, options: types.SpanOptions = {}): types.Span {
const parentContext = this._getParentSpanContext(options.parent);
// make sampling decision
const samplingDecision = this._sampler.shouldSample(parentContext);
const spanId = randomSpanId();
let traceId;
let traceState;
if (!parentContext || !isValid(parentContext)) {
// New root span.
traceId = randomTraceId();
} else {
// New child span.
traceId = parentContext.traceId;
traceState = parentContext.traceState;
}
const traceFlags = samplingDecision
? TraceFlags.SAMPLED
: TraceFlags.UNSAMPLED;
const spanContext = { traceId, spanId, traceFlags, traceState };
const recordEvents = options.isRecording || false;
if (!recordEvents && !samplingDecision) {