public async void Test()
        {
            var service = new CloudWatchLogsService();
            var logs    = await service.GetCloudWatchEventMessagesForLogGroup(_fixture.LogGroupName, _startTime);

            var errorEventRawData = CloudWatchUtilities.GetErrorEventDataFromLog(logs);
            var errorEvents       = JsonConvert.DeserializeObject <List <ErrorEventEvents> >(errorEventRawData);
            var errorEvent        = errorEvents.First();

            var errorTraceRawData = CloudWatchUtilities.GetErrorTraceDataFromLog(logs);
            var errorTraces       = JsonConvert.DeserializeObject <List <ErrorTrace> >(errorTraceRawData);
            var errorTrace        = errorTraces.First();

            Assert.Equal("my exception", errorEvent.IntrinsicAttributes["error.message"]);
            Assert.Equal("Exception", errorEvent.IntrinsicAttributes["error.class"]);
            Assert.Equal("Exception", errorEvent.UserAttributes["error.kind"]);

            Assert.Equal("Exception", errorTrace.ExceptionClassName);
            Assert.Equal("my exception", errorTrace.Message);
            Assert.Equal("Other/Function/AwsLambdaErrorTestFunction", errorTrace.Path);

            Assert.NotNull(errorTrace.Attributes);
            Assert.True(errorTrace.Attributes.IntrinsicAttributes.Count > 0);
            Assert.True(errorTrace.Attributes.UserAttributes.Count > 0);
            Assert.NotNull(errorTrace.Attributes.StackTrace);

            await service.DeleteCloudWatchLogStreamsForLogStreams(_fixture.LogGroupName);
        }
        public async void Test()
        {
            var service = new CloudWatchLogsService();
            var logs    = await service.GetCloudWatchEventMessagesForLogGroup(_fixture.LogGroupName, _startTime);

            var spanEventsRawData = CloudWatchUtilities.GetSpanEventDataFromLog(logs);
            var spanEvents        = JsonConvert.DeserializeObject <List <SpanEvent> >(spanEventsRawData);

            var sQSSendMessageSpan    = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "SQS" && span.AgentAttributes["aws.operation"].ToString() == "Produce").FirstOrDefault();
            var sQSReceiveMessageSpan = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "SQS" && span.AgentAttributes["aws.operation"].ToString() == "Consume").ToList().FirstOrDefault();

            var dynamoDescribeTableDBSpan = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "DynamoDB" && span.AgentAttributes["aws.operation"].ToString() == "describe_table").FirstOrDefault();
            var dynamoGetItemTableDBSpan  = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "DynamoDB" && span.AgentAttributes["aws.operation"].ToString() == "get_item").FirstOrDefault();

            var sNSPublishSpanTopic       = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "SNS" && span.AgentAttributes["aws.operation"].ToString() == "Produce" && !span.IntrinsicAttributes["name"].ToString().Contains("PhoneNumber")).FirstOrDefault();
            var sNSPublishSpanPhoneNumber = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "SNS" && span.AgentAttributes["aws.operation"].ToString() == "Produce" && span.IntrinsicAttributes["name"].ToString().Contains("PhoneNumber")).FirstOrDefault();

            var httpOutErrorSpan = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "HttpOut" && span.AgentAttributes.ContainsKey("error")).FirstOrDefault();
            var httpOutSpan      = spanEvents.Where(span => span.AgentAttributes.ContainsKey("component") && span.AgentAttributes["component"].ToString() == "HttpOut" && !span.AgentAttributes.ContainsKey("error")).FirstOrDefault();

            Assert.Equal("client", (string)sQSSendMessageSpan.AgentAttributes["span.kind"]);
            Assert.Equal("MessageBroker/SQS/Queue/Produce/Named/DotnetTestSQS", (string)sQSSendMessageSpan.IntrinsicAttributes["name"]);
            Assert.Equal("client", (string)sQSReceiveMessageSpan.AgentAttributes["span.kind"]);
            Assert.Equal("MessageBroker/SQS/Queue/Consume/Named/DotnetTestSQS", (string)sQSReceiveMessageSpan.IntrinsicAttributes["name"]);

            Assert.Equal("client", (string)dynamoDescribeTableDBSpan.AgentAttributes["span.kind"]);
            Assert.Equal("Datastore/statement/DynamoDB/DotNetTest/describe_table", (string)dynamoDescribeTableDBSpan.IntrinsicAttributes["name"]);
            Assert.Equal("client", (string)dynamoGetItemTableDBSpan.AgentAttributes["span.kind"]);
            Assert.Equal("Datastore/statement/DynamoDB/DotNetTest/get_item", (string)dynamoGetItemTableDBSpan.IntrinsicAttributes["name"]);

            Assert.Equal("client", (string)sNSPublishSpanTopic.AgentAttributes["span.kind"]);
            Assert.Equal("MessageBroker/SNS/Topic/Produce/Named/DotNetTestSNSTopic", (string)sNSPublishSpanTopic.IntrinsicAttributes["name"]);

            Assert.Equal("client", (string)sNSPublishSpanPhoneNumber.AgentAttributes["span.kind"]);
            Assert.Equal("MessageBroker/SNS/Topic/Produce/Named/PhoneNumber", (string)sNSPublishSpanPhoneNumber.IntrinsicAttributes["name"]);

            Assert.Equal("client", (string)httpOutSpan.AgentAttributes["span.kind"]);
            Assert.Equal("External/www.newrelic.com/GET", (string)httpOutSpan.IntrinsicAttributes["name"]);

            Assert.Equal("client", (string)httpOutErrorSpan.AgentAttributes["span.kind"]);
            Assert.Equal("External/www.b-a-d.url/GET", (string)httpOutErrorSpan.IntrinsicAttributes["name"]);
            Assert.Equal(true, httpOutErrorSpan.AgentAttributes["error"]);

            await service.DeleteCloudWatchLogStreamsForLogStreams(_fixture.LogGroupName);
        }
        public async void Test()
        {
            var service = new CloudWatchLogsService();
            var logs    = await service.GetCloudWatchEventMessagesForLogGroup(_fixture.LogGroupName, _startTime);

            var spanEventsRawData = CloudWatchUtilities.GetSpanEventDataFromLog(logs);
            var spanEvents        = JsonConvert.DeserializeObject <List <SpanEvent> >(spanEventsRawData);

            var transactionEvents = JsonConvert.DeserializeObject <List <TransactionEvent> >(spanEventsRawData);

            var spanEvent        = spanEvents.First();
            var transactionEvent = transactionEvents.First();

            Assert.NotNull(spanEvent.IntrinsicAttributes);
            Assert.NotNull(spanEvent.UserAttributes);
            Assert.NotNull(spanEvent.AgentAttributes);

            // Span Event Intrinsic Attributes
            ValidateExpectedAttributesNotNull(_expectedIntrinsicAttributeNames, spanEvent.IntrinsicAttributes);
            Assert.Equal(spanEvent.IntrinsicAttributes["traceId"], spanEvent.IntrinsicAttributes["transactionId"]);
            Assert.False(spanEvent.IntrinsicAttributes.ContainsKey("parentId")); //There should be no parent as this is the first span.

            // Span Event Agent Attributes
            ValidateExpectedAttributesNotNull(_expectedAgentAttributeNames, spanEvent.AgentAttributes);
            Assert.Equal("443", spanEvent.AgentAttributes["request.headers.x-forwarded-port"]);
            Assert.Equal("200", spanEvent.AgentAttributes["response.status"]);

            // Transaction Event Intrinsic Attributes
            ValidateExpectedAttributesNotNull(_expectedIntrinsicAttributeNames, transactionEvent.IntrinsicAttributes);

            // Transaction Event Agent Attributes
            ValidateExpectedAttributesNotNull(_expectedAgentAttributeNames, transactionEvent.AgentAttributes);
            Assert.Equal("443", transactionEvent.AgentAttributes["request.headers.x-forwarded-port"]);
            Assert.Equal("200", transactionEvent.AgentAttributes["response.status"]);

            await service.DeleteCloudWatchLogStreamsForLogStreams(_fixture.LogGroupName);
        }
