/// <summary> /// Extracts a <see cref="SpanContext"/> from the values found in the specified headers. /// </summary> /// <param name="carrier">The headers that contain the values to be extracted.</param> /// <param name="getter">The function that can extract a list of values for a given header name.</param> /// <typeparam name="T">Type of header collection</typeparam> /// <returns>A new <see cref="SpanContext"/> that contains the values obtained from <paramref name="carrier"/>.</returns> public SpanContext Extract <T>(T carrier, Func <T, string, IEnumerable <string> > getter) { if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } if (getter == null) { throw new ArgumentNullException(nameof(getter)); } var traceId = PropagationHelpers.ParseTraceId(carrier, getter, DDHttpHeaderNames.TraceId, _traceIdConvention, Log); if (traceId == TraceId.Zero) { // a valid traceId is required to use distributed tracing return(null); } var parentId = ParseUInt64(carrier, getter, DDHttpHeaderNames.ParentId); var samplingPriority = ParseSamplingPriority(carrier, getter, DDHttpHeaderNames.SamplingPriority); var origin = PropagationHelpers.ParseString(carrier, getter, DDHttpHeaderNames.Origin); return(new SpanContext(traceId, parentId, samplingPriority, null, origin)); }
/// <inheritdoc cref="IPropagator"/> public virtual SpanContext Extract <T>(T carrier, Func <T, string, IEnumerable <string> > getter) { if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } if (getter == null) { throw new ArgumentNullException(nameof(getter)); } var traceId = PropagationHelpers.ParseTraceId(carrier, getter, B3HttpHeaderNames.B3TraceId, _traceIdConvention, Log); if (traceId == TraceId.Zero) { // a valid traceId is required to use distributed tracing return(null); } var spanId = ParseHexUInt64(carrier, getter, B3HttpHeaderNames.B3SpanId); var samplingPriority = ParseB3Sampling(carrier, getter); return(new SpanContext(traceId, spanId, samplingPriority)); }