public void BuildRootSpanWith_Start() { var tracer = LambdaTracer.Instance; var name = "operationName"; var spanBuilder = tracer.BuildSpan(name); LambdaRootSpan span1 = (LambdaRootSpan)spanBuilder.Start(); LambdaRootSpan span2 = (LambdaRootSpan)spanBuilder.Start(); Assert.IsNull(tracer.ActiveSpan); Thread.Sleep(500); span1.Finish(); span2.Finish(); Assert.NotNull(span1, "span1 must not be null"); Assert.AreEqual(ExpectedGuidLength, span1.Guid().Length, $"span1 guid length must be {ExpectedGuidLength}"); Assert.AreEqual(name, span1.GetOperationName(), $"span1 operation name should be {name} but got {span1.GetOperationName()} instead"); Assert.IsTrue(span1.GetDurationInSeconds() > 0.0, $"span1 duration must be greater than 0 but got {span1.GetDurationInSeconds()} instead"); Assert.IsFalse(string.IsNullOrEmpty(span1.Guid()), "span1 guid must not be null or empty"); Assert.NotNull(span2, "span2 must not be null"); Assert.AreEqual(ExpectedGuidLength, span2.Guid().Length, $"span2 guid length must be {ExpectedGuidLength}"); Assert.AreEqual(name, span2.GetOperationName(), $"span2 operation name should be {name} but got {span2.GetOperationName()} instead"); Assert.IsTrue(span2.GetDurationInSeconds() > 0.0, $"span2 duration must be greater than 0 but got {span2.GetDurationInSeconds()} instead"); Assert.IsFalse(string.IsNullOrEmpty(span2.Guid()), "span2 guid must not be null or empty"); Assert.AreNotEqual(span1.Guid(), span2.Guid(), "span1 and span2 must have different guids"); }
public void BuildActiveRootSpanWith_StartActive() { var tracer = LambdaTracer.Instance; var name = "operationName"; var spanBuilder = tracer.BuildSpan(name); LambdaRootSpan span = null; LambdaRootSpan activeSpan = null; using (var scope = spanBuilder.StartActive()) { span = (LambdaRootSpan)scope.Span; activeSpan = (LambdaRootSpan)tracer.ActiveSpan; } Thread.Sleep(500); span.Finish(); Assert.NotNull(span, "span must not be null"); Assert.AreEqual(ExpectedGuidLength, span.Guid().Length, $"span guid length must be {ExpectedGuidLength}"); Assert.AreSame(activeSpan, span, "The span we created should be the active span"); Assert.AreEqual(name, span.GetOperationName(), $"span operation name should be {name} but got {span.GetOperationName()} instead"); Assert.IsTrue(span.GetDurationInSeconds() > 0.0, $"span duration must be greater than 0 but got {span.GetDurationInSeconds()} instead"); Assert.IsFalse(string.IsNullOrEmpty(span.Guid()), "span guid must not be null or empty"); }