Exemplo n.º 1
0
        public async Task SNSWrapper_PublishRequest_WrapRequestWithObject_GeneratesException()
        {
            const string TestTopicName         = "testTopicName";
            const string ExpectedOperationName = "MessageBroker/SNS/Topic/Produce/Named/" + TestTopicName;
            const string TopicArn = "arn:aws:sns:us-west-2:1234567890:" + TestTopicName;
            const string ExpectedExceptionMessage = "whoopsie";
            var          publishRequest           = new PublishRequest(TopicArn, ExpectedExceptionMessage);

            try
            {
                var result = await SNSWrapper.WrapRequest(SendSNSMessageWithException, publishRequest);
            }
            catch (Exception)
            {
                var span = _tracer.FinishedSpans()[0];
                Assert.That(span.Tags["span.kind"], Is.EqualTo("client"));
                Assert.That(span.Tags["component"], Is.EqualTo("SNS"));
                Assert.That(span.Tags["aws.operation"], Is.EqualTo("Produce"));
                Assert.That(span.Tags["error"], Is.EqualTo(true));

                Assert.That(span.LogEntries.Count, Is.EqualTo(1));
                Assert.That((string)span.LogEntries[0].Fields["event"], Is.EqualTo("error"));
                Assert.That(span.LogEntries[0].Fields["error.object"], Is.TypeOf(typeof(AmazonSimpleNotificationServiceException)));
                Assert.That((string)span.LogEntries[0].Fields["message"], Is.EqualTo(ExpectedExceptionMessage));
                Assert.That((string)span.LogEntries[0].Fields["error.kind"], Is.EqualTo("Exception"));
                Assert.IsTrue(((string)span.LogEntries[0].Fields["stack"]).Contains("NewRelic.Tests.AwsLambda.AwsLambdaWrapperTests.LambdaWrapperTests.SendSNSMessageWithException(PublishRequest publishRequest, CancellationToken cancellationToken)"));

                Assert.That(span.OperationName, Is.EqualTo(ExpectedOperationName));
                return;
            }

            Assert.Fail("Did not catch exception as expected.");
        }
Exemplo n.º 2
0
        public async Task SNSWrapper_PublishRequest_WrapRequestWithTopicAndMessage_BadResponse()
        {
            const string TestTopicName         = "testTopicName";
            const string ExpectedOperationName = "MessageBroker/SNS/Topic/Produce/Named/" + TestTopicName;
            const string TopicArn = "arn:aws:sns:us-west-2:1234567890:" + TestTopicName;

            var result = await SNSWrapper.WrapRequest(SendSNSMessageWithBadResult, TopicArn, "myMessage");

            var span = _tracer.FinishedSpans()[0];

            Assert.That(span.Tags["span.kind"], Is.EqualTo("client"));
            Assert.That(span.Tags["component"], Is.EqualTo("SNS"));
            Assert.That(span.Tags["aws.operation"], Is.EqualTo("Produce"));
            Assert.That(span.Tags["http.status_code"], Is.EqualTo((int)HttpStatusCode.BadRequest));
            Assert.That(span.OperationName, Is.EqualTo(ExpectedOperationName));
        }
Exemplo n.º 3
0
        public async Task SNSWrapper_PublishRequest_WrapRequestWithPhoneNumberObject_OkResponse()
        {
            const string TestPhoneNumber       = "+1503555100";
            const string ExpectedOperationName = "MessageBroker/SNS/Topic/Produce/Named/PhoneNumber";
            var          publishRequest        = new PublishRequest
            {
                PhoneNumber = TestPhoneNumber,
                Message     = "myMessage"
            };

            var result = await SNSWrapper.WrapRequest(SendSNSMessage, publishRequest);

            var span = _tracer.FinishedSpans()[0];

            Assert.That(span.Tags["span.kind"], Is.EqualTo("client"));
            Assert.That(span.Tags["component"], Is.EqualTo("SNS"));
            Assert.That(span.Tags["aws.operation"], Is.EqualTo("Produce"));
            Assert.That(span.Tags["http.status_code"], Is.EqualTo((int)HttpStatusCode.OK));
            Assert.That(span.OperationName, Is.EqualTo(ExpectedOperationName));
        }