From 355e963ba2c9161449c59e0562f4913551aef209 Mon Sep 17 00:00:00 2001 From: sharanrudresh Date: Tue, 30 Jun 2026 12:26:15 +0530 Subject: [PATCH] CC-42186/CC-42185: stop leaking failing-document BSON via DLQ WriteException PR #110 sanitized the ERROR log statements but left the DLQ exception classes untouched. WriteException / WriteConcernException still embedded the failing document's BSON (error.getDetails().toJson()) in getMessage(), which surfaces: - at DEBUG via StartedMongoSinkTask.log() (LOGGER.debug(..., e)), and - in DLQ error headers via AnalyzedBatchFailedWithBulkWriteException.report(). Drop the `details` field from both message formats and bump the documented message-format version 1 -> 2 (the `v` marker exists precisely to signal such format changes). code / codeName / message are retained. Co-Authored-By: Claude Opus 4.8 --- .../connect/sink/dlq/WriteConcernException.java | 17 +++++++++-------- .../kafka/connect/sink/dlq/WriteException.java | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteConcernException.java b/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteConcernException.java index c592f8fdd..0c9df5bdc 100644 --- a/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteConcernException.java +++ b/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteConcernException.java @@ -21,24 +21,25 @@ import com.mongodb.bulk.WriteConcernError; /** - * The {@linkplain #getMessage() message} {@linkplain Formatter format} is {@code "v=1, code=%d, - * codeName=%s, message=%s, details=%s"}, where {@code details} is JSON produced with {@link - * org.bson.BsonDocument#toJson()}. We may change it in the future, in which case the version - * (marked with {@code v}) will be incremented. + * The {@linkplain #getMessage() message} {@linkplain Formatter format} is {@code "v=2, code=%d, + * codeName=%s, message=%s"}. We may change it in the future, in which case the version (marked with + * {@code v}) will be incremented. + * + *

The {@code details} field (BSON of the failing document, previously emitted in {@code v=1}) is + * intentionally omitted: it carried record-derived content into the DLQ and into DEBUG logs. */ public final class WriteConcernException extends NoStackTraceDlqException { private static final long serialVersionUID = 1L; - private static final int MESSAGE_FORMAT_VERSION = 1; + private static final int MESSAGE_FORMAT_VERSION = 2; public WriteConcernException(final WriteConcernError error) { super( String.format( Locale.ENGLISH, - "v=%d, code=%d, codeName=%s, message=%s, details=%s", + "v=%d, code=%d, codeName=%s, message=%s", MESSAGE_FORMAT_VERSION, error.getCode(), error.getCodeName(), - error.getMessage(), - error.getDetails().toJson())); + error.getMessage())); } } diff --git a/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteException.java b/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteException.java index b028421a4..c8b93893f 100644 --- a/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteException.java +++ b/src/main/java/com/mongodb/kafka/connect/sink/dlq/WriteException.java @@ -21,23 +21,24 @@ import com.mongodb.WriteError; /** - * The {@linkplain #getMessage() message} {@linkplain Formatter format} is {@code "v=1, code=%d, - * message=%s, details=%s"}, where {@code details} is JSON produced with {@link - * org.bson.BsonDocument#toJson()}. We may change it in the future, in which case the version - * (marked with {@code v}) will be incremented. + * The {@linkplain #getMessage() message} {@linkplain Formatter format} is {@code "v=2, code=%d, + * message=%s"}. We may change it in the future, in which case the version (marked with {@code v}) + * will be incremented. + * + *

The {@code details} field (BSON of the failing document, previously emitted in {@code v=1}) is + * intentionally omitted: it carried record-derived content into the DLQ and into DEBUG logs. */ public final class WriteException extends NoStackTraceDlqException { private static final long serialVersionUID = 1L; - private static final int MESSAGE_FORMAT_VERSION = 1; + private static final int MESSAGE_FORMAT_VERSION = 2; public WriteException(final WriteError error) { super( String.format( Locale.ENGLISH, - "v=%d, code=%d, message=%s, details=%s", + "v=%d, code=%d, message=%s", MESSAGE_FORMAT_VERSION, error.getCode(), - error.getMessage(), - error.getDetails().toJson())); + error.getMessage())); } }