Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log stacktrace #3418

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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;
Expand Down Expand Up @@ -179,6 +181,10 @@ private void logWarning(
} else {
LOGGER.warn(re.getMessage());
}
// Log the stacktrace for troubleshoot.
StringWriter stringWriter = new StringWriter();
re.printStackTrace(new PrintWriter(stringWriter));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not threadsafe -- we probably don't want this here. Logging is the goal.

LOGGER.warn(stringWriter.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would duplicate the log entry since we're already sending a log above. Can we adjust the log messages above, instead? For example, LOGGER.warn("Message", exception)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks, I wasn't aware there's a LOGGER.warn(String, Exception) method.

}

private void addToHealthRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading