From 09eed914e3ac0e1e193fa5464c3677d6d80db643 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 13 Dec 2024 18:18:02 -0500 Subject: [PATCH 1/5] feat: log stacktrace --- .../pubsub/integration/inbound/PubSubInboundChannelAdapter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java index 14ad6ad288..6ccbca15b8 100644 --- a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java +++ b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java @@ -179,6 +179,7 @@ private void logWarning( } else { LOGGER.warn(re.getMessage()); } + LOGGER.warn(re.getStackTrace()); } private void addToHealthRegistry() { From d438430e2e479ed62668152faebbb9d35ef0326b Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 13 Dec 2024 18:43:56 -0500 Subject: [PATCH 2/5] use string writer --- .../integration/inbound/PubSubInboundChannelAdapter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java index 6ccbca15b8..a5df104c7b 100644 --- a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java +++ b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java @@ -16,6 +16,7 @@ package com.google.cloud.spring.pubsub.integration.inbound; +import com.fasterxml.jackson.databind.util.ExceptionUtil; import com.google.cloud.pubsub.v1.Subscriber; import com.google.cloud.spring.pubsub.core.health.HealthTrackerRegistry; import com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberOperations; @@ -24,6 +25,8 @@ import com.google.cloud.spring.pubsub.support.GcpPubSubHeaders; import com.google.cloud.spring.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage; import com.google.pubsub.v1.ProjectSubscriptionName; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -179,7 +182,10 @@ private void logWarning( } else { LOGGER.warn(re.getMessage()); } - LOGGER.warn(re.getStackTrace()); + + StringWriter stringWriter = new StringWriter(); + re.printStackTrace(new PrintWriter(stringWriter)); + LOGGER.warn(stringWriter.toString()); } private void addToHealthRegistry() { From 50ede5d989d8331e5bf51267d4546ee21a360e97 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 13 Dec 2024 18:46:07 -0500 Subject: [PATCH 3/5] reformat --- .../pubsub/integration/inbound/PubSubInboundChannelAdapter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java index a5df104c7b..eeccda9f71 100644 --- a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java +++ b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java @@ -16,7 +16,6 @@ package com.google.cloud.spring.pubsub.integration.inbound; -import com.fasterxml.jackson.databind.util.ExceptionUtil; import com.google.cloud.pubsub.v1.Subscriber; import com.google.cloud.spring.pubsub.core.health.HealthTrackerRegistry; import com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberOperations; From 0d826d1886f67d80355fb76368a392cbcf154d2c Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Mon, 16 Dec 2024 10:08:29 -0500 Subject: [PATCH 4/5] modify test --- .../pubsub/integration/inbound/PubSubInboundChannelAdapter.java | 2 +- .../integration/inbound/PubSubInboundChannelAdapterTests.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java index eeccda9f71..4ae2374056 100644 --- a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java +++ b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java @@ -181,7 +181,7 @@ private void logWarning( } else { LOGGER.warn(re.getMessage()); } - + // Log the stacktrace for troubleshoot. StringWriter stringWriter = new StringWriter(); re.printStackTrace(new PrintWriter(stringWriter)); LOGGER.warn(stringWriter.toString()); diff --git a/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java b/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java index 05289026e6..b61f42cd2f 100644 --- a/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java +++ b/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java @@ -167,6 +167,7 @@ void testAckModeAuto_nacksWhenDownstreamProcessingFailsWhenContextShutdown(Captu // original message handling exception assertThat(capturedOutput).contains("failed; message nacked automatically").contains(EXCEPTION_MESSAGE); + assertThat(capturedOutput).contains("Caused by"); } @Test From f9f66015fda91bfa489b7c537b57c424a42b86ca Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Mon, 16 Dec 2024 11:00:09 -0500 Subject: [PATCH 5/5] log exception along the message --- .../inbound/PubSubInboundChannelAdapter.java | 10 ++-------- .../inbound/PubSubInboundChannelAdapterTests.java | 6 ++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java index 4ae2374056..21bb4990fb 100644 --- a/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java +++ b/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapter.java @@ -24,8 +24,6 @@ import com.google.cloud.spring.pubsub.support.GcpPubSubHeaders; import com.google.cloud.spring.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage; import com.google.pubsub.v1.ProjectSubscriptionName; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -177,14 +175,10 @@ private void logWarning( // so we explicitly log failure messages. // See https://github.com/spring-projects/spring-framework/issues/25162 for more info. if (re instanceof MessageDeliveryException messageDeliveryException) { - LOGGER.warn(messageDeliveryException.getFailedMessage()); + LOGGER.warn(messageDeliveryException.getFailedMessage(), messageDeliveryException); } else { - LOGGER.warn(re.getMessage()); + LOGGER.warn(re.getMessage(), re); } - // Log the stacktrace for troubleshoot. - StringWriter stringWriter = new StringWriter(); - re.printStackTrace(new PrintWriter(stringWriter)); - LOGGER.warn(stringWriter.toString()); } private void addToHealthRegistry() { diff --git a/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java b/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java index b61f42cd2f..925fc53ded 100644 --- a/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java +++ b/spring-cloud-gcp-pubsub/src/test/java/com/google/cloud/spring/pubsub/integration/inbound/PubSubInboundChannelAdapterTests.java @@ -166,8 +166,10 @@ void testAckModeAuto_nacksWhenDownstreamProcessingFailsWhenContextShutdown(Captu verify(mockAcknowledgeableMessage, times(0)).ack(); // original message handling exception - assertThat(capturedOutput).contains("failed; message nacked automatically").contains(EXCEPTION_MESSAGE); - assertThat(capturedOutput).contains("Caused by"); + assertThat(capturedOutput) + .contains("failed; message nacked automatically") + .contains(EXCEPTION_MESSAGE) + .contains("Caused by"); } @Test