Beispiel #1
0
        /// <summary>
        /// Asserts on 1 transaction with 1 span
        /// </summary>
        private MockPayloadSender AssertWith1TransactionAnd1Span(Action <ITransaction> action)
        {
            var payloadSender = new MockPayloadSender();
            var agent         = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender));

            agent.Tracer.CaptureTransaction(TransactionName, TransactionType, t =>
            {
                WaitHelpers.SleepMinimum();
                action(t);
            });

            Assert.NotEmpty(payloadSender.Payloads);
            Assert.NotEmpty(payloadSender.Payloads[0].Transactions);

            Assert.Equal(TransactionName, payloadSender.Payloads[0].Transactions[0].Name);
            Assert.Equal(TransactionType, payloadSender.Payloads[0].Transactions[0].Type);

            Assert.NotEmpty(payloadSender.SpansOnFirstTransaction);

            Assert.Equal(SpanName, payloadSender.SpansOnFirstTransaction[0].Name);
            Assert.Equal(SpanType, payloadSender.SpansOnFirstTransaction[0].Type);

            var duration = payloadSender.Payloads[0].Transactions[0].Duration;

            WaitHelpers.Assert3XMinimumSleepLength(duration);

            return(payloadSender);
        }
Beispiel #2
0
        /// <summary>
        /// Asserts on 1 transaction with 1 span and 1 error
        /// </summary>
        private void AssertWith1TransactionAnd1SpanAnd1Error(Action <ITransaction> action)
        {
            var payloadSender = new MockPayloadSender();
            var agent         = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender));

            agent.Tracer.CaptureTransaction(TransactionName, TransactionType, t =>
            {
                WaitHelpers.SleepMinimum();
                action(t);
            });

            Assert.NotEmpty(payloadSender.Payloads);
            Assert.NotEmpty(payloadSender.Payloads[0].Transactions);

            Assert.Equal(TransactionName, payloadSender.Payloads[0].Transactions[0].Name);
            Assert.Equal(TransactionType, payloadSender.Payloads[0].Transactions[0].Type);

            var duration = payloadSender.Payloads[0].Transactions[0].Duration;

            WaitHelpers.Assert3XMinimumSleepLength(duration);

            Assert.NotEmpty(payloadSender.SpansOnFirstTransaction);

            Assert.Equal(SpanName, payloadSender.SpansOnFirstTransaction[0].Name);
            Assert.Equal(SpanType, payloadSender.SpansOnFirstTransaction[0].Type);

            Assert.NotEmpty(payloadSender.Errors);
            Assert.NotEmpty(payloadSender.Errors[0].Errors);

            Assert.Equal(typeof(InvalidOperationException).FullName, payloadSender.Errors[0].Errors[0].Exception.Type);
            Assert.Equal(ExceptionMessage, payloadSender.Errors[0].Errors[0].Exception.Message);
        }
Beispiel #3
0
        /// <summary>
        /// Asserts on 1 transaction with 1 async Span
        /// </summary>
        private async Task <MockPayloadSender> AssertWith1TransactionAnd1SpanAsync(Func <ITransaction, Task> func)
        {
            var payloadSender = new MockPayloadSender();
            var agent         = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender));

            await agent.Tracer.CaptureTransaction(TransactionName, TransactionType, async t =>
            {
                await WaitHelpers.DelayMinimum();
                await func(t);
            });

            Assert.NotEmpty(payloadSender.Payloads);
            Assert.NotEmpty(payloadSender.Payloads[0].Transactions);

            Assert.Equal(TransactionName, payloadSender.Payloads[0].Transactions[0].Name);
            Assert.Equal(TransactionType, payloadSender.Payloads[0].Transactions[0].Type);

            var duration = payloadSender.Payloads[0].Transactions[0].Duration;

            WaitHelpers.Assert3XMinimumSleepLength(duration);

            Assert.NotEmpty(payloadSender.SpansOnFirstTransaction);

            Assert.Equal(SpanName, payloadSender.SpansOnFirstTransaction[0].Name);
            Assert.Equal(SpanType, payloadSender.SpansOnFirstTransaction[0].Type);

            return(payloadSender);
        }