public void SpanContext_Parses_Correctly_Formatted_String(string value, int traceId, int spanId, int parentId, byte flags) { var parsed = SpanContext.TryParse(value, out var context); Assert.True(parsed); Assert.Equal(traceId, context.TraceId); Assert.Equal(spanId, context.SpanId); Assert.Equal(parentId, context.ParentId); Assert.Equal(flags, context.Flags); }
/// <summary> /// Extract context from the underlying text map carrier /// </summary> /// <param name="carrier"></param> /// <returns></returns> public SpanContext Extract(ITextMap carrier) { SpanContext context = null; Dictionary <string, string> baggage = null; string debugId = null; bool contextParsed = false; foreach (var item in carrier.GetEntries()) { if (item.Key.Equals(contextKey)) { contextParsed = SpanContext.TryParse(Decode(item.Value), out context); } else if (item.Key.Equals(Constants.DEBUG_ID_HEADER_KEY)) { debugId = Decode(item.Value); } else if (item.Key.StartsWith(baggagePrefix)) { if (baggage == null) { baggage = new Dictionary <string, string>(); } baggage.Add(item.Key.MinusPrefix(baggagePrefix), Decode(item.Value)); } } if (!contextParsed) { if (!string.IsNullOrWhiteSpace(debugId)) { return(SpanContext.Debug(debugId)); } return(null); } if (baggage == null) { return(context); } return(context.SetBaggage(baggage)); }
[InlineData("98:98:97:689")] //flag must be byte public void SpanContext_Parse_For_Malformed_String(string value) { Assert.False(SpanContext.TryParse(value, out var _)); }