public bool TryExtract <TCarrier, TCarrierGetter>(TCarrier carrier, TCarrierGetter carrierGetter, out SpanContext?spanContext) where TCarrierGetter : struct, ICarrierGetter <TCarrier> { spanContext = null; if (carrier is not IReadOnlyDictionary <string, string?> ) { return(false); } var traceIdAsUint64 = ParseUtility.ParseUInt64(carrier, carrierGetter, SpanContext.Keys.TraceId); if (traceIdAsUint64 == null) { // a valid traceId is required to use distributed tracing return(false); } var traceId = TraceId.CreateFromUlong(traceIdAsUint64.Value); if (traceId == TraceId.Zero) { // a valid traceId is required to use distributed tracing return(false); } var parentId = ParseUtility.ParseUInt64(carrier, carrierGetter, SpanContext.Keys.ParentId) ?? 0; var samplingPriority = ParseUtility.ParseInt32(carrier, carrierGetter, SpanContext.Keys.SamplingPriority); var origin = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.Origin); var rawTraceId = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.RawTraceId); var rawSpanId = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.RawSpanId); spanContext = new SpanContext(traceId, parentId, samplingPriority, serviceName: null, origin, rawTraceId, rawSpanId); return(true); }
public bool TryExtract <TCarrier, TCarrierGetter>(TCarrier carrier, TCarrierGetter carrierGetter, out SpanContext?spanContext) where TCarrierGetter : struct, ICarrierGetter <TCarrier> { spanContext = null; var rawTraceId = ParseUtility.ParseString(carrier, carrierGetter, TraceId)?.Trim(); var rawSpanId = ParseUtility.ParseString(carrier, carrierGetter, SpanId)?.Trim(); var samplingPriority = ParseUtility.ParseInt32(carrier, carrierGetter, Sampled); if (IsValidTraceId(rawTraceId) && IsValidSpanId(rawSpanId)) { #if NETCOREAPP var traceId = rawTraceId.Length == 32 ? ParseUtility.ParseFromHexOrDefault(rawTraceId.AsSpan(16)) : ParseUtility.ParseFromHexOrDefault(rawTraceId); #else var traceId = rawTraceId.Length == 32 ? ParseUtility.ParseFromHexOrDefault(rawTraceId.Substring(16)) : ParseUtility.ParseFromHexOrDefault(rawTraceId); #endif if (traceId == 0) { return(false); } var parentId = ParseUtility.ParseFromHexOrDefault(rawSpanId); spanContext = new SpanContext(traceId, parentId, samplingPriority, serviceName: null, null, rawTraceId, rawSpanId); return(true); } return(false); }
public bool TryExtract <TCarrier, TCarrierGetter>(TCarrier carrier, TCarrierGetter carrierGetter, out SpanContext?spanContext) where TCarrierGetter : struct, ICarrierGetter <TCarrier> { spanContext = null; var rawTraceId = ParseUtility.ParseString(carrier, carrierGetter, TraceId)?.Trim(); var rawSpanId = ParseUtility.ParseString(carrier, carrierGetter, SpanId)?.Trim(); var samplingPriority = ParseUtility.ParseInt32(carrier, carrierGetter, Sampled); if (IsValidTraceId(rawTraceId, out var traceId) && IsValidSpanId(rawSpanId)) { var parentId = ParseUtility.ParseFromHexOrDefault(rawSpanId); spanContext = new SpanContext(traceId, parentId, samplingPriority, serviceName: null, null, rawTraceId, rawSpanId); return(true); } return(false); }