Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        internal static LambdaSpan CreateRootSpan(string operationName, DateTimeOffset timestamp, IDictionary <string, object> tags, string guid, ILogger logger = null)
        {
            if (logger == null)
            {
                logger = new MockLogger();
            }
            var rootSpan = new LambdaRootSpan(operationName, timestamp, tags, guid, new DataCollector(logger, false), new TransactionState(), new PrioritySamplingState(), new DistributedTracingState());
            LambdaSpanContext context = new LambdaSpanContext(rootSpan);

            rootSpan.SetContext(context);
            return(rootSpan);
        }
Exemplo n.º 3
0
        public void BuildChildSpanWith_Start()
        {
            var            tracer          = LambdaTracer.Instance;
            var            rootName        = "rootOperationName";
            var            rootSpanBuilder = tracer.BuildSpan(rootName);
            LambdaRootSpan rootSpan        = (LambdaRootSpan)rootSpanBuilder.Start();

            var        childName        = "childOperationName";
            var        childSpanBuilder = tracer.BuildSpan(childName).AsChildOf(rootSpan);
            LambdaSpan childSpan        = (LambdaSpan)childSpanBuilder.Start();

            Assert.AreEqual(rootSpan.Guid(), childSpan.RootSpan.Guid(), "The guid of the child span's RootSpan should match the guid of the root span");
        }
Exemplo n.º 4
0
        public TransactionEvent(LambdaRootSpan rootSpan)
        {
            _duration  = rootSpan.GetDurationInSeconds();
            _timeStamp = rootSpan.TimeStamp.ToUnixTimeMilliseconds();

            _transactionName = rootSpan.TransactionState.TransactionName;
            _guid            = rootSpan.TransactionState.TransactionId;

            if (rootSpan.TransactionState.HasError())
            {
                _hasError = true;
            }

            _distributedTraceIntrinsics = rootSpan.Intrinsics;
            _userAttributes             = rootSpan.Tags.BuildUserAttributes();

            _agentAttributes = rootSpan.Tags.BuildAgentAttributes();
        }
Exemplo n.º 5
0
        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");
        }