@@ -230,6 +230,7 @@ public CompletableFuture<Void> prepare(final String key, final int amountDelta,
230230 // check if the request would be rate limited without actually using the rate limit
231231 checkRateLimit (bucketRef [0 ], requestSize );
232232 } catch (RateLimitExceededException e ) {
233+ meterRegistry .counter (validateCounterName , "outcome" , "requestWouldExceedRateLimit" ).increment ();
233234 return Mono .error (e );
234235 }
235236 final TokenCost cost = TokenCost .create (key , newTokenId , requestSize , now .toString (), getTtl ());
@@ -238,7 +239,8 @@ public CompletableFuture<Void> prepare(final String key, final int amountDelta,
238239 return this .container .createItem (cost , new PartitionKey (cost .getKey ()), new CosmosItemRequestOptions ());
239240 })
240241 .onErrorMap (CosmosException .class , CosmosTokenRateLimiter ::marshal )
241- .doOnError (e -> logger .warn ("Failed to persist token cost for {}" , KeyToken .of (key , newTokenId ), e ))
242+ .doOnError (e -> !(CompletionExceptions .unwrap (e ) instanceof RateLimitExceededException ), e ->
243+ logger .warn ("Failed to persist token cost for {}" , KeyToken .of (key , newTokenId ), e ))
242244 .doFinally (ignore -> sample .stop (prepareTimer ))
243245 .toFuture ().thenApply (ignored -> null );
244246 }
0 commit comments