示例#1
0
 public void SimpleActionWithParameter()
 => AssertWith1TransactionAnd1Span(t =>
 {
     t.CaptureSpan(SpanName, SpanType,
                   s =>
     {
         s.Should().NotBeNull();
         WaitHelpers.Sleep2XMinimum();
     });
 });
示例#2
0
        public void SimpleActionWithReturnType_OnSubSpan()
        => AssertWith1TransactionAnd1SpanOnSubSpan(s =>
        {
            var res = s.CaptureSpan(SpanName, SpanType, () =>
            {
                WaitHelpers.Sleep2XMinimum();
                return(42);
            });

            res.Should().Be(42);
        });
示例#3
0
        public void SimpleActionWithReturnType()
        => AssertWith1TransactionAnd1Span(t =>
        {
            var res = t.CaptureSpan(SpanName, SpanType, () =>
            {
                WaitHelpers.Sleep2XMinimum();
                return(42);
            });

            Assert.Equal(42, res);
        });
示例#4
0
        public void SimpleActionWithReturnTypeAndParameter_OnSubSpan()
        => AssertWith1TransactionAnd1SpanOnSubSpan(t =>
        {
            var res = t.CaptureSpan(SpanName, SpanType, s =>
            {
                t.Should().NotBeNull();
                WaitHelpers.Sleep2XMinimum();
                return(42);
            });

            res.Should().Be(42);
        });
示例#5
0
 public void SimpleActionWithException()
 => AssertWith1TransactionAnd1SpanAnd1Error(t =>
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         t.CaptureSpan(SpanName, SpanType, new Action(() =>
         {
             WaitHelpers.Sleep2XMinimum();
             throw new InvalidOperationException(ExceptionMessage);
         }));
     });
 });
示例#6
0
 public void SimpleActionWithException_OnSubSpan()
 => AssertWith1TransactionAnd1SpanAnd1ErrorOnSubSpan(s =>
 {
     Action act = () =>
     {
         s.CaptureSpan(SpanName, SpanType, new Action(() =>
         {
             WaitHelpers.Sleep2XMinimum();
             throw new InvalidOperationException(ExceptionMessage);
         }));
     };
     act.Should().Throw <InvalidOperationException>();
 });
示例#7
0
 public void SimpleActionWithExceptionAndParameter()
 => AssertWith1TransactionAnd1SpanAnd1Error(t =>
 {
     Action act = () =>
     {
         t.CaptureSpan(SpanName, SpanType, new Action <ISpan>(s =>
         {
             s.Should().NotBeNull();
             WaitHelpers.Sleep2XMinimum();
             throw new InvalidOperationException(ExceptionMessage);
         }));
     };
     act.Should().Throw <InvalidOperationException>().WithMessage(ExceptionMessage);
 });
示例#8
0
        public void LabelsOnSpan()
        {
            var payloadSender = AssertWith1TransactionAnd1Span(
                t =>
            {
                t.CaptureSpan(SpanName, SpanType, span =>
                {
                    WaitHelpers.Sleep2XMinimum();
                    span.SetLabel("foo", "bar");
                });
            });

            //According to the Intake API labels are stored on the Context (and not on Spans.Labels directly).
            payloadSender.SpansOnFirstTransaction[0].Context.InternalLabels.Value.InnerDictionary["foo"].Value.Should().Be("bar");
        }
示例#9
0
        public void SimpleActionWithReturnTypeAndException_OnSubSpan()
        => AssertWith1TransactionAnd1SpanAnd1ErrorOnSubSpan(s =>
        {
            var alwaysThrow = new Random().Next(1) == 0;
            Func <int> act  = () => s.CaptureSpan(SpanName, SpanType, () =>
            {
                WaitHelpers.Sleep2XMinimum();

                if (alwaysThrow)                         //avoid unreachable code warning.
                {
                    throw new InvalidOperationException(ExceptionMessage);
                }

                return(42);
            });
            act.Should().Throw <InvalidOperationException>().WithMessage(ExceptionMessage);
        });
示例#10
0
        public void TagsOnSpan()
        {
            var payloadSender = AssertWith1TransactionAnd1Span(
                t =>
            {
                t.CaptureSpan(SpanName, SpanType, span =>
                {
                    WaitHelpers.Sleep2XMinimum();
                    span.Tags["foo"] = "bar";
                });
            });

            //According to the Intake API tags are stored on the Context (and not on Spans.Tags directly).
            payloadSender.SpansOnFirstTransaction[0].Context.Tags.Should().Contain("foo", "bar");

            //Also make sure the tag is visible directly on Span.Tags.
            payloadSender.SpansOnFirstTransaction[0].Tags.Should().Contain("foo", "bar");
        }
示例#11
0
        public void SimpleActionWithReturnTypeAndExceptionAndParameter_OnSubSpan()
        => AssertWith1TransactionAnd1SpanAnd1ErrorOnSubSpan(s1 =>
        {
            Action act = () =>
            {
                s1.CaptureSpan(SpanName, SpanType, s2 =>
                {
                    s2.Should().NotBeNull();
                    WaitHelpers.Sleep2XMinimum();

                    if (new Random().Next(1) == 0)                             //avoid unreachable code warning.
                    {
                        throw new InvalidOperationException(ExceptionMessage);
                    }

                    return(42);
                });
                throw new Exception("CaptureSpan should not eat exception and continue");
            };
            act.Should().Throw <InvalidOperationException>().WithMessage(ExceptionMessage);
        });
示例#12
0
        public void SimpleActionWithReturnTypeAndException()
        => AssertWith1TransactionAnd1SpanAnd1Error(t =>
        {
            Assert.Throws <InvalidOperationException>(() =>
            {
                var result = t.CaptureSpan(SpanName, SpanType, () =>
                {
                    WaitHelpers.Sleep2XMinimum();

                    if (new Random().Next(1) == 0)                             //avoid unreachable code warning.
                    {
                        throw new InvalidOperationException(ExceptionMessage);
                    }

                    return(42);
                });

                Assert.True(false);                         //Should not be executed because the agent isn't allowed to catch an exception.
                Assert.Equal(42, result);                   //But if it'd not throw it'd be 42.
            });
        });
示例#13
0
 public void SimpleAction()
 => AssertWith1TransactionAnd1Span(t => { t.CaptureSpan(SpanName, SpanType, () => { WaitHelpers.Sleep2XMinimum(); }); });