private void SerializeAndVerify(TraceContextInfo traceContextInfo) { var json = serializer.Serialize(new [] { traceContextInfo }); var spanDto = DeserializeSingleItem(json); AssertSpanDto(spanDto, traceContextInfo); }
public bool TryAdd(TraceContextInfo info) { lock (syncObject) { infos.Add(info); return(true); } }
public void Should_produce_same_results_when_being_reused() { var traceContextInfo = new TraceContextInfo(true, "traceId", "contextId", "contextName", "parentContextId"); var json1 = serializer.Serialize(new [] { traceContextInfo }); var json2 = serializer.Serialize(new [] { traceContextInfo }); Assert.That(json1, Is.EqualTo(json2)); }
private void Match(TraceContextInfo realInfo, TraceContextDescriptor expectedInfo) { Assert.That(Match(realInfo.TraceId, expectedInfo.TraceId), Is.True, "Элементы {0} и {1} не совпали по полю TraceId", InfoToString(realInfo), DescriptorToString(expectedInfo)); Assert.That(Match(realInfo.ContextId, expectedInfo.ContextId), Is.True, "Элементы {0} и {1} не совпали по полю ContextId", InfoToString(realInfo), DescriptorToString(expectedInfo)); Assert.That(Match(realInfo.ParentContextId, expectedInfo.ParentContextId), Is.True, "Элементы {0} и {1} не совпали по полю ParentContextId", InfoToString(realInfo), DescriptorToString(expectedInfo)); Assert.That(Match(realInfo.ContextName, expectedInfo.ContextName), Is.True, "Элементы {0} и {1} не совпали по полю ContextName", InfoToString(realInfo), DescriptorToString(expectedInfo)); Assert.That(Match(realInfo.IsRoot, expectedInfo.IsRoot), Is.True, "Элементы {0} и {1} не совпали по полю IsRoot", InfoToString(realInfo), DescriptorToString(expectedInfo)); Assert.That(Match(realInfo.Annotations, expectedInfo.Annotations), Is.True, "Элементы {0} и {1} не совпали по полю Annotations", InfoToString(realInfo), DescriptorToString(expectedInfo)); Assert.That(Match(realInfo.Timeline, expectedInfo.Timeline), Is.True, "Элементы {0} и {1} не совпали по полю Timeline", InfoToString(realInfo), DescriptorToString(expectedInfo)); }
public void Should_not_use_contextName_if_annotations_contains_targetId() { var traceContextInfo = new TraceContextInfo(true, "traceId", "contextId", "contextName", "parentContextId"); traceContextInfo.Annotations.Add("targetId", "otherContextName"); var json = serializer.Serialize(new [] { traceContextInfo }); var actual = DeserializeSingleItem(json); Assert.That(actual.Annotations["targetId"], Is.EqualTo("otherContextName")); }
public void Should_correctly_serialize_a_span_with_annotations_and_timeline() { var traceContextInfo = new TraceContextInfo(true, "traceId", "contextId", "contextName", "parentContextId"); traceContextInfo.Annotations.Add("k1", "v1"); traceContextInfo.Annotations.Add("k2", "v2"); traceContextInfo.Timeline.Add("k1", DateTime.UtcNow); traceContextInfo.Timeline.Add("k2", DateTime.UtcNow.AddSeconds(1)); SerializeAndVerify(traceContextInfo); }
public void Should_correctly_serialize_multiple_spans() { var traceContextInfo1 = new TraceContextInfo(true, "traceId1", "contextId1", "contextName1", "parentContextId"); var traceContextInfo2 = new TraceContextInfo(false, "traceId2", "contextId2", "contextName2", "parentContextId2"); var json = serializer.Serialize(new[] { traceContextInfo1, traceContextInfo2 }); var actual = Deserialize(json); Assert.That(actual.Count, Is.EqualTo(2)); AssertSpanDto(actual[0], traceContextInfo1); AssertSpanDto(actual[1], traceContextInfo2); }
private static void AssertSpanDto(SpanDto actual, TraceContextInfo expected) { Assert.That(actual.TraceId, Is.EqualTo(expected.TraceId)); Assert.That(actual.SpanId, Is.EqualTo(expected.ContextId)); Assert.That(actual.ParentSpanId, Is.EqualTo(expected.ParentContextId)); Assert.That(actual.Timeline, Is.EquivalentTo(expected.Timeline)); Assert.That(actual.Annotations.Where(x => x.Key != "root" && x.Key != "targetId").ToList(), Is.EquivalentTo(expected.Annotations)); string isRootStr; var actualIsRoot = actual.Annotations.TryGetValue("root", out isRootStr) && bool.Parse(isRootStr); Assert.That(actualIsRoot, Is.EqualTo(expected.IsRoot)); string actualContextName; if (actual.Annotations.TryGetValue("targetId", out actualContextName)) { Assert.That(actualContextName, Is.EqualTo(expected.ContextName)); } else { Assert.That(expected.ContextName == null); } }
public void SetUp() { traceContextInfo = new TraceContextInfo(true, "traceId", "contextId", "contextName", "parentContextId"); }
private string InfoToString(TraceContextInfo info) { return(string.Format("[TraceId={0}, ContextId={1}, ParentContextId={2}, ContextName={3}, IsRoot={4}, Annotations={5}, Timeline={6}]", info.TraceId, info.ContextId, info.ParentContextId, info.ContextName, info.IsRoot, DictionaryToString(info.Annotations), DictionaryToString(info.Timeline))); }