Esempio n. 4
0
        public async void ChainTest()
        {
            var calleeApplicationSpanEvents = await GetSpanEvents(_fixture.CalleeApplication.LogGroupName, _fixture.CallerApplication.StartTime.AddMinutes(-2));

            var callerApplicationSpanEvents = await GetSpanEvents(_fixture.CallerApplication.LogGroupName, _fixture.CallerApplication.StartTime.AddMinutes(-2));

            var calleeApplicationTransactionEvents = await GetTransactionEvents(_fixture.CalleeApplication.LogGroupName, _fixture.CallerApplication.StartTime.AddMinutes(-2));

            var callerApplicationTransactionEvents = await GetTransactionEvents(_fixture.CallerApplication.LogGroupName, _fixture.CallerApplication.StartTime.AddMinutes(-2));

            var calleeSpanEvent        = calleeApplicationSpanEvents.First();
            var calleeTransactionEvent = calleeApplicationTransactionEvents.First();

            var callerSpanEvent        = callerApplicationSpanEvents.First();
            var callerTransactionEvent = callerApplicationTransactionEvents.First();

            Assert.NotNull(calleeSpanEvent.IntrinsicAttributes);
            Assert.NotNull(calleeSpanEvent.UserAttributes);
            Assert.NotNull(calleeSpanEvent.AgentAttributes);

            // Span Event A Intrinsic Attributes
            ValidateExpectedAttributesNotNull(_expectedIntrinsicAttributeNames, calleeSpanEvent.IntrinsicAttributes);
            Assert.Equal(callerSpanEvent.IntrinsicAttributes["transactionId"], calleeSpanEvent.IntrinsicAttributes["traceId"]);
            Assert.True(calleeSpanEvent.IntrinsicAttributes.ContainsKey("parentId"));

            // Span Event A Agent Attributes
            ValidateExpectedAttributesNotNull(_expectedAgentAttributeNames, calleeSpanEvent.AgentAttributes);
            Assert.Equal("443", calleeSpanEvent.AgentAttributes["request.headers.x-forwarded-port"]);
            Assert.Equal("200", calleeSpanEvent.AgentAttributes["response.status"]);

            // Transaction Event A Intrinsic Attributes
            ValidateExpectedAttributesNotNull(_expectedIntrinsicAttributeNames, calleeTransactionEvent.IntrinsicAttributes);

            // Transaction Event A Agent Attributes
            ValidateExpectedAttributesNotNull(_expectedAgentAttributeNames, calleeTransactionEvent.AgentAttributes);
            Assert.Equal("443", calleeTransactionEvent.AgentAttributes["request.headers.x-forwarded-port"]);
            Assert.Equal("200", calleeTransactionEvent.AgentAttributes["response.status"]);

            Assert.NotNull(callerSpanEvent.IntrinsicAttributes);
            Assert.NotNull(callerSpanEvent.UserAttributes);
            Assert.NotNull(callerSpanEvent.AgentAttributes);

            // Span Event B Intrinsic Attributes
            ValidateExpectedAttributesNotNull(_expectedIntrinsicAttributeNames, callerSpanEvent.IntrinsicAttributes);
            Assert.Equal(callerSpanEvent.IntrinsicAttributes["traceId"], callerSpanEvent.IntrinsicAttributes["transactionId"]);
            Assert.False(callerSpanEvent.IntrinsicAttributes.ContainsKey("parentId")); //There should be no parent as this is the first span.

            // Span Event B Agent Attributes
            ValidateExpectedAttributesNotNull(_expectedAgentAttributeNames, callerSpanEvent.AgentAttributes);
            Assert.Equal("443", callerSpanEvent.AgentAttributes["request.headers.x-forwarded-port"]);
            Assert.Equal("200", callerSpanEvent.AgentAttributes["response.status"]);

            // Transaction Event B Intrinsic Attributes
            ValidateExpectedAttributesNotNull(_expectedIntrinsicAttributeNames, callerTransactionEvent.IntrinsicAttributes);

            // Transaction Event B Agent Attributes
            ValidateExpectedAttributesNotNull(_expectedAgentAttributeNames, callerTransactionEvent.AgentAttributes);
            Assert.Equal("443", callerTransactionEvent.AgentAttributes["request.headers.x-forwarded-port"]);
            Assert.Equal("200", callerTransactionEvent.AgentAttributes["response.status"]);

            await _cloudWatchLogsService.DeleteCloudWatchLogStreamsForLogStreams(_fixture.CalleeApplication.LogGroupName);

            await _cloudWatchLogsService.DeleteCloudWatchLogStreamsForLogStreams(_fixture.CallerApplication.LogGroupName);
        }