Exemplo n.º 1
0
        private ISpan StartSpanInternal(
            ISpanContext parent,
            bool hasRemoteParent,
            string name,
            ISampler sampler,
            IEnumerable <ISpan> parentLinks,
            bool recordEvents,
            ITimestampConverter 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,
                this.Options.Clock);

            LinkSpans(span, parentLinks);
            return(span);
        }
Exemplo n.º 2
0
 private SpanContext(ITraceId traceId, ISpanId spanId, TraceOptions traceOptions)
 {
     TraceId      = traceId;
     SpanId       = spanId;
     TraceOptions = traceOptions;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Trace options builder pre-initialized from the given trace options instance.
 /// </summary>
 /// <param name="traceOptions">Trace options to pre-initialize the builder.</param>
 /// <returns>Trace options builder.</returns>
 public static TraceOptionsBuilder Builder(TraceOptions traceOptions)
 {
     return(new TraceOptionsBuilder(traceOptions.options));
 }
Exemplo n.º 4
0
 public static ISpanContext Create(ITraceId traceId, ISpanId spanId, TraceOptions traceOptions)
 {
     return(new SpanContext(traceId, spanId, traceOptions));
 }