/// <inheritdoc/> public ISpan StartSpan() { SpanContext parentContext = FindParent(this.parentType, this.parent, this.parentSpanContext); var activeTraceParams = this.options.TraceConfig.ActiveTraceParams; var random = this.options.RandomHandler; TraceId traceId; var spanId = SpanId.GenerateRandomId(random); SpanId parentSpanId = null; TraceOptionsBuilder traceOptionsBuilder; if (parentContext == null || !parentContext.IsValid) { // New root span. traceId = TraceId.GenerateRandomId(random); traceOptionsBuilder = TraceOptions.Builder(); } else { // New child span. traceId = parentContext.TraceId; parentSpanId = parentContext.SpanId; traceOptionsBuilder = TraceOptions.Builder(parentContext.TraceOptions); } traceOptionsBuilder.SetIsSampled( MakeSamplingDecision( parentContext, this.name, this.sampler, this.links, traceId, spanId, activeTraceParams)); var traceOptions = traceOptionsBuilder.Build(); var spanOptions = SpanOptions.None; if (traceOptions.IsSampled || this.recordEvents) { spanOptions = SpanOptions.RecordEvents; } var span = Span.StartSpan( SpanContext.Create(traceId, spanId, traceOptions, parentContext?.Tracestate ?? Tracestate.Empty), spanOptions, this.name, this.kind, parentSpanId, activeTraceParams, this.options.StartEndHandler, this.timestampConverter); LinkSpans(span, this.links); return(span); }
/// <inheritdoc/> public override bool Equals(object obj) { if (obj == this) { return(true); } if (!(obj is TraceId)) { return(false); } TraceId that = (TraceId)obj; return(Arrays.Equals(this.bytes, that.bytes)); }
public int CompareTo(ITraceId other) { TraceId that = other as TraceId; for (int i = 0; i < Size; i++) { if (this.bytes[i] != that.bytes[i]) { sbyte b1 = (sbyte)this.bytes[i]; sbyte b2 = (sbyte)that.bytes[i]; return(b1 < b2 ? -1 : 1); } } return(0); }
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); }