Пример #1
0
        public void CallToEndDoesNotChangeAlreadySetDuration(bool isSampled)
        {
            var payloadSender      = new MockPayloadSender();
            var expectedSpansCount = isSampled ? 1 : 0;

            using (var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender,
                                                                    config: new MockConfigSnapshot(transactionSampleRate: isSampled ? "1" : "0"))))
            {
                var transaction = agent.Tracer.StartTransaction(TestTransaction, UnitTest);
                var span        = transaction.StartSpan(TestSpan1, ApiConstants.TypeExternal);

                payloadSender.Spans.Should().HaveCount(0);
                span.Duration = 123456.789;
                span.End();

                payloadSender.SignalEndSpans();
                payloadSender.WaitForSpans();
                payloadSender.Spans.Should().HaveCount(expectedSpansCount);
                if (isSampled)
                {
                    payloadSender.FirstSpan.Duration.Should().Be(123456.789);
                }

                payloadSender.Transactions.Should().HaveCount(0);
                transaction.Duration = 987654.321;
                transaction.End();
                payloadSender.SignalEndTransactions();
                payloadSender.WaitForTransactions();
                payloadSender.Transactions.Should().HaveCount(1);
                payloadSender.FirstTransaction.Duration.Should().Be(987654.321);
            }
        }
Пример #2
0
        public void AgentDisabledBasicTransactionWithSpans()
        {
            var payloadSender = new MockPayloadSender();
            var configReader  = new MockConfiguration(enabled: "false");

            using var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender, configuration: configReader));
            var transaction = agent.Tracer.StartTransaction("TestTransaction", "Test");

            transaction.Should().NotBeOfType <Transaction>();
            transaction.Should().BeOfType <NoopTransaction>();

            var span1 = transaction.StartSpan("test", "test");

            span1.Should().NotBeOfType <Span>();
            span1.Should().BeOfType <NoopSpan>();
            agent.Tracer.CurrentSpan.Should().Be(span1);
            span1.End();

            agent.Tracer.CurrentSpan.Should().BeNull();

            var span2 = span1.StartSpan("test2", "test");

            span2.Should().NotBeOfType <Span>();
            span2.Should().BeOfType <NoopSpan>();
            span2.End();

            transaction.End();

            payloadSender.SignalEndTransactions();
            payloadSender.WaitForAny();
            payloadSender.Transactions.Should().BeNullOrEmpty();
            payloadSender.Spans.Should().BeNullOrEmpty();
        }
Пример #3
0
        public void StartNoEndTransaction()
        {
            const string transactionName = TestTransaction;
            const string transactionType = UnitTest;
            var          payloadSender   = new MockPayloadSender();

            using (var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender)))
            {
                var unused = agent.Tracer.StartTransaction(transactionName, transactionType);
            }

            payloadSender.SignalEndTransactions();
            payloadSender.WaitForTransactions();
            payloadSender.Transactions.Should().BeEmpty();
        }
Пример #4
0
        public void AgentDisabledBasicTransaction()
        {
            var payloadSender = new MockPayloadSender();
            var configReader  = new MockConfigSnapshot(enabled: "false");

            using var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender, config: configReader));
            agent.Tracer.CurrentTransaction.Should().BeNull();
            var transaction = agent.Tracer.StartTransaction("TestTransaction", "Test");

            transaction.Should().NotBeOfType <Transaction>();
            transaction.Should().BeOfType <NoopTransaction>();

            agent.Tracer.CurrentTransaction.Should().Be(transaction);

            transaction.End();

            payloadSender.SignalEndTransactions();
            agent.Tracer.CurrentTransaction.Should().BeNull();
            payloadSender.WaitForTransactions();
            payloadSender.Transactions.Should().BeNullOrEmpty();
        }
Пример #5
0
        public void AgentDisabledTransactionWithLambdaAndSpans()
        {
            var payloadSender = new MockPayloadSender();
            var configReader  = new MockConfiguration(enabled: "false");

            using var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender, configuration: configReader));

            var block1Ran = false;
            var block2Ran = false;
            var block3Ran = false;

            agent.Tracer.CaptureTransaction("TestTransaction", "Test", transaction =>
            {
                block1Ran = true;
                transaction.Should().NotBeOfType <Transaction>();
                transaction.Should().BeOfType <NoopTransaction>();

                transaction.CaptureSpan("test", "test", span1 =>
                {
                    block2Ran = true;
                    span1.Should().NotBeOfType <Span>();
                    span1.Should().BeOfType <NoopSpan>();
                    span1.CaptureSpan("test2", "test", span2 =>
                    {
                        block3Ran = true;
                        span2.Should().NotBeOfType <Span>();
                        span2.Should().BeOfType <NoopSpan>();
                    });
                });
            });

            block1Ran.Should().BeTrue();
            block2Ran.Should().BeTrue();
            block3Ran.Should().BeTrue();

            payloadSender.SignalEndTransactions();
            payloadSender.WaitForAny();
            payloadSender.Transactions.Should().BeNullOrEmpty();
            payloadSender.Spans.Should().BeNullOrEmpty();
        }
Пример #6
0
        public void CallingEndMoreThanOnceIsNoop(bool isSampled)
        {
            var payloadSender      = new MockPayloadSender();
            var expectedSpansCount = isSampled ? 1 : 0;

            using (var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender,
                                                                    config: new MockConfigSnapshot(transactionSampleRate: isSampled ? "1" : "0"))))
            {
                var transaction = agent.Tracer.StartTransaction(TestTransaction, UnitTest);
                var span        = transaction.StartSpan(TestSpan1, ApiConstants.TypeExternal);

                payloadSender.Spans.Should().HaveCount(0);
                span.End();

                payloadSender.SignalEndSpans();
                payloadSender.WaitForSpans();
                payloadSender.Spans.Should().HaveCount(expectedSpansCount);
                if (isSampled)
                {
                    payloadSender.FirstSpan.Name.Should().Be(TestSpan1);
                }
                span.End();

                payloadSender.SignalEndSpans();
                payloadSender.WaitForSpans();
                payloadSender.Spans.Should().HaveCount(expectedSpansCount);

                payloadSender.Transactions.Should().HaveCount(0);
                transaction.End();
                payloadSender.WaitForTransactions();
                payloadSender.Transactions.Should().HaveCount(1);
                payloadSender.FirstTransaction.Name.Should().Be(TestTransaction);
                transaction.End();
                payloadSender.SignalEndTransactions();
                payloadSender.WaitForTransactions();
                payloadSender.Transactions.Should().HaveCount(1);
            }
        }
Пример #7
0
        public void AgentDisabledTransactionWithLambda()
        {
            var payloadSender = new MockPayloadSender();
            var configReader  = new MockConfiguration(enabled: "false");

            using var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender, configuration: configReader));
            var codeExecuted = false;

            agent.Tracer.CaptureTransaction("TestTransaction", "Test", transaction =>
            {
                codeExecuted = true;
                transaction.Should().NotBeOfType <Transaction>();
                transaction.Should().BeOfType <NoopTransaction>();

                // ReSharper disable AccessToDisposedClosure
                agent.Tracer.CurrentTransaction.Should().NotBeNull();
                agent.Tracer.CurrentTransaction.Should().Be(transaction);
            });

            codeExecuted.Should().BeTrue();
            payloadSender.SignalEndTransactions();
            payloadSender.WaitForTransactions();
            payloadSender.Transactions.Should().BeNullOrEmpty();
        }