private ISpan StartSpanInternal( ISpanContext parent, bool hasRemoteParent, string name, ISampler sampler, IEnumerable <ISpan> parentLinks, bool recordEvents, Timer timestampConverter) { ITraceParams activeTraceParams = this.Options.TraceConfig.ActiveTraceParams; IRandomGenerator random = this.Options.RandomHandler; ITraceId traceId; ISpanId spanId = SpanId.GenerateRandomId(random); ISpanId parentSpanId = null; TraceOptionsBuilder traceOptionsBuilder; if (parent == null || !parent.IsValid) { // New root span. traceId = TraceId.GenerateRandomId(random); traceOptionsBuilder = TraceOptions.Builder(); // This is a root span so no remote or local parent. // hasRemoteParent = null; hasRemoteParent = false; } else { // New child span. traceId = parent.TraceId; parentSpanId = parent.SpanId; traceOptionsBuilder = TraceOptions.Builder(parent.TraceOptions); } traceOptionsBuilder.SetIsSampled( MakeSamplingDecision( parent, hasRemoteParent, name, sampler, parentLinks, traceId, spanId, activeTraceParams)); TraceOptions traceOptions = traceOptionsBuilder.Build(); SpanOptions spanOptions = SpanOptions.None; if (traceOptions.IsSampled || recordEvents) { spanOptions = SpanOptions.RecordEvents; } ISpan span = Span.StartSpan( SpanContext.Create(traceId, spanId, traceOptions, parent?.Tracestate ?? Tracestate.Empty), spanOptions, name, parentSpanId, hasRemoteParent, activeTraceParams, this.Options.StartEndHandler, timestampConverter); LinkSpans(span, parentLinks); span.Kind = this.Kind; return(span); }