private TraceInfo ReadTraceInfo(HttpContext context) { string headerTraceId = context.Request.Headers[TraceInfo.TraceIdHeaderName]; string headerSpanId = context.Request.Headers[TraceInfo.SpanIdHeaderName]; string headerParentSpanId = context.Request.Headers[TraceInfo.ParentSpanIdHeaderName]; string headerSampled = context.Request.Headers[TraceInfo.SampledHeaderName]; var requestPath = context.Request.Path.ToString(); var traceId = headerTraceId.IsParsableTo128Or64Bit() ? headerTraceId : TraceIdHelper.GenerateNewTraceId(_zipkinConfig.Create128BitTraceId); var spanId = headerSpanId.IsParsableToLong() ? headerSpanId : TraceIdHelper.GenerateHexEncodedInt64Id(); var parentSpanId = headerParentSpanId.IsParsableToLong() ? headerParentSpanId : string.Empty; var isSampled = _zipkinConfig.ShouldBeSampled(headerSampled, requestPath); var domain = _zipkinConfig.Domain(context.Request); var isJoinedSpan = spanId.Equals(headerSpanId); var traceInfo = new TraceInfo(traceId, spanId, isSampled, isJoinedSpan, domain, context.Connection.LocalIpAddress, parentSpanId); context.Items[TraceInfo.TraceInfoKey] = traceInfo; _traceInfoAccessor.TraceInfo = traceInfo; return(traceInfo); }