From 6ed6ce2deb900cec7633858f08e5769e06569e7b Mon Sep 17 00:00:00 2001 From: Jason McKenzie Date: Fri, 29 May 2026 13:08:00 -0700 Subject: [PATCH] adjust logging to avoid expensive CosmosException.getMessage() on WARN level --- .../epkversion/PartitionProcessorImpl.java | 14 +++++++++++--- .../pkversion/PartitionProcessorImpl.java | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/PartitionProcessorImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/PartitionProcessorImpl.java index 8baff17be50b..96d2af4605c6 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/PartitionProcessorImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/epkversion/PartitionProcessorImpl.java @@ -198,9 +198,17 @@ public Mono run(CancellationToken cancellationToken) { CosmosException clientException = (CosmosException) throwable; logger.warn( - "Lease with token " + this.lease.getLeaseToken() + ": CosmosException was thrown from thread " + - Thread.currentThread().getId() + " for lease with owner " + this.lease.getOwner(), - clientException); + "Lease with token {}: CosmosException was thrown from thread {} for lease with owner {} {}", + this.lease.getLeaseToken(), + Thread.currentThread().getId(), + this.lease.getOwner(), + clientException.getShortMessage()); + if (logger.isDebugEnabled()) { + logger.debug( + "Lease with token " + this.lease.getLeaseToken() + ": CosmosException was thrown from thread " + + Thread.currentThread().getId() + " for lease with owner " + this.lease.getOwner(), + clientException); + } StatusCodeErrorType docDbError = ExceptionClassifier.classifyClientException(clientException); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/PartitionProcessorImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/PartitionProcessorImpl.java index fe1609c3a852..c8f1969f22d2 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/PartitionProcessorImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/pkversion/PartitionProcessorImpl.java @@ -208,9 +208,18 @@ public Mono run(CancellationToken cancellationToken) { // we know it is a terminal event. CosmosException clientException = (CosmosException) throwable; - logger.warn("CosmosException: Partition " + this.lease.getLeaseToken() - + " from thread " + Thread.currentThread().getId() + " with owner " + this.lease.getOwner(), - clientException); + logger.warn( + "CosmosException: partition {} from thread {} with owner {} {}", + this.lease.getLeaseToken(), + Thread.currentThread().getId(), + this.lease.getOwner(), + clientException.getShortMessage()); + if (logger.isDebugEnabled()) { + logger.debug( + "CosmosException: partition" + this.lease.getLeaseToken() + + "from thread " + Thread.currentThread().getId() + " with owner " + this.lease.getOwner(), + clientException); + } StatusCodeErrorType docDbError = ExceptionClassifier.classifyClientException(clientException); switch (docDbError) {