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); }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public async Task <AmazonWebServiceResponse> SendEmailHandlerAsync(Event input, ILambdaContext context) { var logs = new CloudWatchLogsService() { LogGroupName = @"/aws/codebuild/" + input.Detail.ProjectName, LogStreamName = input.Detail.BuildId.Split('/').Last().Split(':').Last(), LogRowLimit = 10000 }; var email = new SimpleEmailService() { Subject = String.Format("Build {0} failed on phase {1} at {2}.", input.Detail.ProjectName, input.Detail.CurrentPhase, input.Time), Body = String.Format("The build with id of {0} has failed. \n" + "Here is the log transcript: \n {1}", input.Detail.BuildId, await logs.GetCloudWatchLogEventsAsync()) }; return(await email.SendEmailAsync()); }
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); }