From 344c4db6156b5d88c6e4b545dc7cb4f416f351fb Mon Sep 17 00:00:00 2001 From: annie-mac Date: Thu, 5 May 2022 11:48:43 -0700 Subject: [PATCH 01/12] update comments --- .../main/java/com/azure/cosmos/CosmosAsyncContainer.java | 8 ++++---- .../src/main/java/com/azure/cosmos/CosmosContainer.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java index 33b084e4b949d..d8b651f83f0d2 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java @@ -1651,8 +1651,8 @@ Mono> getNormalizedEffectiveRange(FeedRange feedRange) { *
      * ThroughputControlGroupConfig groupConfig =
      *     new ThroughputControlGroupConfigBuilder()
-     *         .setGroupName("localControlGroup")
-     *         .setTargetThroughputThreshold(0.1)
+     *         .groupName("localControlGroup")
+     *         .targetThroughputThreshold(0.1)
      *         .build();
      *
      * container.enableLocalThroughputControlGroup(groupConfig);
@@ -1675,8 +1675,8 @@ public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig group
      * 
      * ThroughputControlGroupConfig groupConfig =
      *     new ThroughputControlGroupConfigBuilder()
-     *         .setGroupName("localControlGroup")
-     *         .setTargetThroughputThreshold(0.1)
+     *         .groupName("localControlGroup")
+     *         .targetThroughputThreshold(0.1)
      *         .build();
      *
      * GlobalThroughputControlConfig globalControlConfig =
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosContainer.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosContainer.java
index 0551a2610b756..5b6565f274a25 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosContainer.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosContainer.java
@@ -745,8 +745,8 @@ public List getFeedRanges() {
      * 
      * ThroughputControlGroupConfig groupConfig =
      *     new ThroughputControlGroupConfigBuilder()
-     *         .setGroupName("localControlGroup")
-     *         .setTargetThroughputThreshold(0.1)
+     *         .groupName("localControlGroup")
+     *         .targetThroughputThreshold(0.1)
      *         .build();
      *
      * container.enableLocalThroughputControlGroup(groupConfig);
@@ -768,8 +768,8 @@ public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig group
      * 
      * ThroughputControlGroupConfig groupConfig =
      *     new ThroughputControlGroupConfigBuilder()
-     *         .setGroupName("localControlGroup")
-     *         .setTargetThroughputThreshold(0.1)
+     *         .groupName("localControlGroup")
+     *         .targetThroughputThreshold(0.1)
      *         .build();
      *
      * GlobalThroughputControlConfig globalControlConfig =

From bddf11c18bc4c145f20c2786cda437608b4be699 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Mon, 23 May 2022 11:53:40 -0700
Subject: [PATCH 02/12] allowClientTelemetryRequestToGoThroughProxy

---
 .../benchmark/ctl/AsyncCtlWorkload.java       |   2 -
 .../java/com/azure/cosmos/BridgeInternal.java |   2 +-
 .../ClientTelemetryConnectionConfig.java      | 145 ++++++++++++++++++
 .../com/azure/cosmos/CosmosAsyncClient.java   |  17 +-
 .../com/azure/cosmos/CosmosClientBuilder.java |  37 ++++-
 .../implementation/AsyncDocumentClient.java   |  16 +-
 .../implementation/ClientTelemetryConfig.java |  49 ++++++
 .../implementation/ConnectionPolicy.java      |  11 --
 .../implementation/RxDocumentClientImpl.java  |  82 ++++++++--
 .../cosmos/implementation/TracerProvider.java |   6 +-
 .../clienttelemetry/ClientTelemetry.java      |  33 +++-
 .../RntbdChannelAcquisitionTimeline.java      |   3 +-
 .../azure/cosmos/util/CosmosPagedFlux.java    |   4 +-
 .../com/azure/cosmos/ClientTelemetryTest.java |  56 +++++--
 .../azure/cosmos/ClientUnderTestBuilder.java  |   3 +-
 .../azure/cosmos/ConnectionConfigTest.java    |  39 +++++
 .../RxDocumentClientUnderTest.java            |  19 ++-
 .../implementation/SpyClientBuilder.java      |  11 +-
 .../SpyClientUnderTestFactory.java            | 145 ++++++++++++++----
 .../BarrierRequestHelperTest.java             |  15 +-
 .../directconnectivity/ReflectionUtils.java   |   9 ++
 .../cosmos/rx/proxy/HttpProxyServer.java      |   8 +
 22 files changed, 610 insertions(+), 102 deletions(-)
 create mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java
 create mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java

diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java
index 18693846c5cdb..cc8024983dc0f 100644
--- a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java
+++ b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java
@@ -33,7 +33,6 @@
 import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
 import io.micrometer.core.instrument.MeterRegistry;
 import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramResetOnSnapshotReservoir;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,7 +42,6 @@
 import reactor.core.scheduler.Schedulers;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java
index 081ee29e960b4..dcc4b0d78495c 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java
@@ -97,7 +97,7 @@ public static String getServiceEndpoint(CosmosAsyncClient cosmosAsyncClient) {
 
     @Warning(value = INTERNAL_USE_ONLY_WARNING)
     public static boolean isClientTelemetryEnabled(CosmosAsyncClient cosmosAsyncClient) {
-        return cosmosAsyncClient.isClientTelemetryEnabled();
+        return cosmosAsyncClient.getClientTelemetryConfig().isClientTelemetryEnabled();
     }
 
     @Warning(value = INTERNAL_USE_ONLY_WARNING)
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java
new file mode 100644
index 0000000000000..8d2cc3d2fa411
--- /dev/null
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java
@@ -0,0 +1,145 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.azure.cosmos;
+
+import com.azure.core.http.ProxyOptions;
+
+import java.time.Duration;
+
+import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkArgument;
+import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
+
+/**
+ * Represents the client telemetry config.
+ */
+public class ClientTelemetryConnectionConfig {
+    private static final Duration MIN_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(60);
+    private static final Duration DEFAULT_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(60);
+    private static final Duration DEFAULT_IDLE_CONNECTION_TIMEOUT = Duration.ofSeconds(60);
+    private static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 1000;
+
+    private Duration networkRequestTimeout;
+    private int maxConnectionPoolSize;
+    private Duration idleConnectionTimeout;
+    private ProxyOptions proxy;
+
+    public ClientTelemetryConnectionConfig() {
+        this.idleConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
+        this.maxConnectionPoolSize = DEFAULT_MAX_CONNECTION_POOL_SIZE;
+        this.networkRequestTimeout = DEFAULT_NETWORK_REQUEST_TIMEOUT;
+    }
+
+    public static ClientTelemetryConnectionConfig getDefaultConfig() {
+        return new ClientTelemetryConnectionConfig();
+    }
+
+    /**
+     * Gets the network request timeout interval (time to wait for response from network peer).
+     * The default is 60 seconds.
+     *
+     * @return the network request timeout duration.
+     */
+    public Duration getNetworkRequestTimeout() {
+        return this.networkRequestTimeout;
+    }
+
+    /**
+     * Sets the network request timeout interval (time to wait for response from network peer).
+     * The default is 60 seconds.
+     *
+     * @param networkRequestTimeout the network request timeout duration.
+     * @return the {@link ClientTelemetryConnectionConfig}.
+     */
+    ClientTelemetryConnectionConfig setNetworkRequestTimeout(Duration networkRequestTimeout) {
+        checkNotNull(networkRequestTimeout, "NetworkRequestTimeout can not be null");
+        checkArgument(networkRequestTimeout.toMillis() >= MIN_NETWORK_REQUEST_TIMEOUT.toMillis(),
+                "NetworkRequestTimeout can not be less than %s millis", MIN_NETWORK_REQUEST_TIMEOUT.toMillis());
+        this.networkRequestTimeout = networkRequestTimeout;
+        return this;
+    }
+
+    /**
+     * Gets the value of the connection pool size the client is using.
+     *
+     * @return connection pool size.
+     */
+    public int getMaxConnectionPoolSize() {
+        return this.maxConnectionPoolSize;
+    }
+
+    /**
+     * Sets the value of the connection pool size, the default
+     * is 1000.
+     *
+     * @param maxConnectionPoolSize The value of the connection pool size.
+     * @return the {@link ClientTelemetryConnectionConfig}.
+     */
+    ClientTelemetryConnectionConfig setMaxConnectionPoolSize(int maxConnectionPoolSize) {
+        this.maxConnectionPoolSize = maxConnectionPoolSize;
+        return this;
+    }
+
+    /**
+     * Gets the value of the timeout for an idle connection, the default is 60
+     * seconds.
+     *
+     * @return Idle connection timeout duration.
+     */
+    public Duration getIdleConnectionTimeout() {
+        return this.idleConnectionTimeout;
+    }
+
+    /**
+     * sets the value of the timeout for an idle connection. After that time,
+     * the connection will be automatically closed.
+     *
+     * @param idleConnectionTimeout the duration for an idle connection.
+     * @return the {@link ClientTelemetryConnectionConfig}.
+     */
+    ClientTelemetryConnectionConfig setIdleConnectionTimeout(Duration idleConnectionTimeout) {
+        this.idleConnectionTimeout = idleConnectionTimeout;
+        return this;
+    }
+
+    /**
+     * Gets the proxy options which contain the InetSocketAddress of proxy server.
+     *
+     * @return the proxy options.
+     */
+    public ProxyOptions getProxy() {
+        return this.proxy;
+    }
+
+    /**
+     * Sets the proxy options.
+     *
+     * Currently, only support Http proxy type with just the routing address. Username and password will be ignored.
+     *
+     * @param proxy The proxy options.
+     * @return the {@link ClientTelemetryConnectionConfig}.
+     */
+
+    public ClientTelemetryConnectionConfig setProxy(ProxyOptions proxy) {
+        if (proxy.getType() != ProxyOptions.Type.HTTP) {
+            throw new IllegalArgumentException("Only http proxy type is supported.");
+        }
+
+        this.proxy = proxy;
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        String proxyType = proxy != null ? proxy.getType().toString() : null;
+        String proxyAddress = proxy != null ? proxy.getAddress().toString() : null;
+
+        return "ClientTelemetryConfig{" +
+                ", maxConnectionPoolSize=" + maxConnectionPoolSize +
+                ", idleConnectionTimeout=" + idleConnectionTimeout +
+                ", networkRequestTimeout=" + networkRequestTimeout +
+                ", proxyType=" + proxyType +
+                ", inetSocketProxyAddress=" + proxyAddress +
+                '}';
+    }
+}
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java
index 514b2a56a0f9e..5124d8b0f4227 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncClient.java
@@ -9,6 +9,7 @@
 import com.azure.core.util.tracing.Tracer;
 import com.azure.cosmos.implementation.ApiType;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
@@ -66,7 +67,7 @@ public final class CosmosAsyncClient implements Closeable {
     private final TokenCredential tokenCredential;
     private final boolean sessionCapturingOverride;
     private final boolean enableTransportClientSharing;
-    private final boolean clientTelemetryEnabled;
+    private final ClientTelemetryConfig clientTelemetryConfig;
     private final TracerProvider tracerProvider;
     private final boolean contentResponseOnWriteEnabled;
     private static final Tracer TRACER;
@@ -94,7 +95,7 @@ public final class CosmosAsyncClient implements Closeable {
         this.tokenCredential = builder.getTokenCredential();
         this.sessionCapturingOverride = builder.isSessionCapturingOverrideEnabled();
         this.enableTransportClientSharing = builder.isConnectionSharingAcrossClientsEnabled();
-        this.clientTelemetryEnabled = builder.isClientTelemetryEnabled();
+        this.clientTelemetryConfig = builder.getClientTelemetryConfig();
         this.contentResponseOnWriteEnabled = builder.isContentResponseOnWriteEnabled();
         this.tracerProvider = new TracerProvider(TRACER);
         this.apiType = builder.apiType();
@@ -123,7 +124,8 @@ public final class CosmosAsyncClient implements Closeable {
                                        .withTokenCredential(this.tokenCredential)
                                        .withState(builder.metadataCaches())
                                        .withPermissionFeed(permissionList)
-                                       .withApiType(apiType)
+                                       .withApiType(this.apiType)
+                                       .withClientTelemetryConfig(this.clientTelemetryConfig)
                                        .build();
     }
 
@@ -232,8 +234,13 @@ boolean isContentResponseOnWriteEnabled() {
         return contentResponseOnWriteEnabled;
     }
 
-    boolean isClientTelemetryEnabled() {
-        return clientTelemetryEnabled;
+    /***
+     * Get the client telemetry config.
+     *
+     * @return the {@link ClientTelemetryConfig}.
+     */
+    ClientTelemetryConfig getClientTelemetryConfig() {
+        return this.clientTelemetryConfig;
     }
 
     /**
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
index 39662da9e5f07..263683ce8b889 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
@@ -9,6 +9,7 @@
 import com.azure.core.credential.AzureKeyCredential;
 import com.azure.core.credential.TokenCredential;
 import com.azure.cosmos.implementation.ApiType;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.models.CosmosAuthorizationTokenResolver;
@@ -20,6 +21,7 @@
 import com.azure.cosmos.util.Beta;
 
 import static com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientBuilderHelper;
+import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
 
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -117,6 +119,8 @@ public class CosmosClientBuilder implements
     private boolean multipleWriteRegionsEnabled = true;
     private boolean readRequestsFallbackEnabled = true;
     private boolean clientTelemetryEnabled = false;
+    private ClientTelemetryConnectionConfig clientTelemetryConnectionConfig;
+    private ClientTelemetryConfig clientTelemetryConfig;
     private ApiType apiType = null;
 
     /**
@@ -128,6 +132,7 @@ public CosmosClientBuilder() {
         //  Some default values
         this.userAgentSuffix = "";
         this.throttlingRetryOptions = new ThrottlingRetryOptions();
+        this.clientTelemetryConnectionConfig = ClientTelemetryConnectionConfig.getDefaultConfig();
     }
 
     CosmosClientBuilder metadataCaches(CosmosClientMetadataCachesSnapshot metadataCachesSnapshot) {
@@ -663,6 +668,19 @@ public CosmosClientBuilder readRequestsFallbackEnabled(boolean readRequestsFallb
         return this;
     }
 
+    /***
+     * Set the client telemetry connection config.
+     *
+     * @param clientTelemetryConnectionConfig the {@link ClientTelemetryConnectionConfig}.
+     * @return the current CosmosClientBuilder.
+     */
+    public CosmosClientBuilder clientTelemetryConnectionConfig(ClientTelemetryConnectionConfig clientTelemetryConnectionConfig) {
+        checkNotNull(clientTelemetryConnectionConfig, "Argument 'clientTelemetryConnectionConfig' can not be null");
+        this.clientTelemetryConnectionConfig = clientTelemetryConnectionConfig;
+
+        return this;
+    }
+
     /**
      * Gets the GATEWAY connection configuration to be used.
      *
@@ -742,7 +760,7 @@ boolean isMultipleWriteRegionsEnabled() {
      * @return flag to enable client telemetry.
      */
     boolean isClientTelemetryEnabled() {
-        return clientTelemetryEnabled;
+        return this.clientTelemetryEnabled;
     }
 
     /**
@@ -761,6 +779,10 @@ boolean isReadRequestsFallbackEnabled() {
         return readRequestsFallbackEnabled;
     }
 
+    ClientTelemetryConfig getClientTelemetryConfig() {
+        return this.clientTelemetryConfig;
+    }
+
     /**
      * Builds a cosmos async client with the provided properties
      *
@@ -770,6 +792,7 @@ public CosmosAsyncClient buildAsyncClient() {
 
         validateConfig();
         buildConnectionPolicy();
+        buildClientTelemetryConfig();
         return new CosmosAsyncClient(this);
     }
 
@@ -782,6 +805,7 @@ public CosmosClient buildClient() {
 
         validateConfig();
         buildConnectionPolicy();
+        buildClientTelemetryConfig();
         return new CosmosClient(this);
     }
 
@@ -803,7 +827,16 @@ private void buildConnectionPolicy() {
         this.connectionPolicy.setEndpointDiscoveryEnabled(this.endpointDiscoveryEnabled);
         this.connectionPolicy.setMultipleWriteRegionsEnabled(this.multipleWriteRegionsEnabled);
         this.connectionPolicy.setReadRequestsFallbackEnabled(this.readRequestsFallbackEnabled);
-        this.connectionPolicy.setClientTelemetryEnabled(this.clientTelemetryEnabled);
+    }
+
+    private void buildClientTelemetryConfig() {
+        // There are two ways customer can enable the client telemetry:
+        // 1. Enable through CosmosClientBuilder
+        // 2. Enabled by system property
+
+        this.clientTelemetryConfig = new ClientTelemetryConfig(
+                Configs.isClientTelemetryEnabled(this.clientTelemetryEnabled),
+                this.clientTelemetryConnectionConfig);
     }
 
     private void validateConfig() {
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java
index 217ceae69bdac..34c2e6a56d7a8 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java
@@ -92,6 +92,7 @@ class Builder {
         boolean contentResponseOnWriteEnabled;
         private CosmosClientMetadataCachesSnapshot state;
         private ApiType apiType;
+        ClientTelemetryConfig clientTelemetryConfig;
 
         public Builder withServiceEndpoint(String serviceEndpoint) {
             try {
@@ -210,6 +211,18 @@ public Builder withTokenCredential(TokenCredential tokenCredential) {
             return this;
         }
 
+        /***
+         * Set the client telemetry config.
+         *
+         * @param clientTelemetryConfig the {@link ClientTelemetryConfig}.
+         *
+         * @return the current builder.
+         */
+        public Builder withClientTelemetryConfig(ClientTelemetryConfig clientTelemetryConfig) {
+            this.clientTelemetryConfig = clientTelemetryConfig;
+            return this;
+        }
+
         private void ifThrowIllegalArgException(boolean value, String error) {
             if (value) {
                 throw new IllegalArgumentException(error);
@@ -240,7 +253,8 @@ public AsyncDocumentClient build() {
                 transportClientSharing,
                 contentResponseOnWriteEnabled,
                 state,
-                apiType);
+                apiType,
+                clientTelemetryConfig);
 
             client.init(state, null);
             return client;
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
new file mode 100644
index 0000000000000..2621b27faa2e6
--- /dev/null
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
@@ -0,0 +1,49 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.azure.cosmos.implementation;
+
+import com.azure.core.http.ProxyOptions;
+import com.azure.cosmos.ClientTelemetryConnectionConfig;
+
+import java.time.Duration;
+
+import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
+
+public class ClientTelemetryConfig {
+    private final boolean clientTelemetryEnabled;
+    private final Duration httpNetworkRequestTimeout;
+    private final int maxConnectionPoolSize;
+    private final Duration idleHttpConnectionTimeout;
+    private final ProxyOptions proxy;
+
+    public ClientTelemetryConfig(boolean clientTelemetryEnabled, ClientTelemetryConnectionConfig connectionConfig) {
+        checkNotNull(connectionConfig, "Argument 'connectionConfig' should not be null");
+
+        this.clientTelemetryEnabled = clientTelemetryEnabled;
+        this.httpNetworkRequestTimeout = connectionConfig.getNetworkRequestTimeout();
+        this.maxConnectionPoolSize = connectionConfig.getMaxConnectionPoolSize();
+        this.idleHttpConnectionTimeout = connectionConfig.getIdleConnectionTimeout();
+        this.proxy = connectionConfig.getProxy();
+    }
+
+    public boolean isClientTelemetryEnabled() {
+        return this.clientTelemetryEnabled;
+    }
+
+    public Duration getHttpNetworkRequestTimeout() {
+        return this.httpNetworkRequestTimeout;
+    }
+
+    public int getMaxConnectionPoolSize() {
+        return this.maxConnectionPoolSize;
+    }
+
+    public Duration getIdleHttpConnectionTimeout() {
+        return this.idleHttpConnectionTimeout;
+    }
+
+    public ProxyOptions getProxy() {
+        return this.proxy;
+    }
+}
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConnectionPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConnectionPolicy.java
index 6bde8c8d352e5..91c8e091cefb2 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConnectionPolicy.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConnectionPolicy.java
@@ -47,8 +47,6 @@ public final class ConnectionPolicy {
     private int ioThreadCountPerCoreFactor;
     private int ioThreadPriority;
 
-    private boolean clientTelemetryEnabled;
-
     /**
      * Constructor.
      */
@@ -548,14 +546,6 @@ public ConnectionPolicy setMaxRequestsPerConnection(int maxRequestsPerConnection
         return this;
     }
 
-    public boolean isClientTelemetryEnabled() {
-        return clientTelemetryEnabled;
-    }
-
-    public void setClientTelemetryEnabled(boolean clientTelemetryEnabled) {
-        this.clientTelemetryEnabled = clientTelemetryEnabled;
-    }
-
     public int getIoThreadCountPerCoreFactor() { return this.ioThreadCountPerCoreFactor; }
 
     public int getIoThreadPriority() { return this.ioThreadPriority; }
@@ -592,7 +582,6 @@ public String toString() {
             ", maxConnectionsPerEndpoint=" + maxConnectionsPerEndpoint +
             ", maxRequestsPerConnection=" + maxRequestsPerConnection +
             ", tcpConnectionEndpointRediscoveryEnabled=" + tcpConnectionEndpointRediscoveryEnabled +
-            ", clientTelemetryEnabled=" + clientTelemetryEnabled +
             '}';
     }
 }
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java
index dee46cd55b228..6956945d3b2f0 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java
@@ -178,6 +178,7 @@ public class RxDocumentClientImpl implements AsyncDocumentClient, IAuthorization
 
     private final AtomicBoolean throughputControlEnabled;
     private ThroughputControlStore throughputControlStore;
+    private final ClientTelemetryConfig clientTelemetryConfig;
 
     public RxDocumentClientImpl(URI serviceEndpoint,
                                 String masterKeyOrResourceToken,
@@ -191,9 +192,23 @@ public RxDocumentClientImpl(URI serviceEndpoint,
                                 boolean connectionSharingAcrossClientsEnabled,
                                 boolean contentResponseOnWriteEnabled,
                                 CosmosClientMetadataCachesSnapshot metadataCachesSnapshot,
-                                ApiType apiType) {
-        this(serviceEndpoint, masterKeyOrResourceToken, permissionFeed, connectionPolicy, consistencyLevel, configs,
-            credential, null, sessionCapturingOverride, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled, metadataCachesSnapshot, apiType);
+                                ApiType apiType,
+                                ClientTelemetryConfig clientTelemetryConfig) {
+        this(
+                serviceEndpoint,
+                masterKeyOrResourceToken,
+                permissionFeed,
+                connectionPolicy,
+                consistencyLevel,
+                configs,
+                credential,
+                null,
+                sessionCapturingOverride,
+                connectionSharingAcrossClientsEnabled,
+                contentResponseOnWriteEnabled,
+                metadataCachesSnapshot,
+                apiType,
+                clientTelemetryConfig);
         this.cosmosAuthorizationTokenResolver = cosmosAuthorizationTokenResolver;
     }
 
@@ -210,9 +225,23 @@ public RxDocumentClientImpl(URI serviceEndpoint,
                                 boolean connectionSharingAcrossClientsEnabled,
                                 boolean contentResponseOnWriteEnabled,
                                 CosmosClientMetadataCachesSnapshot metadataCachesSnapshot,
-                                ApiType apiType) {
-        this(serviceEndpoint, masterKeyOrResourceToken, permissionFeed, connectionPolicy, consistencyLevel, configs,
-            credential, tokenCredential, sessionCapturingOverride, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled, metadataCachesSnapshot, apiType);
+                                ApiType apiType,
+                                ClientTelemetryConfig clientTelemetryConfig) {
+        this(
+                serviceEndpoint,
+                masterKeyOrResourceToken,
+                permissionFeed,
+                connectionPolicy,
+                consistencyLevel,
+                configs,
+                credential,
+                tokenCredential,
+                sessionCapturingOverride,
+                connectionSharingAcrossClientsEnabled,
+                contentResponseOnWriteEnabled,
+                metadataCachesSnapshot,
+                apiType,
+                clientTelemetryConfig);
         this.cosmosAuthorizationTokenResolver = cosmosAuthorizationTokenResolver;
     }
 
@@ -228,9 +257,22 @@ private RxDocumentClientImpl(URI serviceEndpoint,
                                 boolean connectionSharingAcrossClientsEnabled,
                                 boolean contentResponseOnWriteEnabled,
                                 CosmosClientMetadataCachesSnapshot metadataCachesSnapshot,
-                                ApiType apiType) {
-        this(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs,
-            credential, tokenCredential, sessionCapturingOverrideEnabled, connectionSharingAcrossClientsEnabled, contentResponseOnWriteEnabled, metadataCachesSnapshot, apiType);
+                                ApiType apiType,
+                                ClientTelemetryConfig clientTelemetryConfig) {
+        this(
+                serviceEndpoint,
+                masterKeyOrResourceToken,
+                connectionPolicy,
+                consistencyLevel,
+                configs,
+                credential,
+                tokenCredential,
+                sessionCapturingOverrideEnabled,
+                connectionSharingAcrossClientsEnabled,
+                contentResponseOnWriteEnabled,
+                metadataCachesSnapshot,
+                apiType,
+                clientTelemetryConfig);
 
         if (permissionFeed != null && permissionFeed.size() > 0) {
             this.resourceTokensMap = new HashMap<>();
@@ -285,7 +327,8 @@ private RxDocumentClientImpl(URI serviceEndpoint,
                          boolean connectionSharingAcrossClientsEnabled,
                          boolean contentResponseOnWriteEnabled,
                          CosmosClientMetadataCachesSnapshot metadataCachesSnapshot,
-                         ApiType apiType) {
+                         ApiType apiType,
+                         ClientTelemetryConfig clientTelemetryConfig) {
 
         activeClientsCnt.incrementAndGet();
         this.clientId = clientIdGenerator.incrementAndGet();
@@ -372,6 +415,7 @@ private RxDocumentClientImpl(URI serviceEndpoint,
             CpuMemoryMonitor.register(this);
             this.queryPlanCache = new ConcurrentHashMap<>();
             this.apiType = apiType;
+            this.clientTelemetryConfig = clientTelemetryConfig;
         } catch (RuntimeException e) {
             logger.error("unexpected failure in initializing client.", e);
             close();
@@ -457,10 +501,20 @@ public void init(CosmosClientMetadataCachesSnapshot metadataCachesSnapshot, Func
                 collectionCache);
 
             updateGatewayProxy();
-            clientTelemetry = new ClientTelemetry(this, null, UUID.randomUUID().toString(),
-                ManagementFactory.getRuntimeMXBean().getName(), userAgentContainer.getUserAgent(),
-                connectionPolicy.getConnectionMode(), globalEndpointManager.getLatestDatabaseAccount().getId(),
-                null, null, this.reactorHttpClient, connectionPolicy.isClientTelemetryEnabled(), this, this.connectionPolicy.getPreferredRegions());
+            clientTelemetry = new ClientTelemetry(
+                    this,
+                    null,
+                    UUID.randomUUID().toString(),
+                    ManagementFactory.getRuntimeMXBean().getName(),
+                    userAgentContainer.getUserAgent(),
+                    connectionPolicy.getConnectionMode(),
+                    globalEndpointManager.getLatestDatabaseAccount().getId(),
+                    null,
+                    null,
+                    this.configs,
+                    this.clientTelemetryConfig,
+                    this,
+                    this.connectionPolicy.getPreferredRegions());
             clientTelemetry.init();
             if (this.connectionPolicy.getConnectionMode() == ConnectionMode.GATEWAY) {
                 this.storeModel = this.gatewayProxy;
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/TracerProvider.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/TracerProvider.java
index faa7481869515..6faf25f497467 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/TracerProvider.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/TracerProvider.java
@@ -321,14 +321,14 @@ private  Mono publisherWithClientTelemetry(Mono resultPublisher,
         Mono tracerMono = traceEnabledPublisher(resultPublisher, context, spanName, databaseId, endpoint, statusCodeFunc, diagnosticFunc, thresholdForDiagnosticsOnTracer);
         return tracerMono
             .doOnSuccess(response -> {
-                if (Configs.isClientTelemetryEnabled(BridgeInternal.isClientTelemetryEnabled(client)) && response instanceof CosmosItemResponse) {
+                if (BridgeInternal.isClientTelemetryEnabled(client) && response instanceof CosmosItemResponse) {
                     @SuppressWarnings("unchecked")
                     CosmosItemResponse itemResponse = (CosmosItemResponse) response;
                     fillClientTelemetry(client, itemResponse.getDiagnostics(), itemResponse.getStatusCode(),
                         ModelBridgeInternal.getPayloadLength(itemResponse), containerId,
                         databaseId, operationType, resourceType, consistencyLevel,
                         (float) itemResponse.getRequestCharge());
-                } else if (Configs.isClientTelemetryEnabled(BridgeInternal.isClientTelemetryEnabled(client)) && response instanceof CosmosBatchResponse) {
+                } else if (BridgeInternal.isClientTelemetryEnabled(client) && response instanceof CosmosBatchResponse) {
                     @SuppressWarnings("unchecked")
                     CosmosBatchResponse cosmosBatchResponse = (CosmosBatchResponse) response;
                     fillClientTelemetry(client, cosmosBatchResponse.getDiagnostics(), cosmosBatchResponse.getStatusCode(),
@@ -337,7 +337,7 @@ private  Mono publisherWithClientTelemetry(Mono resultPublisher,
                         (float) cosmosBatchResponse.getRequestCharge());
                 }
             }).doOnError(throwable -> {
-                if (Configs.isClientTelemetryEnabled(BridgeInternal.isClientTelemetryEnabled(client)) && throwable instanceof CosmosException) {
+                if (BridgeInternal.isClientTelemetryEnabled(client) && throwable instanceof CosmosException) {
                     CosmosException cosmosException = (CosmosException) throwable;
                     fillClientTelemetry(client, cosmosException.getDiagnostics(), cosmosException.getStatusCode(),
                         null, containerId,
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java
index 4f96efa200271..3840415ced80e 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java
@@ -5,6 +5,7 @@
 import com.azure.cosmos.BridgeInternal;
 import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.implementation.AuthorizationTokenType;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.Constants;
 import com.azure.cosmos.implementation.CosmosDaemonThreadFactory;
@@ -20,6 +21,7 @@
 import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
 import com.azure.cosmos.implementation.cpu.CpuMemoryMonitor;
 import com.azure.cosmos.implementation.http.HttpClient;
+import com.azure.cosmos.implementation.http.HttpClientConfig;
 import com.azure.cosmos.implementation.http.HttpHeaders;
 import com.azure.cosmos.implementation.http.HttpRequest;
 import com.azure.cosmos.implementation.http.HttpResponse;
@@ -50,6 +52,8 @@
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
+import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
+
 public class ClientTelemetry {
     public final static int ONE_KB_TO_BYTES = 1024;
     public final static int REQUEST_LATENCY_MAX_MILLI_SEC = 300000;
@@ -83,13 +87,14 @@ public class ClientTelemetry {
     private final static AtomicReference azureVmMetaDataSingleton =
         new AtomicReference<>(null);
     private ClientTelemetryInfo clientTelemetryInfo;
+    private final Configs configs;
+    private final ClientTelemetryConfig clientTelemetryConfig;
     private final HttpClient httpClient;
     private final ScheduledThreadPoolExecutor scheduledExecutorService = new ScheduledThreadPoolExecutor(1,
         new CosmosDaemonThreadFactory("ClientTelemetry-" + instanceCount.incrementAndGet()));
     private final Scheduler scheduler = Schedulers.fromExecutor(scheduledExecutorService);
     private static final Logger logger = LoggerFactory.getLogger(ClientTelemetry.class);
     private volatile boolean isClosed;
-    private volatile boolean isClientTelemetryEnabled;
     private static String AZURE_VM_METADATA = "http://169.254.169.254:80/metadata/instance?api-version=2020-06-01";
 
     private static final double PERCENTILE_50 = 50.0;
@@ -111,8 +116,8 @@ public ClientTelemetry(DiagnosticsClientContext diagnosticsClientContext,
                            String globalDatabaseAccountName,
                            String applicationRegion,
                            String hostEnvInfo,
-                           HttpClient httpClient,
-                           boolean isClientTelemetryEnabled,
+                           Configs configs,
+                           ClientTelemetryConfig clientTelemetryConfig,
                            IAuthorizationTokenProvider tokenProvider,
                            List preferredRegions
     ) {
@@ -127,9 +132,13 @@ public ClientTelemetry(DiagnosticsClientContext diagnosticsClientContext,
             hostEnvInfo,
             acceleratedNetworking,
             preferredRegions);
+
+        checkNotNull(clientTelemetryConfig, "Argument 'clientTelemetryConfig' cannot be null");
+
         this.isClosed = false;
-        this.httpClient = httpClient;
-        this.isClientTelemetryEnabled = isClientTelemetryEnabled;
+        this.configs = configs;
+        this.clientTelemetryConfig = clientTelemetryConfig;
+        this.httpClient = httpClient();
         this.clientTelemetrySchedulingSec = Configs.getClientTelemetrySchedulingInSec();
         this.tokenProvider = tokenProvider;
         this.globalDatabaseAccountName = globalDatabaseAccountName;
@@ -174,7 +183,7 @@ public static void recordValue(ConcurrentDoubleHistogram doubleHistogram, double
     }
 
     public boolean isClientTelemetryEnabled() {
-        return isClientTelemetryEnabled;
+        return this.clientTelemetryConfig.isClientTelemetryEnabled();
     }
 
     public void init() {
@@ -188,6 +197,16 @@ public void close() {
         logger.debug("GlobalEndpointManager closed.");
     }
 
+    private HttpClient httpClient() {
+        HttpClientConfig httpClientConfig = new HttpClientConfig(this.configs)
+                .withMaxIdleConnectionTimeout(this.clientTelemetryConfig.getIdleHttpConnectionTimeout())
+                .withPoolSize(this.clientTelemetryConfig.getMaxConnectionPoolSize())
+                .withProxy(this.clientTelemetryConfig.getProxy())
+                .withNetworkRequestTimeout(this.clientTelemetryConfig.getHttpNetworkRequestTimeout());
+
+        return HttpClient.createFixed(httpClientConfig);
+    }
+
     private Mono sendClientTelemetry() {
         return Mono.delay(Duration.ofSeconds(clientTelemetrySchedulingSec), CosmosSchedulers.COSMOS_PARALLEL)
             .flatMap(t -> {
@@ -196,7 +215,7 @@ private Mono sendClientTelemetry() {
                     return Mono.empty();
                 }
 
-                if (!Configs.isClientTelemetryEnabled(this.isClientTelemetryEnabled)) {
+                if (!this.isClientTelemetryEnabled()) {
                     logger.trace("client telemetry not enabled");
                     return Mono.empty();
                 }
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdChannelAcquisitionTimeline.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdChannelAcquisitionTimeline.java
index 7e644a1025d7d..3f41cc76ecbc8 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdChannelAcquisitionTimeline.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdChannelAcquisitionTimeline.java
@@ -3,7 +3,6 @@
 
 package com.azure.cosmos.implementation.directconnectivity.rntbd;
 
-import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.clienttelemetry.ClientTelemetry;
 import com.azure.cosmos.implementation.clienttelemetry.ReportPayload;
 import org.HdrHistogram.ConcurrentDoubleHistogram;
@@ -60,7 +59,7 @@ public static RntbdPollChannelEvent startNewPollEvent(
     private void addNewEvent(RntbdChannelAcquisitionEvent event, ClientTelemetry clientTelemetry) {
         if (this.currentEvent != null) {
             this.currentEvent.complete(event.getCreatedTime());
-            if(clientTelemetry!= null && Configs.isClientTelemetryEnabled(clientTelemetry.isClientTelemetryEnabled())) {
+            if(clientTelemetry!= null && clientTelemetry.isClientTelemetryEnabled()) {
                 if (event.getEventType().equals(RntbdChannelAcquisitionEventType.ATTEMPT_TO_CREATE_NEW_CHANNEL_COMPLETE)) {
                     ReportPayload reportPayload = new ReportPayload(ClientTelemetry.TCP_NEW_CHANNEL_LATENCY_NAME,
                         ClientTelemetry.TCP_NEW_CHANNEL_LATENCY_UNIT);
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/util/CosmosPagedFlux.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/util/CosmosPagedFlux.java
index 115da96c6ea89..081ff56f744a2 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/util/CosmosPagedFlux.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/util/CosmosPagedFlux.java
@@ -188,7 +188,7 @@ private Flux> byPage(CosmosPagedFluxOptions pagedFluxOptions, Co
                     case ON_ERROR:
                         Throwable throwable = signal.getThrowable();
                         if (pagedFluxOptions.getCosmosAsyncClient() != null &&
-                            Configs.isClientTelemetryEnabled(BridgeInternal.isClientTelemetryEnabled(pagedFluxOptions.getCosmosAsyncClient())) &&
+                            BridgeInternal.isClientTelemetryEnabled(pagedFluxOptions.getCosmosAsyncClient()) &&
                             throwable instanceof CosmosException) {
                             CosmosException cosmosException = (CosmosException) throwable;
                             // not adding diagnostics on trace event for exception as this information is already there as
@@ -232,7 +232,7 @@ private Flux> byPage(CosmosPagedFluxOptions pagedFluxOptions, Co
                         }
 
                         if (pagedFluxOptions.getCosmosAsyncClient() != null &&
-                            Configs.isClientTelemetryEnabled(BridgeInternal.isClientTelemetryEnabled(pagedFluxOptions.getCosmosAsyncClient()))) {
+                            BridgeInternal.isClientTelemetryEnabled(pagedFluxOptions.getCosmosAsyncClient())) {
                             if (this.cosmosDiagnosticsAccessor.isDiagnosticsCapturedInPagedFlux(feedResponse.getCosmosDiagnostics()).compareAndSet(false, true)) {
                                 fillClientTelemetry(pagedFluxOptions.getCosmosAsyncClient(), HttpConstants.StatusCodes.OK,
                                     pagedFluxOptions.getContainerId(),
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
index 2ad95810cef08..6ff73602598ed 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
@@ -2,6 +2,7 @@
 // Licensed under the MIT License.
 package com.azure.cosmos;
 
+import com.azure.core.http.ProxyOptions;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.HttpConstants;
 import com.azure.cosmos.implementation.InternalObjectNode;
@@ -19,6 +20,7 @@
 import com.azure.cosmos.models.FeedResponse;
 import com.azure.cosmos.models.PartitionKey;
 import com.azure.cosmos.rx.TestSuiteBase;
+import com.azure.cosmos.rx.proxy.HttpProxyServer;
 import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 import org.testng.annotations.AfterClass;
@@ -30,6 +32,7 @@
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -39,9 +42,10 @@
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class ClientTelemetryTest extends TestSuiteBase {
-    CosmosClient gatewayClient = null;
-    CosmosClient directClient = null;
-    CosmosClient telemetryDisabledClient = null;
+    private CosmosClient gatewayClient = null;
+    private CosmosClient directClient = null;
+    private CosmosClient telemetryDisabledClient = null;
+    private HttpProxyServer httpProxyServer;
 
     @BeforeClass(groups = {"emulator"})
     public void beforeClass() {
@@ -72,6 +76,9 @@ public void beforeClass() {
             .contentResponseOnWriteEnabled(true)
             .directMode()
             .buildClient();
+
+        httpProxyServer = new HttpProxyServer();
+        httpProxyServer.start();
     }
 
     @AfterClass(groups = {"emulator"})
@@ -87,6 +94,10 @@ public void afterClass() {
         if (this.telemetryDisabledClient != null) {
             this.telemetryDisabledClient.close();
         }
+
+        if (this.httpProxyServer != null) {
+            this.httpProxyServer.shutDown();
+        }
     }
 
     @DataProvider(name = "clients")
@@ -97,6 +108,15 @@ public Object[][] clients() {
         };
     }
 
+
+    @DataProvider(name = "useProxy")
+    public static Object[][] useProxy() {
+        return new Object[][]{
+                { true },
+                { false }
+        };
+    }
+
     @Test(groups = {"emulator"}, dataProvider = "clients", timeOut = TIMEOUT)
     public void operationsList(CosmosClient cosmosClient) throws Exception {
         CosmosAsyncContainer asyncContainer = getSharedMultiPartitionCosmosContainer(cosmosClient.asyncClient());
@@ -237,8 +257,8 @@ public void clientTelemetryScheduling() {
     }
 
     @SuppressWarnings("unchecked")
-    @Test(groups = {"non-emulator"}, timeOut = TIMEOUT)
-    public void clientTelemetryWithStageJunoEndpoint() throws InterruptedException, NoSuchFieldException,
+    @Test(groups = {"non-emulator"}, dataProvider = "useProxy", timeOut = TIMEOUT)
+    public void clientTelemetryWithStageJunoEndpoint(boolean useProxy) throws InterruptedException, NoSuchFieldException,
         IllegalAccessException {
         CosmosClient cosmosClient = null;
         String databaseId = UUID.randomUUID().toString();
@@ -249,11 +269,21 @@ public void clientTelemetryWithStageJunoEndpoint() throws InterruptedException,
             String host = credentialList[0].substring("AccountEndpoint=".length());
             String key = credentialList[1].substring("AccountKey=".length());
 
-            cosmosClient = new CosmosClientBuilder()
+            CosmosClientBuilder clientBuilder = new CosmosClientBuilder()
                 .endpoint(host)
                 .key(key)
-                .clientTelemetryEnabled(true)
-                .buildClient();
+                .clientTelemetryEnabled(true);
+
+            if (useProxy) {
+                ClientTelemetryConnectionConfig connectionConfig = ClientTelemetryConnectionConfig.getDefaultConfig();
+                connectionConfig.setProxy(
+                        new ProxyOptions(
+                                ProxyOptions.Type.HTTP,
+                                new InetSocketAddress(this.httpProxyServer.getHost(), this.httpProxyServer.getPort())));
+                clientBuilder.clientTelemetryConnectionConfig(connectionConfig);
+            }
+            cosmosClient = clientBuilder.buildClient();
+
             String containerId = UUID.randomUUID().toString();
             cosmosClient.createDatabase(databaseId);
 
@@ -270,9 +300,13 @@ public void clientTelemetryWithStageJunoEndpoint() throws InterruptedException,
             // in test env we add the env property with cosmos-client-telemetry-endpoint variable in tests.yml,
             // which gets its value from key vault TestSecrets-Cosmos
 
-            logger.info("clientTelemetryWithStageJunoEndpoint client telemetry endpoint {}",  System.getProperty("COSMOS.CLIENT_TELEMETRY_ENDPOINT").split("/")[2]);
-            logger.info("clientTelemetryWithStageJunoEndpoint cosmos account name  {}",
-                ReflectionUtils.getGlobalEndpointManager((RxDocumentClientImpl) CosmosBridgeInternal.getAsyncDocumentClient(cosmosClient)).getLatestDatabaseAccount().getResourceId());
+            logger.info(
+                    "clientTelemetryWithStageJunoEndpoint client telemetry endpoint {}",
+                    System.getProperty("COSMOS.CLIENT_TELEMETRY_ENDPOINT").split("/")[2]);
+            logger.info(
+                    "clientTelemetryWithStageJunoEndpoint cosmos account name  {}",
+                    ReflectionUtils.getGlobalEndpointManager(
+                            (RxDocumentClientImpl) CosmosBridgeInternal.getAsyncDocumentClient(cosmosClient)).getLatestDatabaseAccount().getResourceId());
 
 
             HttpClient httpClient = ReflectionUtils.getHttpClient(clientTelemetry);
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java
index aed6aa0e81ca1..8651442f3d188 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java
@@ -56,7 +56,8 @@ public CosmosAsyncClient buildAsyncClient() {
                 this.configs(),
                 this.getCredential(),
                 this.isContentResponseOnWriteEnabled(),
-                this.apiType());
+                this.apiType(),
+                this.getClientTelemetryConfig());
         } catch (URISyntaxException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
index 7859f6ad8b8f8..c397c73eac5b1 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
@@ -5,6 +5,7 @@
 
 import com.azure.core.http.ProxyOptions;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.TestConfigurations;
 import com.azure.cosmos.implementation.directconnectivity.ReflectionUtils;
@@ -203,6 +204,34 @@ public void gatewayConnectionConfigWithNetworkRequestTimeout() {
         assertThat(gatewayConnectionConfig.getNetworkRequestTimeout().equals(networkRequestTimeout));
     }
 
+    @Test(groups = { "unit" })
+    public void buildClientTelemetryConfig_withClientTelemetryConnectionConfig() throws Exception {
+        ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("127.0.0.0", 8080));
+        DirectConnectionConfig directConnectionConfig = DirectConnectionConfig.getDefaultConfig();
+        GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
+
+        ClientTelemetryConnectionConfig clientTelemetryConnectionConfig = ClientTelemetryConnectionConfig.getDefaultConfig();
+        clientTelemetryConnectionConfig.setProxy(proxyOptions);
+
+        CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder()
+                .endpoint(TestConfigurations.HOST)
+                .key(TestConfigurations.MASTER_KEY)
+                .directMode(directConnectionConfig, gatewayConnectionConfig)
+                .clientTelemetryEnabled(true)
+                .clientTelemetryConnectionConfig(clientTelemetryConnectionConfig);
+
+        ReflectionUtils.buildConnectionPolicy(cosmosClientBuilder);
+        ReflectionUtils.buildClientTelemetryConfig(cosmosClientBuilder);
+
+        ConnectionPolicy connectionPolicy = ReflectionUtils.getConnectionPolicy(cosmosClientBuilder);
+        assertThat(connectionPolicy.getConnectionMode()).isEqualTo(ConnectionMode.DIRECT);
+        validateDirectAndGatewayConnectionConfig(connectionPolicy, cosmosClientBuilder, directConnectionConfig, gatewayConnectionConfig);
+
+        ClientTelemetryConfig clientTelemetryConfig = ReflectionUtils.getClientTelemetryConfig(cosmosClientBuilder);
+        assertThat(clientTelemetryConfig.isClientTelemetryEnabled()).isTrue();
+        this.validateClientTelemetryConfig(clientTelemetryConfig, clientTelemetryConnectionConfig);
+    }
+
     private void validateDirectAndGatewayConnectionConfig(ConnectionPolicy connectionPolicy, CosmosClientBuilder cosmosClientBuilder,
                                                           DirectConnectionConfig directConnectionConfig, GatewayConnectionConfig gatewayConnectionConfig) {
         validateCommonConnectionConfig(connectionPolicy, cosmosClientBuilder);
@@ -246,4 +275,14 @@ private void validateDirectConfig(ConnectionPolicy connectionPolicy, DirectConne
         assertThat(connectionPolicy.getMaxConnectionsPerEndpoint()).isEqualTo(directConnectionConfig.getMaxConnectionsPerEndpoint());
         assertThat(connectionPolicy.getMaxRequestsPerConnection()).isEqualTo(directConnectionConfig.getMaxRequestsPerConnection());
     }
+
+    private void validateClientTelemetryConfig(ClientTelemetryConfig clientTelemetryConfig, ClientTelemetryConnectionConfig clientTelemetryConnectionConfig) {
+        assertThat(clientTelemetryConfig).isNotNull();
+        assertThat(clientTelemetryConnectionConfig).isNotNull();
+
+        assertThat(clientTelemetryConfig.getMaxConnectionPoolSize()).isEqualTo(clientTelemetryConnectionConfig.getMaxConnectionPoolSize());
+        assertThat(clientTelemetryConfig.getIdleHttpConnectionTimeout()).isEqualTo(clientTelemetryConnectionConfig.getIdleConnectionTimeout());
+        assertThat(clientTelemetryConfig.getHttpNetworkRequestTimeout()).isEqualTo(clientTelemetryConnectionConfig.getNetworkRequestTimeout());
+        assertThat(clientTelemetryConfig.getProxy()).isEqualTo(clientTelemetryConfig.getProxy());
+    }
 }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java
index f5db5f8325250..d7150054357dc 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RxDocumentClientUnderTest.java
@@ -38,9 +38,22 @@ public RxDocumentClientUnderTest(URI serviceEndpoint,
                                      Configs configs,
                                      AzureKeyCredential credential,
                                      boolean contentResponseOnWriteEnabled,
-                                     ApiType apiType) {
-        super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential, null, false,
-              false, contentResponseOnWriteEnabled, null, apiType);
+                                     ApiType apiType,
+                                     ClientTelemetryConfig clientTelemetryConfig) {
+        super(
+                serviceEndpoint,
+                masterKey,
+                connectionPolicy,
+                consistencyLevel,
+                configs,
+                credential,
+                null,
+                false,
+                false,
+                contentResponseOnWriteEnabled,
+                null,
+                apiType,
+                clientTelemetryConfig);
         init(null, null);
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java
index 705b1f255037e..0cd2b37d9ae2c 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientBuilder.java
@@ -1,5 +1,6 @@
 // Copyright (c) Microsoft Corporation. All rights reserved.
 // Licensed under the MIT License.
+
 package com.azure.cosmos.implementation;
 
 public class SpyClientBuilder extends AsyncDocumentClient.Builder {
@@ -13,6 +14,7 @@ public SpyClientBuilder(AsyncDocumentClient.Builder builder) {
         super.serviceEndpoint = builder.serviceEndpoint;
         super.credential = builder.credential;
         super.contentResponseOnWriteEnabled = builder.contentResponseOnWriteEnabled;
+        super.clientTelemetryConfig = builder.clientTelemetryConfig;
     }
 
     public SpyClientUnderTestFactory.ClientUnderTest build() {
@@ -23,7 +25,8 @@ public SpyClientUnderTestFactory.ClientUnderTest build() {
             desiredConsistencyLevel,
             configs,
             credential,
-            contentResponseOnWriteEnabled);
+            contentResponseOnWriteEnabled,
+            clientTelemetryConfig);
     }
 
     public SpyClientUnderTestFactory.ClientWithGatewaySpy buildWithGatewaySpy() {
@@ -34,7 +37,8 @@ public SpyClientUnderTestFactory.ClientWithGatewaySpy buildWithGatewaySpy() {
             desiredConsistencyLevel,
             configs,
             credential,
-            contentResponseOnWriteEnabled);
+            contentResponseOnWriteEnabled,
+            clientTelemetryConfig);
     }
 
     public SpyClientUnderTestFactory.DirectHttpsClientUnderTest buildWithDirectHttps() {
@@ -44,6 +48,7 @@ public SpyClientUnderTestFactory.DirectHttpsClientUnderTest buildWithDirectHttps
             connectionPolicy,
             desiredConsistencyLevel,
             credential,
-            contentResponseOnWriteEnabled);
+            contentResponseOnWriteEnabled,
+            clientTelemetryConfig);
     }
 }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java
index 7661310348923..16cb320af2447 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java
@@ -3,6 +3,7 @@
 package com.azure.cosmos.implementation;
 
 import com.azure.core.credential.AzureKeyCredential;
+import com.azure.cosmos.ClientTelemetryConnectionConfig;
 import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.implementation.directconnectivity.Protocol;
@@ -34,11 +35,30 @@ public class SpyClientUnderTestFactory {
 
     public static abstract class SpyBaseClass extends RxDocumentClientImpl {
 
-        public SpyBaseClass(URI serviceEndpoint, String masterKeyOrResourceToken, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs, AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) {
-
-            super(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs, credential,
-                null, false, false,
-                contentResponseOnWriteEnabled, null, null);
+        public SpyBaseClass(
+                URI serviceEndpoint,
+                String masterKeyOrResourceToken,
+                ConnectionPolicy connectionPolicy,
+                ConsistencyLevel consistencyLevel,
+                Configs configs,
+                AzureKeyCredential credential,
+                boolean contentResponseOnWriteEnabled,
+                ClientTelemetryConfig clientTelemetryConfig) {
+
+            super(
+                    serviceEndpoint,
+                    masterKeyOrResourceToken,
+                    connectionPolicy,
+                    consistencyLevel,
+                    configs,
+                    credential,
+                    null,
+                    false,
+                    false,
+                    contentResponseOnWriteEnabled,
+                    null,
+                    null,
+                    clientTelemetryConfig);
         }
 
         public abstract List getCapturedRequests();
@@ -60,11 +80,24 @@ public static class ClientWithGatewaySpy extends SpyBaseClass requests;
 
 
-        ClientWithGatewaySpy(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy,
-                             ConsistencyLevel consistencyLevel, Configs configs, AzureKeyCredential credential,
-                             boolean contentResponseOnWriteEnabled) {
-            super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential,
-                contentResponseOnWriteEnabled);
+        ClientWithGatewaySpy(
+                URI serviceEndpoint,
+                String masterKey,
+                ConnectionPolicy connectionPolicy,
+                ConsistencyLevel consistencyLevel,
+                Configs configs,
+                AzureKeyCredential credential,
+                boolean contentResponseOnWriteEnabled,
+                ClientTelemetryConfig clientTelemetryConfig) {
+            super(
+                    serviceEndpoint,
+                    masterKey,
+                    connectionPolicy,
+                    consistencyLevel,
+                    configs,
+                    credential,
+                    contentResponseOnWriteEnabled,
+                    clientTelemetryConfig);
             init(null, null);
             updateOrigRxGatewayStoreModel();
         }
@@ -136,11 +169,24 @@ public static class ClientUnderTest extends SpyBaseClass {
             Collections.synchronizedList(new ArrayList<>());
 
 
-        ClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy,
-                        ConsistencyLevel consistencyLevel, Configs configs, AzureKeyCredential credential,
-                        boolean contentResponseOnWriteEnabled) {
-            super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs, credential,
-                contentResponseOnWriteEnabled);
+        ClientUnderTest(
+                URI serviceEndpoint,
+                String masterKey,
+                ConnectionPolicy connectionPolicy,
+                ConsistencyLevel consistencyLevel,
+                Configs configs,
+                AzureKeyCredential credential,
+                boolean contentResponseOnWriteEnabled,
+                ClientTelemetryConfig clientTelemetryConfig) {
+            super(
+                    serviceEndpoint,
+                    masterKey,
+                    connectionPolicy,
+                    consistencyLevel,
+                    configs,
+                    credential,
+                    contentResponseOnWriteEnabled,
+                    clientTelemetryConfig);
             init(null, this::initHttpRequestCapture);
         }
 
@@ -212,11 +258,23 @@ public static class DirectHttpsClientUnderTest extends SpyBaseClass
         List>> requestsResponsePairs =
             Collections.synchronizedList(new ArrayList<>());
 
-        DirectHttpsClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy,
-                                   ConsistencyLevel consistencyLevel, AzureKeyCredential credential,
-                                   boolean contentResponseOnWriteEnabled) {
-            super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, createConfigsSpy(Protocol.HTTPS),
-                credential, contentResponseOnWriteEnabled);
+        DirectHttpsClientUnderTest(
+                URI serviceEndpoint,
+                String masterKey,
+                ConnectionPolicy connectionPolicy,
+                ConsistencyLevel consistencyLevel,
+                AzureKeyCredential credential,
+                boolean contentResponseOnWriteEnabled,
+                ClientTelemetryConfig clientTelemetryConfig) {
+            super(
+                    serviceEndpoint,
+                    masterKey,
+                    connectionPolicy,
+                    consistencyLevel,
+                    createConfigsSpy(Protocol.HTTPS),
+                    credential,
+                    contentResponseOnWriteEnabled,
+                    clientTelemetryConfig);
             assert connectionPolicy.getConnectionMode() == ConnectionMode.DIRECT;
             init(null, null);
 
@@ -278,9 +336,17 @@ public static ClientWithGatewaySpy createClientWithGatewaySpy(URI serviceEndpoin
                                                                   ConsistencyLevel consistencyLevel,
                                                                   Configs configs,
                                                                   AzureKeyCredential credential,
-                                                                  boolean contentResponseOnWriteEnabled) {
-        return new ClientWithGatewaySpy(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs,
-            credential, contentResponseOnWriteEnabled);
+                                                                  boolean contentResponseOnWriteEnabled,
+                                                                  ClientTelemetryConfig clientTelemetryConfig) {
+        return new ClientWithGatewaySpy(
+                serviceEndpoint,
+                masterKey,
+                connectionPolicy,
+                consistencyLevel,
+                configs,
+                credential,
+                contentResponseOnWriteEnabled,
+                clientTelemetryConfig);
     }
 
     public static ClientUnderTest createClientUnderTest(AsyncDocumentClient.Builder builder) {
@@ -297,15 +363,34 @@ public static ClientUnderTest createClientUnderTest(URI serviceEndpoint,
                                                         ConsistencyLevel consistencyLevel,
                                                         Configs configs,
                                                         AzureKeyCredential credential,
-                                                        boolean contentResponseOnWriteEnabled) {
-        return new ClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs,
-            credential, contentResponseOnWriteEnabled);
+                                                        boolean contentResponseOnWriteEnabled,
+                                                        ClientTelemetryConfig clientTelemetryConfig) {
+        return new ClientUnderTest(
+                serviceEndpoint,
+                masterKey,
+                connectionPolicy,
+                consistencyLevel,
+                configs,
+                credential,
+                contentResponseOnWriteEnabled,
+                clientTelemetryConfig);
     }
 
     public static DirectHttpsClientUnderTest createDirectHttpsClientUnderTest(
-        URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel,
-        AzureKeyCredential credential, boolean contentResponseOnWriteEnabled) {
-        return new DirectHttpsClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel,
-            credential, contentResponseOnWriteEnabled);
+        URI serviceEndpoint,
+        String masterKey,
+        ConnectionPolicy connectionPolicy,
+        ConsistencyLevel consistencyLevel,
+        AzureKeyCredential credential,
+        boolean contentResponseOnWriteEnabled,
+        ClientTelemetryConfig clientTelemetryConfig) {
+        return new DirectHttpsClientUnderTest(
+                serviceEndpoint,
+                masterKey,
+                connectionPolicy,
+                consistencyLevel,
+                credential,
+                contentResponseOnWriteEnabled,
+                clientTelemetryConfig);
     }
 }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
index 10dd7eaa7410a..0d6063f874cde 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
@@ -6,9 +6,10 @@
 import com.azure.core.credential.AccessToken;
 import com.azure.core.credential.TokenCredential;
 import com.azure.core.credential.TokenRequestContext;
-import com.azure.cosmos.implementation.ApiType;
+import com.azure.cosmos.ClientTelemetryConnectionConfig;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
 import com.azure.cosmos.implementation.AuthorizationTokenType;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.Document;
 import com.azure.cosmos.implementation.HttpConstants;
@@ -26,6 +27,7 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.time.Duration;
 import java.time.OffsetDateTime;
 import java.time.ZonedDateTime;
 import java.util.Map;
@@ -159,8 +161,12 @@ public void barrierDocumentReadRidBasedRequest() {
     public void barrierWithAadAuthorizationTokenProviderType() throws URISyntaxException {
 
         TokenCredential tokenCredential = new AadSimpleTokenCredential(TestConfigurations.MASTER_KEY);
-
-        IAuthorizationTokenProvider authTokenProvider = new RxDocumentClientImpl(new URI(TestConfigurations.HOST),
+        ClientTelemetryConfig clientTelemetryConfig = new ClientTelemetryConfig(
+                false,
+                ClientTelemetryConnectionConfig.getDefaultConfig()
+        );
+        IAuthorizationTokenProvider authTokenProvider = new RxDocumentClientImpl(
+                new URI(TestConfigurations.HOST),
                 null,
                 null,
                 null,
@@ -173,7 +179,8 @@ public void barrierWithAadAuthorizationTokenProviderType() throws URISyntaxExcep
                 false,
                 false,
                 null,
-                null);
+                null,
+                clientTelemetryConfig);
 
         ResourceType resourceType = ResourceType.DocumentCollection;
         OperationType operationType = OperationType.Read;
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java
index 4bd58465c3d95..c864bac80fb9c 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java
@@ -11,6 +11,7 @@
 import com.azure.cosmos.implementation.ApiType;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
 import com.azure.cosmos.implementation.ClientSideRequestStatistics;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.DocumentCollection;
 import com.azure.cosmos.implementation.GlobalEndpointManager;
@@ -177,10 +178,18 @@ public static ConnectionPolicy getConnectionPolicy(CosmosClientBuilder cosmosCli
         return get(ConnectionPolicy.class, cosmosClientBuilder, "connectionPolicy");
     }
 
+    public static ClientTelemetryConfig getClientTelemetryConfig(CosmosClientBuilder cosmosClientBuilder){
+        return get(ClientTelemetryConfig.class, cosmosClientBuilder, "clientTelemetryConfig");
+    }
+
     public static void buildConnectionPolicy(CosmosClientBuilder cosmosClientBuilder) {
         invokeMethod(CosmosClientBuilder.class, cosmosClientBuilder, "buildConnectionPolicy");
     }
 
+    public static void buildClientTelemetryConfig(CosmosClientBuilder cosmosClientBuilder) {
+        invokeMethod(CosmosClientBuilder.class, cosmosClientBuilder, "buildClientTelemetryConfig");
+    }
+
     public static UserAgentContainer getUserAgentContainer(RxDocumentClientImpl rxDocumentClient) {
         return get(UserAgentContainer.class, rxDocumentClient, "userAgentContainer");
     }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/proxy/HttpProxyServer.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/proxy/HttpProxyServer.java
index 763859125b6d1..b518db313ee20 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/proxy/HttpProxyServer.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/proxy/HttpProxyServer.java
@@ -48,4 +48,12 @@ public void  shutDown() {
             bossGroup.shutdownGracefully();
         }
     }
+
+    public int getPort() {
+        return port;
+    }
+
+    public String getHost() {
+        return "localHost";
+    }
 }

From 7aa799c2aa6d5e0e3f2a4448605cbba6b2f6b0ef Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Tue, 24 May 2022 18:38:55 -0700
Subject: [PATCH 03/12] resolve feedback

---
 .../ClientTelemetryConnectionConfig.java      | 145 ------------------
 .../com/azure/cosmos/CosmosClientBuilder.java |  30 +---
 .../implementation/ClientTelemetryConfig.java |  77 ++++++++--
 .../azure/cosmos/implementation/Configs.java  |  14 +-
 .../com/azure/cosmos/ClientTelemetryTest.java |  37 ++---
 .../azure/cosmos/ConnectionConfigTest.java    |  27 ++--
 .../SpyClientUnderTestFactory.java            |   1 -
 .../BarrierRequestHelperTest.java             |   7 +-
 8 files changed, 103 insertions(+), 235 deletions(-)
 delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java

diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java
deleted file mode 100644
index 8d2cc3d2fa411..0000000000000
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ClientTelemetryConnectionConfig.java
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.cosmos;
-
-import com.azure.core.http.ProxyOptions;
-
-import java.time.Duration;
-
-import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkArgument;
-import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
-
-/**
- * Represents the client telemetry config.
- */
-public class ClientTelemetryConnectionConfig {
-    private static final Duration MIN_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(60);
-    private static final Duration DEFAULT_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(60);
-    private static final Duration DEFAULT_IDLE_CONNECTION_TIMEOUT = Duration.ofSeconds(60);
-    private static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 1000;
-
-    private Duration networkRequestTimeout;
-    private int maxConnectionPoolSize;
-    private Duration idleConnectionTimeout;
-    private ProxyOptions proxy;
-
-    public ClientTelemetryConnectionConfig() {
-        this.idleConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
-        this.maxConnectionPoolSize = DEFAULT_MAX_CONNECTION_POOL_SIZE;
-        this.networkRequestTimeout = DEFAULT_NETWORK_REQUEST_TIMEOUT;
-    }
-
-    public static ClientTelemetryConnectionConfig getDefaultConfig() {
-        return new ClientTelemetryConnectionConfig();
-    }
-
-    /**
-     * Gets the network request timeout interval (time to wait for response from network peer).
-     * The default is 60 seconds.
-     *
-     * @return the network request timeout duration.
-     */
-    public Duration getNetworkRequestTimeout() {
-        return this.networkRequestTimeout;
-    }
-
-    /**
-     * Sets the network request timeout interval (time to wait for response from network peer).
-     * The default is 60 seconds.
-     *
-     * @param networkRequestTimeout the network request timeout duration.
-     * @return the {@link ClientTelemetryConnectionConfig}.
-     */
-    ClientTelemetryConnectionConfig setNetworkRequestTimeout(Duration networkRequestTimeout) {
-        checkNotNull(networkRequestTimeout, "NetworkRequestTimeout can not be null");
-        checkArgument(networkRequestTimeout.toMillis() >= MIN_NETWORK_REQUEST_TIMEOUT.toMillis(),
-                "NetworkRequestTimeout can not be less than %s millis", MIN_NETWORK_REQUEST_TIMEOUT.toMillis());
-        this.networkRequestTimeout = networkRequestTimeout;
-        return this;
-    }
-
-    /**
-     * Gets the value of the connection pool size the client is using.
-     *
-     * @return connection pool size.
-     */
-    public int getMaxConnectionPoolSize() {
-        return this.maxConnectionPoolSize;
-    }
-
-    /**
-     * Sets the value of the connection pool size, the default
-     * is 1000.
-     *
-     * @param maxConnectionPoolSize The value of the connection pool size.
-     * @return the {@link ClientTelemetryConnectionConfig}.
-     */
-    ClientTelemetryConnectionConfig setMaxConnectionPoolSize(int maxConnectionPoolSize) {
-        this.maxConnectionPoolSize = maxConnectionPoolSize;
-        return this;
-    }
-
-    /**
-     * Gets the value of the timeout for an idle connection, the default is 60
-     * seconds.
-     *
-     * @return Idle connection timeout duration.
-     */
-    public Duration getIdleConnectionTimeout() {
-        return this.idleConnectionTimeout;
-    }
-
-    /**
-     * sets the value of the timeout for an idle connection. After that time,
-     * the connection will be automatically closed.
-     *
-     * @param idleConnectionTimeout the duration for an idle connection.
-     * @return the {@link ClientTelemetryConnectionConfig}.
-     */
-    ClientTelemetryConnectionConfig setIdleConnectionTimeout(Duration idleConnectionTimeout) {
-        this.idleConnectionTimeout = idleConnectionTimeout;
-        return this;
-    }
-
-    /**
-     * Gets the proxy options which contain the InetSocketAddress of proxy server.
-     *
-     * @return the proxy options.
-     */
-    public ProxyOptions getProxy() {
-        return this.proxy;
-    }
-
-    /**
-     * Sets the proxy options.
-     *
-     * Currently, only support Http proxy type with just the routing address. Username and password will be ignored.
-     *
-     * @param proxy The proxy options.
-     * @return the {@link ClientTelemetryConnectionConfig}.
-     */
-
-    public ClientTelemetryConnectionConfig setProxy(ProxyOptions proxy) {
-        if (proxy.getType() != ProxyOptions.Type.HTTP) {
-            throw new IllegalArgumentException("Only http proxy type is supported.");
-        }
-
-        this.proxy = proxy;
-        return this;
-    }
-
-    @Override
-    public String toString() {
-        String proxyType = proxy != null ? proxy.getType().toString() : null;
-        String proxyAddress = proxy != null ? proxy.getAddress().toString() : null;
-
-        return "ClientTelemetryConfig{" +
-                ", maxConnectionPoolSize=" + maxConnectionPoolSize +
-                ", idleConnectionTimeout=" + idleConnectionTimeout +
-                ", networkRequestTimeout=" + networkRequestTimeout +
-                ", proxyType=" + proxyType +
-                ", inetSocketProxyAddress=" + proxyAddress +
-                '}';
-    }
-}
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
index 263683ce8b889..0abe6b2bfa311 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
@@ -12,17 +12,14 @@
 import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.ConnectionPolicy;
-import com.azure.cosmos.models.CosmosAuthorizationTokenResolver;
 import com.azure.cosmos.implementation.CosmosClientMetadataCachesSnapshot;
 import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
 import com.azure.cosmos.implementation.guava25.base.Preconditions;
 import com.azure.cosmos.implementation.routing.LocationHelper;
+import com.azure.cosmos.models.CosmosAuthorizationTokenResolver;
 import com.azure.cosmos.models.CosmosPermissionProperties;
 import com.azure.cosmos.util.Beta;
 
-import static com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientBuilderHelper;
-import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
-
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Collections;
@@ -30,6 +27,8 @@
 import java.util.Locale;
 import java.util.Objects;
 
+import static com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientBuilderHelper;
+
 /**
  * Helper class to build CosmosAsyncClient {@link CosmosAsyncClient} and CosmosClient {@link CosmosClient}
  * instances as logical representation of the Azure Cosmos database service.
@@ -119,7 +118,6 @@ public class CosmosClientBuilder implements
     private boolean multipleWriteRegionsEnabled = true;
     private boolean readRequestsFallbackEnabled = true;
     private boolean clientTelemetryEnabled = false;
-    private ClientTelemetryConnectionConfig clientTelemetryConnectionConfig;
     private ClientTelemetryConfig clientTelemetryConfig;
     private ApiType apiType = null;
 
@@ -132,7 +130,6 @@ public CosmosClientBuilder() {
         //  Some default values
         this.userAgentSuffix = "";
         this.throttlingRetryOptions = new ThrottlingRetryOptions();
-        this.clientTelemetryConnectionConfig = ClientTelemetryConnectionConfig.getDefaultConfig();
     }
 
     CosmosClientBuilder metadataCaches(CosmosClientMetadataCachesSnapshot metadataCachesSnapshot) {
@@ -668,19 +665,6 @@ public CosmosClientBuilder readRequestsFallbackEnabled(boolean readRequestsFallb
         return this;
     }
 
-    /***
-     * Set the client telemetry connection config.
-     *
-     * @param clientTelemetryConnectionConfig the {@link ClientTelemetryConnectionConfig}.
-     * @return the current CosmosClientBuilder.
-     */
-    public CosmosClientBuilder clientTelemetryConnectionConfig(ClientTelemetryConnectionConfig clientTelemetryConnectionConfig) {
-        checkNotNull(clientTelemetryConnectionConfig, "Argument 'clientTelemetryConnectionConfig' can not be null");
-        this.clientTelemetryConnectionConfig = clientTelemetryConnectionConfig;
-
-        return this;
-    }
-
     /**
      * Gets the GATEWAY connection configuration to be used.
      *
@@ -830,13 +814,7 @@ private void buildConnectionPolicy() {
     }
 
     private void buildClientTelemetryConfig() {
-        // There are two ways customer can enable the client telemetry:
-        // 1. Enable through CosmosClientBuilder
-        // 2. Enabled by system property
-
-        this.clientTelemetryConfig = new ClientTelemetryConfig(
-                Configs.isClientTelemetryEnabled(this.clientTelemetryEnabled),
-                this.clientTelemetryConnectionConfig);
+        this.clientTelemetryConfig = new ClientTelemetryConfig(this.clientTelemetryEnabled);
     }
 
     private void validateConfig() {
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
index 2621b27faa2e6..94b463cd42fe1 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
@@ -4,27 +4,33 @@
 package com.azure.cosmos.implementation;
 
 import com.azure.core.http.ProxyOptions;
-import com.azure.cosmos.ClientTelemetryConnectionConfig;
+import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.net.InetSocketAddress;
 import java.time.Duration;
 
-import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
-
 public class ClientTelemetryConfig {
+    private static Logger logger = LoggerFactory.getLogger(ClientTelemetryConfig.class);
+
+    private static final Duration DEFAULT_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(60);
+    private static final Duration DEFAULT_IDLE_CONNECTION_TIMEOUT = Duration.ofSeconds(60);
+    private static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 1000;
+
     private final boolean clientTelemetryEnabled;
     private final Duration httpNetworkRequestTimeout;
     private final int maxConnectionPoolSize;
     private final Duration idleHttpConnectionTimeout;
     private final ProxyOptions proxy;
 
-    public ClientTelemetryConfig(boolean clientTelemetryEnabled, ClientTelemetryConnectionConfig connectionConfig) {
-        checkNotNull(connectionConfig, "Argument 'connectionConfig' should not be null");
-
+    public ClientTelemetryConfig(boolean clientTelemetryEnabled) {
         this.clientTelemetryEnabled = clientTelemetryEnabled;
-        this.httpNetworkRequestTimeout = connectionConfig.getNetworkRequestTimeout();
-        this.maxConnectionPoolSize = connectionConfig.getMaxConnectionPoolSize();
-        this.idleHttpConnectionTimeout = connectionConfig.getIdleConnectionTimeout();
-        this.proxy = connectionConfig.getProxy();
+        this.httpNetworkRequestTimeout = DEFAULT_NETWORK_REQUEST_TIMEOUT;
+        this.maxConnectionPoolSize = DEFAULT_MAX_CONNECTION_POOL_SIZE;
+        this.idleHttpConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
+        this.proxy = this.getProxyOptions();
     }
 
     public boolean isClientTelemetryEnabled() {
@@ -46,4 +52,55 @@ public Duration getIdleHttpConnectionTimeout() {
     public ProxyOptions getProxy() {
         return this.proxy;
     }
+
+    private ProxyOptions getProxyOptions() {
+        String config = Configs.getClientTelemetryProxyOptionsConfig();
+
+        if (StringUtils.isNotEmpty(config)) {
+            try {
+                ProxyOptionsConfig proxyOptionsConfig = Utils.getSimpleObjectMapper().readValue(config, ProxyOptionsConfig.class);
+                ProxyOptions.Type type = ProxyOptions.Type.valueOf(proxyOptionsConfig.type);
+
+                if (type != ProxyOptions.Type.HTTP) {
+                    throw new IllegalArgumentException("Only http proxy type is supported.");
+                }
+
+                logger.info(
+                        "Enable proxy with type {}, host {}, port {}",
+                        type,
+                        proxyOptionsConfig.host,
+                        proxyOptionsConfig.port);
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug(
+                            "Enable proxy with type {}, host {}, port {}",
+                            type,
+                            proxyOptionsConfig.host,
+                            proxyOptionsConfig.port);
+                }
+
+                return new ProxyOptions(type, new InetSocketAddress(proxyOptionsConfig.host, proxyOptionsConfig.port));
+            } catch (Exception e) {
+                logger.error("Failed to parse client telemetry proxy option config", e);
+            }
+        }
+
+        return null;
+    }
+
+    private static class ProxyOptionsConfig {
+        @JsonProperty
+        private String host;
+        @JsonProperty
+        private int port;
+        @JsonProperty
+        private String type;
+
+        private ProxyOptionsConfig() {}
+        private ProxyOptionsConfig(String host, int port, String type) {
+            this.host = host;
+            this.port = port;
+            this.type = type;
+        }
+    }
 }
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
index 161e832f75eba..f506010325bda 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
@@ -41,9 +41,13 @@ public class Configs {
     private static final String HTTP_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.HTTP_RESPONSE_TIMEOUT_IN_SECONDS";
     private static final String QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS";
     private static final String ADDRESS_REFRESH_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.ADDRESS_REFRESH_RESPONSE_TIMEOUT_IN_SECONDS";
-    private static final String CLIENT_TELEMETRY_ENABLED = "COSMOS.CLIENT_TELEMETRY_ENABLED";
+
+    // In the future, the client telemetry related config will be part of the database account info
+    // Before that day comes, use JVM properties
     private static final String CLIENT_TELEMETRY_SCHEDULING_IN_SECONDS = "COSMOS.CLIENT_TELEMETRY_SCHEDULING_IN_SECONDS";
     private static final String CLIENT_TELEMETRY_ENDPOINT = "COSMOS.CLIENT_TELEMETRY_ENDPOINT";
+    private static final String CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG = "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG";
+
     private static final String ENVIRONMENT_NAME = "COSMOS.ENVIRONMENT_NAME";
     private static final String QUERYPLAN_CACHING_ENABLED = "COSMOS.QUERYPLAN_CACHING_ENABLED";
 
@@ -221,14 +225,14 @@ public static int getQueryPlanResponseTimeoutInSeconds() {
         return getJVMConfigAsInt(QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS, DEFAULT_QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS);
     }
 
-    public static boolean isClientTelemetryEnabled(boolean defaultValue) {
-        return getJVMConfigAsBoolean(CLIENT_TELEMETRY_ENABLED, defaultValue);
-    }
-
     public static String getClientTelemetryEndpoint() {
         return System.getProperty(CLIENT_TELEMETRY_ENDPOINT);
     }
 
+    public static String getClientTelemetryProxyOptionsConfig() {
+        return System.getProperty(CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG);
+    }
+
     public static String getEnvironmentName() {
         return System.getProperty(ENVIRONMENT_NAME);
     }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
index 6ff73602598ed..f567b9bb5c789 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
@@ -2,7 +2,6 @@
 // Licensed under the MIT License.
 package com.azure.cosmos;
 
-import com.azure.core.http.ProxyOptions;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.HttpConstants;
 import com.azure.cosmos.implementation.InternalObjectNode;
@@ -32,7 +31,6 @@
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -109,7 +107,7 @@ public Object[][] clients() {
     }
 
 
-    @DataProvider(name = "useProxy")
+    @DataProvider(name = "useProxy", parallel = false)
     public static Object[][] useProxy() {
         return new Object[][]{
                 { true },
@@ -232,20 +230,6 @@ public void systemInfo(CosmosClient cosmosClient) throws Exception {
         }
     }
 
-    //Setting priority = 1 as system properties below interfering in other tests in this file
-    @Test(groups = {"unit"}, priority = 1)
-    public void clientTelemetryEnabledFlag() {
-        CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder();
-        assertThat(cosmosClientBuilder.isClientTelemetryEnabled()).isFalse();
-        assertThat(Configs.isClientTelemetryEnabled(cosmosClientBuilder.isClientTelemetryEnabled())).isFalse();
-
-        System.setProperty("COSMOS.CLIENT_TELEMETRY_ENABLED", "true");
-        assertThat(Configs.isClientTelemetryEnabled(cosmosClientBuilder.isClientTelemetryEnabled())).isTrue();
-
-        System.setProperty("COSMOS.CLIENT_TELEMETRY_ENABLED", "false");// setting it back for other tests
-        assertThat(Configs.isClientTelemetryEnabled(cosmosClientBuilder.isClientTelemetryEnabled())).isFalse();
-    }
-
     @Test(groups = {"unit"})
     public void clientTelemetryScheduling() {
         assertThat(Configs.getClientTelemetrySchedulingInSec()).isEqualTo(600);
@@ -269,19 +253,19 @@ public void clientTelemetryWithStageJunoEndpoint(boolean useProxy) throws Interr
             String host = credentialList[0].substring("AccountEndpoint=".length());
             String key = credentialList[1].substring("AccountKey=".length());
 
+            if (useProxy) {
+                System.setProperty(
+                        "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG",
+                        String.format("{\"type\":\"HTTP\", \"host\": \"%s\", \"port\": %d}", this.httpProxyServer.getHost(), this.httpProxyServer.getPort()));
+            } else {
+                System.clearProperty("COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG");
+            }
+
             CosmosClientBuilder clientBuilder = new CosmosClientBuilder()
                 .endpoint(host)
                 .key(key)
                 .clientTelemetryEnabled(true);
 
-            if (useProxy) {
-                ClientTelemetryConnectionConfig connectionConfig = ClientTelemetryConnectionConfig.getDefaultConfig();
-                connectionConfig.setProxy(
-                        new ProxyOptions(
-                                ProxyOptions.Type.HTTP,
-                                new InetSocketAddress(this.httpProxyServer.getHost(), this.httpProxyServer.getPort())));
-                clientBuilder.clientTelemetryConnectionConfig(connectionConfig);
-            }
             cosmosClient = clientBuilder.buildClient();
 
             String containerId = UUID.randomUUID().toString();
@@ -334,6 +318,9 @@ public void clientTelemetryWithStageJunoEndpoint(boolean useProxy) throws Interr
                 cosmosClient.getDatabase(databaseId).delete();
             }
             safeCloseSyncClient(cosmosClient);
+
+            // clear system property
+            System.clearProperty("COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG");
         }
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
index c397c73eac5b1..1730566f86cbd 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
@@ -205,20 +205,22 @@ public void gatewayConnectionConfigWithNetworkRequestTimeout() {
     }
 
     @Test(groups = { "unit" })
-    public void buildClientTelemetryConfig_withClientTelemetryConnectionConfig() throws Exception {
-        ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("127.0.0.0", 8080));
+    public void buildClientTelemetryConfig() {
         DirectConnectionConfig directConnectionConfig = DirectConnectionConfig.getDefaultConfig();
         GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
 
-        ClientTelemetryConnectionConfig clientTelemetryConnectionConfig = ClientTelemetryConnectionConfig.getDefaultConfig();
-        clientTelemetryConnectionConfig.setProxy(proxyOptions);
+        String proxyHost = "127.0.0.0";
+        int proxyPort = 8080;
+        ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
+        System.setProperty(
+                "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG",
+                String.format("{\"type\":\"%s\", \"host\": \"%s\", \"port\": %d}", proxyOptions.getType().toString(), proxyHost, proxyPort));
 
         CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder()
                 .endpoint(TestConfigurations.HOST)
                 .key(TestConfigurations.MASTER_KEY)
                 .directMode(directConnectionConfig, gatewayConnectionConfig)
-                .clientTelemetryEnabled(true)
-                .clientTelemetryConnectionConfig(clientTelemetryConnectionConfig);
+                .clientTelemetryEnabled(true);
 
         ReflectionUtils.buildConnectionPolicy(cosmosClientBuilder);
         ReflectionUtils.buildClientTelemetryConfig(cosmosClientBuilder);
@@ -229,7 +231,8 @@ public void buildClientTelemetryConfig_withClientTelemetryConnectionConfig() thr
 
         ClientTelemetryConfig clientTelemetryConfig = ReflectionUtils.getClientTelemetryConfig(cosmosClientBuilder);
         assertThat(clientTelemetryConfig.isClientTelemetryEnabled()).isTrue();
-        this.validateClientTelemetryConfig(clientTelemetryConfig, clientTelemetryConnectionConfig);
+        assertThat(clientTelemetryConfig.getProxy().getType()).isEqualTo(proxyOptions.getType());
+        assertThat(clientTelemetryConfig.getProxy().getAddress()).isEqualTo(proxyOptions.getAddress());
     }
 
     private void validateDirectAndGatewayConnectionConfig(ConnectionPolicy connectionPolicy, CosmosClientBuilder cosmosClientBuilder,
@@ -275,14 +278,4 @@ private void validateDirectConfig(ConnectionPolicy connectionPolicy, DirectConne
         assertThat(connectionPolicy.getMaxConnectionsPerEndpoint()).isEqualTo(directConnectionConfig.getMaxConnectionsPerEndpoint());
         assertThat(connectionPolicy.getMaxRequestsPerConnection()).isEqualTo(directConnectionConfig.getMaxRequestsPerConnection());
     }
-
-    private void validateClientTelemetryConfig(ClientTelemetryConfig clientTelemetryConfig, ClientTelemetryConnectionConfig clientTelemetryConnectionConfig) {
-        assertThat(clientTelemetryConfig).isNotNull();
-        assertThat(clientTelemetryConnectionConfig).isNotNull();
-
-        assertThat(clientTelemetryConfig.getMaxConnectionPoolSize()).isEqualTo(clientTelemetryConnectionConfig.getMaxConnectionPoolSize());
-        assertThat(clientTelemetryConfig.getIdleHttpConnectionTimeout()).isEqualTo(clientTelemetryConnectionConfig.getIdleConnectionTimeout());
-        assertThat(clientTelemetryConfig.getHttpNetworkRequestTimeout()).isEqualTo(clientTelemetryConnectionConfig.getNetworkRequestTimeout());
-        assertThat(clientTelemetryConfig.getProxy()).isEqualTo(clientTelemetryConfig.getProxy());
-    }
 }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java
index 16cb320af2447..1094946e16c74 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/SpyClientUnderTestFactory.java
@@ -3,7 +3,6 @@
 package com.azure.cosmos.implementation;
 
 import com.azure.core.credential.AzureKeyCredential;
-import com.azure.cosmos.ClientTelemetryConnectionConfig;
 import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.implementation.directconnectivity.Protocol;
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
index 0d6063f874cde..6a85ed1715ddb 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
@@ -6,7 +6,6 @@
 import com.azure.core.credential.AccessToken;
 import com.azure.core.credential.TokenCredential;
 import com.azure.core.credential.TokenRequestContext;
-import com.azure.cosmos.ClientTelemetryConnectionConfig;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
 import com.azure.cosmos.implementation.AuthorizationTokenType;
 import com.azure.cosmos.implementation.ClientTelemetryConfig;
@@ -27,7 +26,6 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.time.Duration;
 import java.time.OffsetDateTime;
 import java.time.ZonedDateTime;
 import java.util.Map;
@@ -161,10 +159,7 @@ public void barrierDocumentReadRidBasedRequest() {
     public void barrierWithAadAuthorizationTokenProviderType() throws URISyntaxException {
 
         TokenCredential tokenCredential = new AadSimpleTokenCredential(TestConfigurations.MASTER_KEY);
-        ClientTelemetryConfig clientTelemetryConfig = new ClientTelemetryConfig(
-                false,
-                ClientTelemetryConnectionConfig.getDefaultConfig()
-        );
+        ClientTelemetryConfig clientTelemetryConfig = new ClientTelemetryConfig(false);
         IAuthorizationTokenProvider authTokenProvider = new RxDocumentClientImpl(
                 new URI(TestConfigurations.HOST),
                 null,

From da6b9302497adcffa828a3f1e3e4c5f33ee8fa50 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Tue, 24 May 2022 18:45:15 -0700
Subject: [PATCH 04/12] clear

---
 .../azure/cosmos/implementation/ClientTelemetryConfig.java | 6 ------
 .../main/java/com/azure/cosmos/implementation/Configs.java | 4 ++--
 .../test/java/com/azure/cosmos/ClientTelemetryTest.java    | 7 +++----
 3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
index 94b463cd42fe1..aedffdf0268d8 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
@@ -65,12 +65,6 @@ private ProxyOptions getProxyOptions() {
                     throw new IllegalArgumentException("Only http proxy type is supported.");
                 }
 
-                logger.info(
-                        "Enable proxy with type {}, host {}, port {}",
-                        type,
-                        proxyOptionsConfig.host,
-                        proxyOptionsConfig.port);
-
                 if (logger.isDebugEnabled()) {
                     logger.debug(
                             "Enable proxy with type {}, host {}, port {}",
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
index f506010325bda..fc8ba88604d79 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
@@ -42,11 +42,11 @@ public class Configs {
     private static final String QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS";
     private static final String ADDRESS_REFRESH_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.ADDRESS_REFRESH_RESPONSE_TIMEOUT_IN_SECONDS";
 
-    // In the future, the client telemetry related config will be part of the database account info
+    private static final String CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG = "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG";
+    // In the future, the following two client telemetry related configs will be part of the database account info
     // Before that day comes, use JVM properties
     private static final String CLIENT_TELEMETRY_SCHEDULING_IN_SECONDS = "COSMOS.CLIENT_TELEMETRY_SCHEDULING_IN_SECONDS";
     private static final String CLIENT_TELEMETRY_ENDPOINT = "COSMOS.CLIENT_TELEMETRY_ENDPOINT";
-    private static final String CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG = "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG";
 
     private static final String ENVIRONMENT_NAME = "COSMOS.ENVIRONMENT_NAME";
     private static final String QUERYPLAN_CACHING_ENABLED = "COSMOS.QUERYPLAN_CACHING_ENABLED";
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
index f567b9bb5c789..2753dfee1a7b2 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientTelemetryTest.java
@@ -261,12 +261,11 @@ public void clientTelemetryWithStageJunoEndpoint(boolean useProxy) throws Interr
                 System.clearProperty("COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG");
             }
 
-            CosmosClientBuilder clientBuilder = new CosmosClientBuilder()
+            cosmosClient = new CosmosClientBuilder()
                 .endpoint(host)
                 .key(key)
-                .clientTelemetryEnabled(true);
-
-            cosmosClient = clientBuilder.buildClient();
+                .clientTelemetryEnabled(true)
+                .buildClient();
 
             String containerId = UUID.randomUUID().toString();
             cosmosClient.createDatabase(databaseId);

From 3baf33a2c1250cd68f89c2dc4b4a957bbe5d410e Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Tue, 24 May 2022 18:52:17 -0700
Subject: [PATCH 05/12] update changelog

---
 sdk/cosmos/azure-cosmos/CHANGELOG.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sdk/cosmos/azure-cosmos/CHANGELOG.md b/sdk/cosmos/azure-cosmos/CHANGELOG.md
index d1b805d2f6387..d3d82ff97cf82 100644
--- a/sdk/cosmos/azure-cosmos/CHANGELOG.md
+++ b/sdk/cosmos/azure-cosmos/CHANGELOG.md
@@ -9,9 +9,9 @@
 #### Bugs Fixed
 
 #### Other Changes
+* Added support for config Proxy for `ClientTelemetry` - See [PR 29022](https://github.com/Azure/azure-sdk-for-java/pull/29022)
 
 ### 4.30.0 (2022-05-20)
-
 #### Bugs Fixed
 * Fixed bubbling of Errors in case of any `java.lang.Error` - See [PR 28620](https://github.com/Azure/azure-sdk-for-java/pull/28620)
 * Fixed an issue with creating new Throughput control client item when `enableThroughputControlGroup` is being called multiple times with the same throughput control group. - See [PR 28905](https://github.com/Azure/azure-sdk-for-java/pull/28905)

From 125e859c1246ef338a4f0811c3d2cc135379f8c1 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Tue, 24 May 2022 22:09:40 -0700
Subject: [PATCH 06/12] fix tests

---
 .../com/azure/cosmos/benchmark/Utils.java     |  13 +-
 .../implementation/ConsistencyTests1.java     | 205 +++++++++++------
 .../implementation/ConsistencyTests2.java     |  98 ++++++---
 .../implementation/ConsistencyTestsBase.java  | 206 ++++++++++++------
 .../GoneAndRetryPolicyWithSpyClientTest.java  |   3 +-
 .../implementation/RetryThrottleTest.java     |   3 +-
 .../cosmos/implementation/TestSuiteBase.java  |  34 +--
 .../BarrierRequestHelperTest.java             |   1 +
 .../DCDocumentCrudTest.java                   |   4 +-
 .../azure/cosmos/rx/ResourceTokenTest.java    |  59 +++--
 10 files changed, 413 insertions(+), 213 deletions(-)

diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
index 24ee16f53a134..2ed632b207ce3 100644
--- a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
+++ b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
@@ -4,6 +4,7 @@
 package com.azure.cosmos.benchmark;
 
 import com.azure.cosmos.DirectConnectionConfig;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.models.FeedResponse;
 import com.azure.cosmos.ThrottlingRetryOptions;
@@ -26,11 +27,13 @@ public static AsyncDocumentClient housekeepingClient() {
         options.setMaxRetryAttemptsOnThrottledRequests(100);
         options.setMaxRetryWaitTime(Duration.ofSeconds(60));
         connectionPolicy.setThrottlingRetryOptions(options);
-        return new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                                                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                                                .withConnectionPolicy(connectionPolicy)
-                                                .withContentResponseOnWriteEnabled(true)
-                                                .build();
+        return new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
     }
 
     public static String getCollectionLink(Database db, DocumentCollection collection) {
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
index 0a94787acaacf..b938e9dfcedf4 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
@@ -3,7 +3,6 @@
 
 package com.azure.cosmos.implementation;
 
-import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.DirectConnectionConfig;
 import com.azure.cosmos.GatewayConnectionConfig;
@@ -28,15 +27,25 @@ public void validateStrongConsistencyOnSyncReplication() throws Exception {
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         User userDefinition = getUserDefinition();
         userDefinition.setId(userDefinition.getId() + "validateStrongConsistencyOnSyncReplication");
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), userDefinition);
@@ -49,30 +58,46 @@ public void validateConsistentLSNForDirectTCPClient() {
         //TODO Need to test with TCP protocol
         // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         validateConsistentLSN();
     }
 
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateConsistentLSNForDirectHttpsClient() {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         validateConsistentLSN();
     }
 
@@ -81,15 +106,23 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectTCPClient() {
         //TODO Need to test with TCP protocol
         //https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
 
@@ -114,15 +147,23 @@ public void validateBoundedStalenessDynamicQuorumSyncReplication() {
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateConsistentLSNAndQuorumAckedLSNForDirectHttpsClient() {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
 
@@ -156,15 +197,25 @@ public void validateConsistentPrefixOnSyncReplication() throws InterruptedExcept
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), getUserDefinition());
         boolean readLagging = validateConsistentPrefix(user);
         assertThat(readLagging).isFalse();
@@ -177,17 +228,25 @@ public void validateConsistentPrefixOnAsyncReplication() throws InterruptedExcep
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.initClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
         boolean readLagging = validateConsistentPrefix(document);
@@ -229,11 +288,15 @@ private void validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(boolean
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        AsyncDocumentClient client = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION)
-                .withContentResponseOnWriteEnabled(true).build();
+        AsyncDocumentClient client =
+                new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
             DocumentCollection documentCollection = new DocumentCollection();
             documentCollection.setId(UUID.randomUUID().toString());
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
index e18b7b9037a79..83bff9633c392 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
@@ -30,15 +30,25 @@ public class ConsistencyTests2 extends ConsistencyTestsBase {
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateReadSessionOnAsyncReplication() throws InterruptedException {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
                                                            null, false).block().getResource();
@@ -50,15 +60,25 @@ public void validateReadSessionOnAsyncReplication() throws InterruptedException
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateWriteSessionOnAsyncReplication() throws InterruptedException {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
                                                            null, false).block().getResource();
@@ -156,17 +176,25 @@ public void validateSessionTokenFromCollectionReplaceIsServerToken() {
     public void validateNoChargeOnFailedSessionRead() throws Exception {
         // DIRECT clients for read and write operations
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         // Client locked to replica for pause/resume
-        RxDocumentClientImpl readSecondaryClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl readSecondaryClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
             // CREATE collection
             DocumentCollection parentResource = writeClient.createCollection(createdDatabase.getSelfLink(),
@@ -216,11 +244,15 @@ public void validateSessionTokenAsync() {
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        RxDocumentClientImpl client = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl client =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
 
         try {
             Document lastDocument = client.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
index 9d4650d262bd8..dc64ca2ad5e16 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
@@ -118,15 +118,24 @@ void validateStrongConsistencyOnAsyncReplication(boolean useGateway) throws Inte
             connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
         }
 
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
 
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .build();
 
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.writeClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
@@ -158,10 +167,15 @@ void validateSessionContainerAfterCollectionCreateReplace(boolean useGateway) {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
 
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
 
         try {
             PartitionKeyDefinition partitionKey = new PartitionKeyDefinition();
@@ -364,16 +378,24 @@ void validateSessionContainerAfterCollectionDeletion(boolean useGateway) throws
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl client1 =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+        RxDocumentClientImpl client2 =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION
+                        ).withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
 
         String collectionId = UUID.randomUUID().toString();
         try {
@@ -495,16 +517,24 @@ void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exce
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+        RxDocumentClientImpl validationClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
             // write a document, and upsert to it to update etag.
             ResourceResponse documentResponse = writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, true).block();
@@ -536,16 +566,24 @@ void validateSessionTokenWithDocumentNotFoundException(boolean useGateway) throw
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+        RxDocumentClientImpl validationClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
             DocumentCollection collectionDefinition = getCollectionDefinition();
             collectionDefinition.setId("TestCollection");
@@ -572,11 +610,15 @@ void validateSessionTokenWithExpectedException(boolean useGateway) throws Except
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
             ResourceResponse documentResponse =
                     writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, false).block();
@@ -605,16 +647,24 @@ void validateSessionTokenWithConflictException(boolean useGateway) {
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
+        RxDocumentClientImpl validationClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
             Document documentDefinition = getDocumentDefinition();
             ResourceResponse documentResponse =
@@ -638,11 +688,15 @@ void validateSessionTokenMultiPartitionCollection(boolean useGateway) throws Exc
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         try {
 
             Range fullRange = new Range(PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey,
@@ -717,11 +771,15 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl client1 =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .build();
         RxDocumentClientImpl client2 = null;
         try {
             Document doc = client1.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, true).block().getResource();
@@ -730,11 +788,15 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
             Document doc1 = client1.readDocument(BridgeInternal.getAltLink(doc), requestOptions).block().getResource();
 
             String token1 = ((SessionContainer) client1.getSession()).getSessionToken(createdCollection.getSelfLink());
-            client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                    .withConnectionPolicy(connectionPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                    .build();
+            client2 =
+                    (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                            .withConnectionPolicy(connectionPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withContentResponseOnWriteEnabled(true)
+                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                            .build();
             client2.replaceCollection(createdCollection, null).block();
             String token2 = ((SessionContainer) client2.getSession()).getSessionToken(createdCollection.getSelfLink());
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
index d7fc693572f0b..2b468b476386f 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
@@ -69,7 +69,8 @@ static Builder createDCBuilder(Protocol protocol) {
             .withConnectionPolicy(connectionPolicy)
             .withConsistencyLevel(ConsistencyLevel.SESSION)
             .withContentResponseOnWriteEnabled(true)
-            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY);
+            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+            .withClientTelemetryConfig(new ClientTelemetryConfig(false));
     }
 
     @Factory(dataProvider = "directClientBuilder")
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
index e77a9fcaa7677..121907e1afe20 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
@@ -48,7 +48,8 @@ public void retryCreateDocumentsOnSpike() throws Exception {
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(policy)
                 .withConsistencyLevel(ConsistencyLevel.EVENTUAL)
-                .withContentResponseOnWriteEnabled(true);
+                .withContentResponseOnWriteEnabled(true)
+                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
 
         client = SpyClientUnderTestFactory.createClientWithGatewaySpy(builder);
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
index c9a16bfbdaced..50de809cbef47 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
@@ -904,10 +904,13 @@ static protected Builder createGatewayHouseKeepingDocumentClient() {
         options.setMaxRetryWaitTime(Duration.ofSeconds(SUITE_SETUP_TIMEOUT));
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(gatewayConnectionConfig);
         connectionPolicy.setThrottlingRetryOptions(options);
-        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
+        return new Builder()
+                .withServiceEndpoint(TestConfigurations.HOST)
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true);
+                .withConsistencyLevel(ConsistencyLevel.SESSION)
+                .withContentResponseOnWriteEnabled(true)
+                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
     }
 
     static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List preferredLocations, boolean contentResponseOnWriteEnabled) {
@@ -915,11 +918,13 @@ static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consiste
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(gatewayConnectionConfig);
         connectionPolicy.setMultipleWriteRegionsEnabled(multiMasterEnabled);
         connectionPolicy.setPreferredRegions(preferredLocations);
-        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
-                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                            .withConnectionPolicy(connectionPolicy)
-                            .withConsistencyLevel(consistencyLevel)
-                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
+        return new Builder()
+                .withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(consistencyLevel)
+                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled)
+                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
     }
 
     static protected Builder createGatewayRxDocumentClient() {
@@ -944,12 +949,15 @@ static protected Builder createDirectRxDocumentClient(ConsistencyLevel consisten
         Configs configs = Mockito.spy(new Configs());
         doAnswer((Answer)invocation -> protocol).when(configs).getProtocol();
 
-        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
-                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                            .withConnectionPolicy(connectionPolicy)
-                            .withConsistencyLevel(consistencyLevel)
-                            .withConfigs(configs)
-                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
+        return new Builder()
+                .withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(consistencyLevel)
+                .withConfigs(configs)
+                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled)
+                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
+
     }
 
     protected int expectedNumberOfPages(int totalExpectedResult, int maxPageSize) {
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
index 6a85ed1715ddb..9ed972fb91d8d 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
@@ -238,6 +238,7 @@ private IAuthorizationTokenProvider getIAuthorizationTokenProvider() {
                 new AsyncDocumentClient.Builder()
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withServiceEndpoint(TestConfigurations.HOST)
+                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
index f7c516c2f1795..23c1d20f2b9bd 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
@@ -4,6 +4,7 @@
 
 import com.azure.cosmos.BridgeInternal;
 import com.azure.cosmos.DirectConnectionConfig;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.models.CosmosQueryRequestOptions;
@@ -80,7 +81,8 @@ static Builder createDCBuilder(Protocol protocol) {
             .withConnectionPolicy(connectionPolicy)
             .withConsistencyLevel(ConsistencyLevel.SESSION)
             .withContentResponseOnWriteEnabled(true)
-            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY);
+            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+            .withClientTelemetryConfig(new ClientTelemetryConfig(false));
     }
 
     @Factory(dataProvider = "directClientBuilder")
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
index 4daca069ea51e..fef724a29670d 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
@@ -5,6 +5,7 @@
 import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
 import com.azure.cosmos.implementation.DatabaseForTest;
@@ -255,9 +256,14 @@ public void readCollectionFromPermissionFeed(String collectionUrl, Permission pe
         try {
             List permissionFeed = new ArrayList<>();
             permissionFeed.add(permission);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                            .build();
             Mono> readObservable = asyncClientResourceToken
                     .readCollection(collectionUrl, null);
 
@@ -282,9 +288,14 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
             permissionFeed.add(permission);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(defaultPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                            .build();
             RequestOptions options = new RequestOptions();
             if (StringUtils.isNotEmpty(partitionKey)) {
                 options.setPartitionKey(new PartitionKey(partitionKey));
@@ -310,10 +321,14 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
     public void readDocumentFromResouceToken(String resourceToken) throws Exception {
         AsyncDocumentClient asyncClientResourceToken = null;
         try {
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withMasterKeyOrResourceToken(resourceToken)
-                    .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy()).withConsistencyLevel(ConsistencyLevel.SESSION)
-                    .build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withMasterKeyOrResourceToken(resourceToken)
+                            .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                            .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(PartitionKey.NONE);
             Mono> readObservable = asyncClientResourceToken
@@ -340,9 +355,14 @@ public void readDocumentOfParKeyFromTwoCollPermissionWithDiffPartitionKeys(Strin
             permissionFeed.add(collPermission2);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(defaultPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                            .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
             Mono> readObservable = asyncClientResourceToken
@@ -369,9 +389,14 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_ResourceNotFound(
             permissionFeed.add(permission);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(defaultPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                            .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
             Mono> readObservable = asyncClientResourceToken
@@ -400,6 +425,7 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_WithException() t
                 .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
                 .withPermissionFeed(permissionFeed)
+                .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                 .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(PARTITION_KEY_VALUE_2));
@@ -425,6 +451,7 @@ public void queryItemFromResourceToken(DocumentCollection documentCollection, Pe
                 .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
                 .withMasterKeyOrResourceToken(permission.getToken())
+                .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                 .build();
 
             CosmosQueryRequestOptions queryRequestOptions = new CosmosQueryRequestOptions();

From a56418203b0a8944e63f0e3da464cf4e1a166c05 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Tue, 24 May 2022 22:24:39 -0700
Subject: [PATCH 07/12] fix spotbug issue

---
 .../azure/cosmos/implementation/ClientTelemetryConfig.java  | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
index aedffdf0268d8..6971a33fb5487 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
@@ -6,6 +6,8 @@
 import com.azure.core.http.ProxyOptions;
 import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -74,7 +76,9 @@ private ProxyOptions getProxyOptions() {
                 }
 
                 return new ProxyOptions(type, new InetSocketAddress(proxyOptionsConfig.host, proxyOptionsConfig.port));
-            } catch (Exception e) {
+            } catch (JsonMappingException e) {
+                logger.error("Failed to parse client telemetry proxy option config", e);
+            } catch (JsonProcessingException e) {
                 logger.error("Failed to parse client telemetry proxy option config", e);
             }
         }

From f0d8e284a62824c5516e5a5b001e020953347bd4 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Tue, 24 May 2022 23:25:13 -0700
Subject: [PATCH 08/12] fix tests

---
 .../src/test/java/com/azure/cosmos/CosmosClientBuilderTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosClientBuilderTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosClientBuilderTest.java
index 9197fef7ca830..7d73baa947c69 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosClientBuilderTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosClientBuilderTest.java
@@ -65,7 +65,7 @@ public void validateApiTypePresent() {
          accessor.setCosmosClientApiType(cosmosClientBuilder, apiType);
 
         RxDocumentClientImpl documentClient =
-            (RxDocumentClientImpl) ReflectionUtils.getAsyncDocumentClient(new CosmosAsyncClient(cosmosClientBuilder));
+            (RxDocumentClientImpl) ReflectionUtils.getAsyncDocumentClient(cosmosClientBuilder.buildAsyncClient());
         assertThat(ReflectionUtils.getApiType(documentClient)).isEqualTo(apiType);
     }
 }

From f53d754d30381a57615eece6c07eccc372a96272 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Wed, 25 May 2022 14:57:21 -0700
Subject: [PATCH 09/12] resolve comments

---
 .../java/com/azure/cosmos/benchmark/Utils.java |  8 +++-----
 .../com/azure/cosmos/CosmosClientBuilder.java  | 14 ++++----------
 .../implementation/ClientTelemetryConfig.java  | 16 ++++++++++++----
 .../implementation/ConsistencyTests1.java      | 15 ---------------
 .../implementation/ConsistencyTests2.java      |  7 -------
 .../implementation/ConsistencyTestsBase.java   | 18 ++----------------
 .../GoneAndRetryPolicyWithSpyClientTest.java   |  3 +--
 .../implementation/RetryThrottleTest.java      |  3 +--
 .../cosmos/implementation/TestSuiteBase.java   | 10 +++-------
 .../BarrierRequestHelperTest.java              |  4 +---
 .../directconnectivity/DCDocumentCrudTest.java | 16 +++++++---------
 .../com/azure/cosmos/rx/ResourceTokenTest.java |  8 --------
 12 files changed, 34 insertions(+), 88 deletions(-)

diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
index 2ed632b207ce3..62b64b5fa961e 100644
--- a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
+++ b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
@@ -4,17 +4,16 @@
 package com.azure.cosmos.benchmark;
 
 import com.azure.cosmos.DirectConnectionConfig;
-import com.azure.cosmos.implementation.ClientTelemetryConfig;
-import com.azure.cosmos.implementation.ConnectionPolicy;
-import com.azure.cosmos.models.FeedResponse;
 import com.azure.cosmos.ThrottlingRetryOptions;
-import com.azure.cosmos.models.SqlQuerySpec;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
+import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
 import com.azure.cosmos.implementation.DatabaseForTest;
 import com.azure.cosmos.implementation.DocumentCollection;
 import com.azure.cosmos.implementation.ResourceResponse;
 import com.azure.cosmos.implementation.TestConfigurations;
+import com.azure.cosmos.models.FeedResponse;
+import com.azure.cosmos.models.SqlQuerySpec;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
@@ -32,7 +31,6 @@ public static AsyncDocumentClient housekeepingClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
index 0abe6b2bfa311..bec6e443b7ef9 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java
@@ -117,8 +117,7 @@ public class CosmosClientBuilder implements
     private boolean endpointDiscoveryEnabled = true;
     private boolean multipleWriteRegionsEnabled = true;
     private boolean readRequestsFallbackEnabled = true;
-    private boolean clientTelemetryEnabled = false;
-    private ClientTelemetryConfig clientTelemetryConfig;
+    private final ClientTelemetryConfig clientTelemetryConfig;
     private ApiType apiType = null;
 
     /**
@@ -130,6 +129,7 @@ public CosmosClientBuilder() {
         //  Some default values
         this.userAgentSuffix = "";
         this.throttlingRetryOptions = new ThrottlingRetryOptions();
+        this.clientTelemetryConfig = ClientTelemetryConfig.getDefaultConfig();
     }
 
     CosmosClientBuilder metadataCaches(CosmosClientMetadataCachesSnapshot metadataCachesSnapshot) {
@@ -642,7 +642,7 @@ public CosmosClientBuilder multipleWriteRegionsEnabled(boolean multipleWriteRegi
      * @return current CosmosClientBuilder
      */
     public CosmosClientBuilder clientTelemetryEnabled(boolean clientTelemetryEnabled) {
-        this.clientTelemetryEnabled = clientTelemetryEnabled;
+        this.clientTelemetryConfig.setClientTelemetryEnabled(clientTelemetryEnabled);
         return this;
     }
 
@@ -744,7 +744,7 @@ boolean isMultipleWriteRegionsEnabled() {
      * @return flag to enable client telemetry.
      */
     boolean isClientTelemetryEnabled() {
-        return this.clientTelemetryEnabled;
+        return this.clientTelemetryConfig.isClientTelemetryEnabled();
     }
 
     /**
@@ -776,7 +776,6 @@ public CosmosAsyncClient buildAsyncClient() {
 
         validateConfig();
         buildConnectionPolicy();
-        buildClientTelemetryConfig();
         return new CosmosAsyncClient(this);
     }
 
@@ -789,7 +788,6 @@ public CosmosClient buildClient() {
 
         validateConfig();
         buildConnectionPolicy();
-        buildClientTelemetryConfig();
         return new CosmosClient(this);
     }
 
@@ -813,10 +811,6 @@ private void buildConnectionPolicy() {
         this.connectionPolicy.setReadRequestsFallbackEnabled(this.readRequestsFallbackEnabled);
     }
 
-    private void buildClientTelemetryConfig() {
-        this.clientTelemetryConfig = new ClientTelemetryConfig(this.clientTelemetryEnabled);
-    }
-
     private void validateConfig() {
         URI uri;
         try {
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
index 6971a33fb5487..c6f760f8cf716 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
@@ -16,25 +16,33 @@
 
 public class ClientTelemetryConfig {
     private static Logger logger = LoggerFactory.getLogger(ClientTelemetryConfig.class);
-
+    private static boolean DEFAULT_CLIENT_TELEMETRY_ENABLED = false;
     private static final Duration DEFAULT_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(60);
     private static final Duration DEFAULT_IDLE_CONNECTION_TIMEOUT = Duration.ofSeconds(60);
     private static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 1000;
 
-    private final boolean clientTelemetryEnabled;
+    private boolean clientTelemetryEnabled;
     private final Duration httpNetworkRequestTimeout;
     private final int maxConnectionPoolSize;
     private final Duration idleHttpConnectionTimeout;
     private final ProxyOptions proxy;
 
-    public ClientTelemetryConfig(boolean clientTelemetryEnabled) {
-        this.clientTelemetryEnabled = clientTelemetryEnabled;
+    public ClientTelemetryConfig() {
+        this.clientTelemetryEnabled = DEFAULT_CLIENT_TELEMETRY_ENABLED;
         this.httpNetworkRequestTimeout = DEFAULT_NETWORK_REQUEST_TIMEOUT;
         this.maxConnectionPoolSize = DEFAULT_MAX_CONNECTION_POOL_SIZE;
         this.idleHttpConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
         this.proxy = this.getProxyOptions();
     }
 
+    public static ClientTelemetryConfig getDefaultConfig() {
+        return new ClientTelemetryConfig();
+    }
+
+    public void setClientTelemetryEnabled(boolean clientTelemetryEnabled) {
+        this.clientTelemetryEnabled = clientTelemetryEnabled;
+    }
+
     public boolean isClientTelemetryEnabled() {
         return this.clientTelemetryEnabled;
     }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
index b938e9dfcedf4..bb535b2cdd888 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
@@ -34,7 +34,6 @@ public void validateStrongConsistencyOnSyncReplication() throws Exception {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.STRONG)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -44,7 +43,6 @@ public void validateStrongConsistencyOnSyncReplication() throws Exception {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.STRONG)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         User userDefinition = getUserDefinition();
         userDefinition.setId(userDefinition.getId() + "validateStrongConsistencyOnSyncReplication");
@@ -64,7 +62,6 @@ public void validateConsistentLSNForDirectTCPClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -73,7 +70,6 @@ public void validateConsistentLSNForDirectTCPClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         validateConsistentLSN();
     }
@@ -87,7 +83,6 @@ public void validateConsistentLSNForDirectHttpsClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -96,7 +91,6 @@ public void validateConsistentLSNForDirectHttpsClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         validateConsistentLSN();
     }
@@ -112,7 +106,6 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectTCPClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -121,7 +114,6 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectTCPClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
@@ -153,7 +145,6 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectHttpsClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -162,7 +153,6 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectHttpsClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
@@ -204,7 +194,6 @@ public void validateConsistentPrefixOnSyncReplication() throws InterruptedExcept
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -214,7 +203,6 @@ public void validateConsistentPrefixOnSyncReplication() throws InterruptedExcept
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), getUserDefinition());
         boolean readLagging = validateConsistentPrefix(user);
@@ -235,7 +223,6 @@ public void validateConsistentPrefixOnAsyncReplication() throws InterruptedExcep
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -245,7 +232,6 @@ public void validateConsistentPrefixOnAsyncReplication() throws InterruptedExcep
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.initClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
@@ -295,7 +281,6 @@ private void validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(boolean
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
             DocumentCollection documentCollection = new DocumentCollection();
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
index 83bff9633c392..62ebaa931ebf3 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
@@ -37,7 +37,6 @@ public void validateReadSessionOnAsyncReplication() throws InterruptedException
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -47,7 +46,6 @@ public void validateReadSessionOnAsyncReplication() throws InterruptedException
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
@@ -67,7 +65,6 @@ public void validateWriteSessionOnAsyncReplication() throws InterruptedException
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -77,7 +74,6 @@ public void validateWriteSessionOnAsyncReplication() throws InterruptedException
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
@@ -183,7 +179,6 @@ public void validateNoChargeOnFailedSessionRead() throws Exception {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         // Client locked to replica for pause/resume
         RxDocumentClientImpl readSecondaryClient =
@@ -193,7 +188,6 @@ public void validateNoChargeOnFailedSessionRead() throws Exception {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
             // CREATE collection
@@ -251,7 +245,6 @@ public void validateSessionTokenAsync() {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         try {
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
index dc64ca2ad5e16..dca0069c20026 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
@@ -125,7 +125,6 @@ void validateStrongConsistencyOnAsyncReplication(boolean useGateway) throws Inte
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.STRONG)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         this.readClient =
@@ -174,7 +173,6 @@ void validateSessionContainerAfterCollectionCreateReplace(boolean useGateway) {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
 
         try {
@@ -385,16 +383,14 @@ void validateSessionContainerAfterCollectionDeletion(boolean useGateway) throws
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         RxDocumentClientImpl client2 =
                 (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
                         .withServiceEndpoint(TestConfigurations.HOST)
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION
-                        ).withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
                         .build();
 
         String collectionId = UUID.randomUUID().toString();
@@ -524,7 +520,6 @@ void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exce
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         RxDocumentClientImpl validationClient =
                 (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
@@ -533,7 +528,6 @@ void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exce
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
             // write a document, and upsert to it to update etag.
@@ -573,7 +567,6 @@ void validateSessionTokenWithDocumentNotFoundException(boolean useGateway) throw
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         RxDocumentClientImpl validationClient =
                 (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
@@ -582,7 +575,6 @@ void validateSessionTokenWithDocumentNotFoundException(boolean useGateway) throw
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
             DocumentCollection collectionDefinition = getCollectionDefinition();
@@ -617,7 +609,6 @@ void validateSessionTokenWithExpectedException(boolean useGateway) throws Except
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
             ResourceResponse documentResponse =
@@ -654,7 +645,6 @@ void validateSessionTokenWithConflictException(boolean useGateway) {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         RxDocumentClientImpl validationClient =
                 (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
@@ -663,7 +653,6 @@ void validateSessionTokenWithConflictException(boolean useGateway) {
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
             Document documentDefinition = getDocumentDefinition();
@@ -695,7 +684,6 @@ void validateSessionTokenMultiPartitionCollection(boolean useGateway) throws Exc
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         try {
 
@@ -778,7 +766,6 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
                         .withConnectionPolicy(connectionPolicy)
                         .withConsistencyLevel(ConsistencyLevel.SESSION)
                         .withContentResponseOnWriteEnabled(true)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
         RxDocumentClientImpl client2 = null;
         try {
@@ -795,7 +782,6 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
                             .withConnectionPolicy(connectionPolicy)
                             .withConsistencyLevel(ConsistencyLevel.SESSION)
                             .withContentResponseOnWriteEnabled(true)
-                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                             .build();
             client2.replaceCollection(createdCollection, null).block();
             String token2 = ((SessionContainer) client2.getSession()).getSessionToken(createdCollection.getSelfLink());
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
index 2b468b476386f..d7fc693572f0b 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
@@ -69,8 +69,7 @@ static Builder createDCBuilder(Protocol protocol) {
             .withConnectionPolicy(connectionPolicy)
             .withConsistencyLevel(ConsistencyLevel.SESSION)
             .withContentResponseOnWriteEnabled(true)
-            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-            .withClientTelemetryConfig(new ClientTelemetryConfig(false));
+            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY);
     }
 
     @Factory(dataProvider = "directClientBuilder")
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
index 121907e1afe20..e77a9fcaa7677 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
@@ -48,8 +48,7 @@ public void retryCreateDocumentsOnSpike() throws Exception {
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(policy)
                 .withConsistencyLevel(ConsistencyLevel.EVENTUAL)
-                .withContentResponseOnWriteEnabled(true)
-                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
+                .withContentResponseOnWriteEnabled(true);
 
         client = SpyClientUnderTestFactory.createClientWithGatewaySpy(builder);
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
index 50de809cbef47..a0852bbaba970 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
@@ -909,8 +909,7 @@ static protected Builder createGatewayHouseKeepingDocumentClient() {
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(connectionPolicy)
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
-                .withContentResponseOnWriteEnabled(true)
-                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
+                .withContentResponseOnWriteEnabled(true);
     }
 
     static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List preferredLocations, boolean contentResponseOnWriteEnabled) {
@@ -923,8 +922,7 @@ static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consiste
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(connectionPolicy)
                 .withConsistencyLevel(consistencyLevel)
-                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled)
-                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
+                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
     }
 
     static protected Builder createGatewayRxDocumentClient() {
@@ -955,9 +953,7 @@ static protected Builder createDirectRxDocumentClient(ConsistencyLevel consisten
                 .withConnectionPolicy(connectionPolicy)
                 .withConsistencyLevel(consistencyLevel)
                 .withConfigs(configs)
-                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled)
-                .withClientTelemetryConfig(new ClientTelemetryConfig(false));
-
+                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
     }
 
     protected int expectedNumberOfPages(int totalExpectedResult, int maxPageSize) {
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
index 9ed972fb91d8d..12d1b024ca04e 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
@@ -159,7 +159,6 @@ public void barrierDocumentReadRidBasedRequest() {
     public void barrierWithAadAuthorizationTokenProviderType() throws URISyntaxException {
 
         TokenCredential tokenCredential = new AadSimpleTokenCredential(TestConfigurations.MASTER_KEY);
-        ClientTelemetryConfig clientTelemetryConfig = new ClientTelemetryConfig(false);
         IAuthorizationTokenProvider authTokenProvider = new RxDocumentClientImpl(
                 new URI(TestConfigurations.HOST),
                 null,
@@ -175,7 +174,7 @@ public void barrierWithAadAuthorizationTokenProviderType() throws URISyntaxExcep
                 false,
                 null,
                 null,
-                clientTelemetryConfig);
+                ClientTelemetryConfig.getDefaultConfig());
 
         ResourceType resourceType = ResourceType.DocumentCollection;
         OperationType operationType = OperationType.Read;
@@ -238,7 +237,6 @@ private IAuthorizationTokenProvider getIAuthorizationTokenProvider() {
                 new AsyncDocumentClient.Builder()
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withServiceEndpoint(TestConfigurations.HOST)
-                        .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                         .build();
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
index 23c1d20f2b9bd..6cb23e4fbdf9f 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
@@ -3,16 +3,11 @@
 package com.azure.cosmos.implementation.directconnectivity;
 
 import com.azure.cosmos.BridgeInternal;
-import com.azure.cosmos.DirectConnectionConfig;
-import com.azure.cosmos.implementation.ClientTelemetryConfig;
-import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.ConsistencyLevel;
-import com.azure.cosmos.models.CosmosQueryRequestOptions;
-import com.azure.cosmos.models.FeedResponse;
-import com.azure.cosmos.models.ModelBridgeInternal;
-import com.azure.cosmos.models.PartitionKey;
+import com.azure.cosmos.DirectConnectionConfig;
 import com.azure.cosmos.implementation.AsyncDocumentClient.Builder;
 import com.azure.cosmos.implementation.Configs;
+import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
 import com.azure.cosmos.implementation.Document;
 import com.azure.cosmos.implementation.DocumentCollection;
@@ -29,6 +24,10 @@
 import com.azure.cosmos.implementation.StoredProcedureResponse;
 import com.azure.cosmos.implementation.TestConfigurations;
 import com.azure.cosmos.implementation.TestSuiteBase;
+import com.azure.cosmos.models.CosmosQueryRequestOptions;
+import com.azure.cosmos.models.FeedResponse;
+import com.azure.cosmos.models.ModelBridgeInternal;
+import com.azure.cosmos.models.PartitionKey;
 import org.mockito.stubbing.Answer;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -81,8 +80,7 @@ static Builder createDCBuilder(Protocol protocol) {
             .withConnectionPolicy(connectionPolicy)
             .withConsistencyLevel(ConsistencyLevel.SESSION)
             .withContentResponseOnWriteEnabled(true)
-            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-            .withClientTelemetryConfig(new ClientTelemetryConfig(false));
+            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY);
     }
 
     @Factory(dataProvider = "directClientBuilder")
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
index fef724a29670d..4ea8cc1c418f2 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
@@ -5,7 +5,6 @@
 import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
-import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
 import com.azure.cosmos.implementation.DatabaseForTest;
@@ -262,7 +261,6 @@ public void readCollectionFromPermissionFeed(String collectionUrl, Permission pe
                             .withPermissionFeed(permissionFeed)
                             .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                             .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                             .build();
             Mono> readObservable = asyncClientResourceToken
                     .readCollection(collectionUrl, null);
@@ -294,7 +292,6 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
                             .withPermissionFeed(permissionFeed)
                             .withConnectionPolicy(defaultPolicy)
                             .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                             .build();
             RequestOptions options = new RequestOptions();
             if (StringUtils.isNotEmpty(partitionKey)) {
@@ -327,7 +324,6 @@ public void readDocumentFromResouceToken(String resourceToken) throws Exception
                             .withMasterKeyOrResourceToken(resourceToken)
                             .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                             .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                             .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(PartitionKey.NONE);
@@ -361,7 +357,6 @@ public void readDocumentOfParKeyFromTwoCollPermissionWithDiffPartitionKeys(Strin
                             .withPermissionFeed(permissionFeed)
                             .withConnectionPolicy(defaultPolicy)
                             .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                             .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
@@ -395,7 +390,6 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_ResourceNotFound(
                             .withPermissionFeed(permissionFeed)
                             .withConnectionPolicy(defaultPolicy)
                             .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                             .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
@@ -425,7 +419,6 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_WithException() t
                 .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
                 .withPermissionFeed(permissionFeed)
-                .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                 .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(PARTITION_KEY_VALUE_2));
@@ -451,7 +444,6 @@ public void queryItemFromResourceToken(DocumentCollection documentCollection, Pe
                 .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
                 .withMasterKeyOrResourceToken(permission.getToken())
-                .withClientTelemetryConfig(new ClientTelemetryConfig(false))
                 .build();
 
             CosmosQueryRequestOptions queryRequestOptions = new CosmosQueryRequestOptions();

From 1a828b9e516e96b1320d3e97aa27523be174e2c9 Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Wed, 25 May 2022 15:41:08 -0700
Subject: [PATCH 10/12] resolve comments

---
 .../azure/cosmos/ClientUnderTestBuilder.java  |   1 -
 .../azure/cosmos/ConnectionConfigTest.java    |   1 -
 .../implementation/ConsistencyTests1.java     | 190 +++++++----------
 .../implementation/ConsistencyTests2.java     |  91 +++------
 .../implementation/ConsistencyTestsBase.java  | 192 +++++++-----------
 .../cosmos/implementation/TestSuiteBase.java  |  30 ++-
 .../directconnectivity/ReflectionUtils.java   |   4 -
 .../azure/cosmos/rx/ResourceTokenTest.java    |  51 ++---
 8 files changed, 205 insertions(+), 355 deletions(-)

diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java
index 8651442f3d188..93f1d88bc2a06 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ClientUnderTestBuilder.java
@@ -2,7 +2,6 @@
 // Licensed under the MIT License.
 package com.azure.cosmos;
 
-import com.azure.cosmos.implementation.ApiType;
 import com.azure.cosmos.implementation.ImplementationBridgeHelpers;
 import com.azure.cosmos.implementation.RxDocumentClientUnderTest;
 import com.azure.cosmos.implementation.Strings;
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
index 1730566f86cbd..1b7644fc1e3ab 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/ConnectionConfigTest.java
@@ -223,7 +223,6 @@ public void buildClientTelemetryConfig() {
                 .clientTelemetryEnabled(true);
 
         ReflectionUtils.buildConnectionPolicy(cosmosClientBuilder);
-        ReflectionUtils.buildClientTelemetryConfig(cosmosClientBuilder);
 
         ConnectionPolicy connectionPolicy = ReflectionUtils.getConnectionPolicy(cosmosClientBuilder);
         assertThat(connectionPolicy.getConnectionMode()).isEqualTo(ConnectionMode.DIRECT);
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
index bb535b2cdd888..0a94787acaacf 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
@@ -3,6 +3,7 @@
 
 package com.azure.cosmos.implementation;
 
+import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.DirectConnectionConfig;
 import com.azure.cosmos.GatewayConnectionConfig;
@@ -27,23 +28,15 @@ public void validateStrongConsistencyOnSyncReplication() throws Exception {
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.STRONG)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.STRONG)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
         User userDefinition = getUserDefinition();
         userDefinition.setId(userDefinition.getId() + "validateStrongConsistencyOnSyncReplication");
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), userDefinition);
@@ -56,42 +49,30 @@ public void validateConsistentLSNForDirectTCPClient() {
         //TODO Need to test with TCP protocol
         // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
         validateConsistentLSN();
     }
 
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateConsistentLSNForDirectHttpsClient() {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
         validateConsistentLSN();
     }
 
@@ -100,21 +81,15 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectTCPClient() {
         //TODO Need to test with TCP protocol
         //https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
 
@@ -139,21 +114,15 @@ public void validateBoundedStalenessDynamicQuorumSyncReplication() {
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateConsistentLSNAndQuorumAckedLSNForDirectHttpsClient() {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withContentResponseOnWriteEnabled(true).build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
 
@@ -187,23 +156,15 @@ public void validateConsistentPrefixOnSyncReplication() throws InterruptedExcept
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS).withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS).withContentResponseOnWriteEnabled(true).build();
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), getUserDefinition());
         boolean readLagging = validateConsistentPrefix(user);
         assertThat(readLagging).isFalse();
@@ -216,23 +177,17 @@ public void validateConsistentPrefixOnAsyncReplication() throws InterruptedExcep
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                .withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                .withContentResponseOnWriteEnabled(true).build();
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.initClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
         boolean readLagging = validateConsistentPrefix(document);
@@ -274,14 +229,11 @@ private void validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(boolean
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        AsyncDocumentClient client =
-                new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        AsyncDocumentClient client = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION)
+                .withContentResponseOnWriteEnabled(true).build();
         try {
             DocumentCollection documentCollection = new DocumentCollection();
             documentCollection.setId(UUID.randomUUID().toString());
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
index 62ebaa931ebf3..e18b7b9037a79 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
@@ -30,23 +30,15 @@ public class ConsistencyTests2 extends ConsistencyTestsBase {
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateReadSessionOnAsyncReplication() throws InterruptedException {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
                                                            null, false).block().getResource();
@@ -58,23 +50,15 @@ public void validateReadSessionOnAsyncReplication() throws InterruptedException
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateWriteSessionOnAsyncReplication() throws InterruptedException {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
                                                            null, false).block().getResource();
@@ -172,23 +156,17 @@ public void validateSessionTokenFromCollectionReplaceIsServerToken() {
     public void validateNoChargeOnFailedSessionRead() throws Exception {
         // DIRECT clients for read and write operations
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         // Client locked to replica for pause/resume
-        RxDocumentClientImpl readSecondaryClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl readSecondaryClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         try {
             // CREATE collection
             DocumentCollection parentResource = writeClient.createCollection(createdDatabase.getSelfLink(),
@@ -238,14 +216,11 @@ public void validateSessionTokenAsync() {
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        RxDocumentClientImpl client =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl client = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
 
         try {
             Document lastDocument = client.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
index dca0069c20026..9d4650d262bd8 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
@@ -118,23 +118,15 @@ void validateStrongConsistencyOnAsyncReplication(boolean useGateway) throws Inte
             connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
         }
 
-        this.writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.STRONG)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
 
-        this.readClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.STRONG)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
 
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.writeClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
@@ -166,14 +158,10 @@ void validateSessionContainerAfterCollectionCreateReplace(boolean useGateway) {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
 
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
 
         try {
             PartitionKeyDefinition partitionKey = new PartitionKeyDefinition();
@@ -376,22 +364,16 @@ void validateSessionContainerAfterCollectionDeletion(boolean useGateway) throws
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl client1 =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-        RxDocumentClientImpl client2 =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
+        RxDocumentClientImpl client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
 
         String collectionId = UUID.randomUUID().toString();
         try {
@@ -513,22 +495,16 @@ void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exce
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-        RxDocumentClientImpl validationClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
+        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         try {
             // write a document, and upsert to it to update etag.
             ResourceResponse documentResponse = writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, true).block();
@@ -560,22 +536,16 @@ void validateSessionTokenWithDocumentNotFoundException(boolean useGateway) throw
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-        RxDocumentClientImpl validationClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
+        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         try {
             DocumentCollection collectionDefinition = getCollectionDefinition();
             collectionDefinition.setId("TestCollection");
@@ -602,14 +572,11 @@ void validateSessionTokenWithExpectedException(boolean useGateway) throws Except
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         try {
             ResourceResponse documentResponse =
                     writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, false).block();
@@ -638,22 +605,16 @@ void validateSessionTokenWithConflictException(boolean useGateway) {
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
-        RxDocumentClientImpl validationClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
+        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         try {
             Document documentDefinition = getDocumentDefinition();
             ResourceResponse documentResponse =
@@ -677,14 +638,11 @@ void validateSessionTokenMultiPartitionCollection(boolean useGateway) throws Exc
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         try {
 
             Range fullRange = new Range(PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey,
@@ -759,14 +717,11 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl client1 =
-                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                        .withServiceEndpoint(TestConfigurations.HOST)
-                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                        .withConnectionPolicy(connectionPolicy)
-                        .withConsistencyLevel(ConsistencyLevel.SESSION)
-                        .withContentResponseOnWriteEnabled(true)
-                        .build();
+        RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                .build();
         RxDocumentClientImpl client2 = null;
         try {
             Document doc = client1.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, true).block().getResource();
@@ -775,14 +730,11 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
             Document doc1 = client1.readDocument(BridgeInternal.getAltLink(doc), requestOptions).block().getResource();
 
             String token1 = ((SessionContainer) client1.getSession()).getSessionToken(createdCollection.getSelfLink());
-            client2 =
-                    (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
-                            .withServiceEndpoint(TestConfigurations.HOST)
-                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                            .withConnectionPolicy(connectionPolicy)
-                            .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .withContentResponseOnWriteEnabled(true)
-                            .build();
+            client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                    .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                    .withConnectionPolicy(connectionPolicy)
+                    .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                    .build();
             client2.replaceCollection(createdCollection, null).block();
             String token2 = ((SessionContainer) client2.getSession()).getSessionToken(createdCollection.getSelfLink());
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
index a0852bbaba970..c9a16bfbdaced 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
@@ -904,12 +904,10 @@ static protected Builder createGatewayHouseKeepingDocumentClient() {
         options.setMaxRetryWaitTime(Duration.ofSeconds(SUITE_SETUP_TIMEOUT));
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(gatewayConnectionConfig);
         connectionPolicy.setThrottlingRetryOptions(options);
-        return new Builder()
-                .withServiceEndpoint(TestConfigurations.HOST)
+        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION)
-                .withContentResponseOnWriteEnabled(true);
+                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true);
     }
 
     static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List preferredLocations, boolean contentResponseOnWriteEnabled) {
@@ -917,12 +915,11 @@ static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consiste
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(gatewayConnectionConfig);
         connectionPolicy.setMultipleWriteRegionsEnabled(multiMasterEnabled);
         connectionPolicy.setPreferredRegions(preferredLocations);
-        return new Builder()
-                .withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(consistencyLevel)
-                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
+        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
+                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                            .withConnectionPolicy(connectionPolicy)
+                            .withConsistencyLevel(consistencyLevel)
+                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
     }
 
     static protected Builder createGatewayRxDocumentClient() {
@@ -947,13 +944,12 @@ static protected Builder createDirectRxDocumentClient(ConsistencyLevel consisten
         Configs configs = Mockito.spy(new Configs());
         doAnswer((Answer)invocation -> protocol).when(configs).getProtocol();
 
-        return new Builder()
-                .withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(consistencyLevel)
-                .withConfigs(configs)
-                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
+        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
+                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                            .withConnectionPolicy(connectionPolicy)
+                            .withConsistencyLevel(consistencyLevel)
+                            .withConfigs(configs)
+                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
     }
 
     protected int expectedNumberOfPages(int totalExpectedResult, int maxPageSize) {
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java
index c864bac80fb9c..d4a3042ef7689 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/ReflectionUtils.java
@@ -186,10 +186,6 @@ public static void buildConnectionPolicy(CosmosClientBuilder cosmosClientBuilder
         invokeMethod(CosmosClientBuilder.class, cosmosClientBuilder, "buildConnectionPolicy");
     }
 
-    public static void buildClientTelemetryConfig(CosmosClientBuilder cosmosClientBuilder) {
-        invokeMethod(CosmosClientBuilder.class, cosmosClientBuilder, "buildClientTelemetryConfig");
-    }
-
     public static UserAgentContainer getUserAgentContainer(RxDocumentClientImpl rxDocumentClient) {
         return get(UserAgentContainer.class, rxDocumentClient, "userAgentContainer");
     }
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
index 4ea8cc1c418f2..4daca069ea51e 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
@@ -255,13 +255,9 @@ public void readCollectionFromPermissionFeed(String collectionUrl, Permission pe
         try {
             List permissionFeed = new ArrayList<>();
             permissionFeed.add(permission);
-            asyncClientResourceToken =
-                    new AsyncDocumentClient.Builder()
-                            .withServiceEndpoint(TestConfigurations.HOST)
-                            .withPermissionFeed(permissionFeed)
-                            .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
-                            .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .build();
+            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                    .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
+                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
             Mono> readObservable = asyncClientResourceToken
                     .readCollection(collectionUrl, null);
 
@@ -286,13 +282,9 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
             permissionFeed.add(permission);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken =
-                    new AsyncDocumentClient.Builder()
-                            .withServiceEndpoint(TestConfigurations.HOST)
-                            .withPermissionFeed(permissionFeed)
-                            .withConnectionPolicy(defaultPolicy)
-                            .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .build();
+            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
+                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
             RequestOptions options = new RequestOptions();
             if (StringUtils.isNotEmpty(partitionKey)) {
                 options.setPartitionKey(new PartitionKey(partitionKey));
@@ -318,13 +310,10 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
     public void readDocumentFromResouceToken(String resourceToken) throws Exception {
         AsyncDocumentClient asyncClientResourceToken = null;
         try {
-            asyncClientResourceToken =
-                    new AsyncDocumentClient.Builder()
-                            .withServiceEndpoint(TestConfigurations.HOST)
-                            .withMasterKeyOrResourceToken(resourceToken)
-                            .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
-                            .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .build();
+            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                    .withMasterKeyOrResourceToken(resourceToken)
+                    .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy()).withConsistencyLevel(ConsistencyLevel.SESSION)
+                    .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(PartitionKey.NONE);
             Mono> readObservable = asyncClientResourceToken
@@ -351,13 +340,9 @@ public void readDocumentOfParKeyFromTwoCollPermissionWithDiffPartitionKeys(Strin
             permissionFeed.add(collPermission2);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken =
-                    new AsyncDocumentClient.Builder()
-                            .withServiceEndpoint(TestConfigurations.HOST)
-                            .withPermissionFeed(permissionFeed)
-                            .withConnectionPolicy(defaultPolicy)
-                            .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .build();
+            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
+                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
             Mono> readObservable = asyncClientResourceToken
@@ -384,13 +369,9 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_ResourceNotFound(
             permissionFeed.add(permission);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken =
-                    new AsyncDocumentClient.Builder()
-                            .withServiceEndpoint(TestConfigurations.HOST)
-                            .withPermissionFeed(permissionFeed)
-                            .withConnectionPolicy(defaultPolicy)
-                            .withConsistencyLevel(ConsistencyLevel.SESSION)
-                            .build();
+            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
+                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
             Mono> readObservable = asyncClientResourceToken

From 36aa6ca1f9b6890db86499d6ebd854ee887ae6af Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Wed, 25 May 2022 17:47:15 -0700
Subject: [PATCH 11/12] add the tests change back

---
 .../com/azure/cosmos/benchmark/Utils.java     |   2 +
 .../implementation/ConsistencyTests1.java     | 205 ++++++++++++------
 .../implementation/ConsistencyTests2.java     |  98 ++++++---
 .../implementation/ConsistencyTestsBase.java  | 198 +++++++++++------
 .../GoneAndRetryPolicyWithSpyClientTest.java  |   3 +-
 .../implementation/RetryThrottleTest.java     |   3 +-
 .../cosmos/implementation/TestSuiteBase.java  |  23 +-
 .../BarrierRequestHelperTest.java             |   1 +
 .../DCDocumentCrudTest.java                   |   4 +-
 .../azure/cosmos/rx/ResourceTokenTest.java    |  59 +++--
 10 files changed, 396 insertions(+), 200 deletions(-)

diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
index 62b64b5fa961e..38c620fa8a1ec 100644
--- a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
+++ b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/Utils.java
@@ -6,6 +6,7 @@
 import com.azure.cosmos.DirectConnectionConfig;
 import com.azure.cosmos.ThrottlingRetryOptions;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
 import com.azure.cosmos.implementation.DatabaseForTest;
@@ -31,6 +32,7 @@ public static AsyncDocumentClient housekeepingClient() {
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withConnectionPolicy(connectionPolicy)
                         .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
                         .build();
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
index 0a94787acaacf..c52826d202133 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests1.java
@@ -3,7 +3,6 @@
 
 package com.azure.cosmos.implementation;
 
-import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.DirectConnectionConfig;
 import com.azure.cosmos.GatewayConnectionConfig;
@@ -28,15 +27,25 @@ public void validateStrongConsistencyOnSyncReplication() throws Exception {
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         User userDefinition = getUserDefinition();
         userDefinition.setId(userDefinition.getId() + "validateStrongConsistencyOnSyncReplication");
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), userDefinition);
@@ -49,30 +58,46 @@ public void validateConsistentLSNForDirectTCPClient() {
         //TODO Need to test with TCP protocol
         // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         validateConsistentLSN();
     }
 
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateConsistentLSNForDirectHttpsClient() {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         validateConsistentLSN();
     }
 
@@ -81,15 +106,23 @@ public void validateConsistentLSNAndQuorumAckedLSNForDirectTCPClient() {
         //TODO Need to test with TCP protocol
         //https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
 
@@ -114,15 +147,23 @@ public void validateBoundedStalenessDynamicQuorumSyncReplication() {
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateConsistentLSNAndQuorumAckedLSNForDirectHttpsClient() {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         validateConsistentLSNAndQuorumAckedLSN();
     }
 
@@ -156,15 +197,25 @@ public void validateConsistentPrefixOnSyncReplication() throws InterruptedExcept
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         User user = safeCreateUser(this.initClient, createdDatabase.getId(), getUserDefinition());
         boolean readLagging = validateConsistentPrefix(user);
         assertThat(readLagging).isFalse();
@@ -177,17 +228,25 @@ public void validateConsistentPrefixOnAsyncReplication() throws InterruptedExcep
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                .withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
-                .withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.BOUNDED_STALENESS)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.initClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
         boolean readLagging = validateConsistentPrefix(document);
@@ -229,11 +288,15 @@ private void validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(boolean
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        AsyncDocumentClient client = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION)
-                .withContentResponseOnWriteEnabled(true).build();
+        AsyncDocumentClient client =
+                new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
             DocumentCollection documentCollection = new DocumentCollection();
             documentCollection.setId(UUID.randomUUID().toString());
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
index e18b7b9037a79..0ee7bc152e1c5 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTests2.java
@@ -30,15 +30,25 @@ public class ConsistencyTests2 extends ConsistencyTestsBase {
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateReadSessionOnAsyncReplication() throws InterruptedException {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
                                                            null, false).block().getResource();
@@ -50,15 +60,25 @@ public void validateReadSessionOnAsyncReplication() throws InterruptedException
     @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT)
     public void validateWriteSessionOnAsyncReplication() throws InterruptedException {
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
-
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
 
         Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
                                                            null, false).block().getResource();
@@ -156,17 +176,25 @@ public void validateSessionTokenFromCollectionReplaceIsServerToken() {
     public void validateNoChargeOnFailedSessionRead() throws Exception {
         // DIRECT clients for read and write operations
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         // Client locked to replica for pause/resume
-        RxDocumentClientImpl readSecondaryClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl readSecondaryClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
             // CREATE collection
             DocumentCollection parentResource = writeClient.createCollection(createdDatabase.getSelfLink(),
@@ -216,11 +244,15 @@ public void validateSessionTokenAsync() {
         }
 
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
-        RxDocumentClientImpl client = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl client =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
 
         try {
             Document lastDocument = client.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(),
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
index 9d4650d262bd8..7f70fdc433d5c 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java
@@ -118,15 +118,25 @@ void validateStrongConsistencyOnAsyncReplication(boolean useGateway) throws Inte
             connectionPolicy = new ConnectionPolicy(GatewayConnectionConfig.getDefaultConfig());
         }
 
-        this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+        this.writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
 
-        this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.STRONG).withContentResponseOnWriteEnabled(true).build();
+        this.readClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.STRONG)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
 
         Document documentDefinition = getDocumentDefinition();
         Document document = createDocument(this.writeClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition);
@@ -158,10 +168,15 @@ void validateSessionContainerAfterCollectionCreateReplace(boolean useGateway) {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
 
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true).build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
 
         try {
             PartitionKeyDefinition partitionKey = new PartitionKeyDefinition();
@@ -364,16 +379,23 @@ void validateSessionContainerAfterCollectionDeletion(boolean useGateway) throws
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl client1 =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+        RxDocumentClientImpl client2 =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .build();
 
         String collectionId = UUID.randomUUID().toString();
         try {
@@ -495,16 +517,24 @@ void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exce
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+        RxDocumentClientImpl validationClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
             // write a document, and upsert to it to update etag.
             ResourceResponse documentResponse = writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, true).block();
@@ -536,16 +566,24 @@ void validateSessionTokenWithDocumentNotFoundException(boolean useGateway) throw
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
+        RxDocumentClientImpl validationClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
             DocumentCollection collectionDefinition = getCollectionDefinition();
             collectionDefinition.setId("TestCollection");
@@ -572,11 +610,15 @@ void validateSessionTokenWithExpectedException(boolean useGateway) throws Except
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
             ResourceResponse documentResponse =
                     writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, false).block();
@@ -605,16 +647,23 @@ void validateSessionTokenWithConflictException(boolean useGateway) {
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
-        RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .build();
+        RxDocumentClientImpl validationClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
             Document documentDefinition = getDocumentDefinition();
             ResourceResponse documentResponse =
@@ -638,11 +687,15 @@ void validateSessionTokenMultiPartitionCollection(boolean useGateway) throws Exc
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl writeClient =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         try {
 
             Range fullRange = new Range(PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey,
@@ -717,11 +770,15 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
         } else {
             connectionPolicy = new ConnectionPolicy(DirectConnectionConfig.getDefaultConfig());
         }
-        RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
-                .build();
+        RxDocumentClientImpl client1 =
+                (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                        .withServiceEndpoint(TestConfigurations.HOST)
+                        .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                        .withConnectionPolicy(connectionPolicy)
+                        .withConsistencyLevel(ConsistencyLevel.SESSION)
+                        .withContentResponseOnWriteEnabled(true)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                        .build();
         RxDocumentClientImpl client2 = null;
         try {
             Document doc = client1.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, true).block().getResource();
@@ -730,10 +787,13 @@ void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway)
             Document doc1 = client1.readDocument(BridgeInternal.getAltLink(doc), requestOptions).block().getResource();
 
             String token1 = ((SessionContainer) client1.getSession()).getSessionToken(createdCollection.getSelfLink());
-            client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
+            client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder()
+                    .withServiceEndpoint(TestConfigurations.HOST)
                     .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                     .withConnectionPolicy(connectionPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true)
+                    .withConsistencyLevel(ConsistencyLevel.SESSION)
+                    .withContentResponseOnWriteEnabled(true)
+                    .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
                     .build();
             client2.replaceCollection(createdCollection, null).block();
             String token2 = ((SessionContainer) client2.getSession()).getSessionToken(createdCollection.getSelfLink());
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
index d7fc693572f0b..0ed1f4acb48b4 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/GoneAndRetryPolicyWithSpyClientTest.java
@@ -69,7 +69,8 @@ static Builder createDCBuilder(Protocol protocol) {
             .withConnectionPolicy(connectionPolicy)
             .withConsistencyLevel(ConsistencyLevel.SESSION)
             .withContentResponseOnWriteEnabled(true)
-            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY);
+            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig());
     }
 
     @Factory(dataProvider = "directClientBuilder")
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
index e77a9fcaa7677..b47d60e262c47 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryThrottleTest.java
@@ -48,7 +48,8 @@ public void retryCreateDocumentsOnSpike() throws Exception {
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(policy)
                 .withConsistencyLevel(ConsistencyLevel.EVENTUAL)
-                .withContentResponseOnWriteEnabled(true);
+                .withContentResponseOnWriteEnabled(true)
+                .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig());
 
         client = SpyClientUnderTestFactory.createClientWithGatewaySpy(builder);
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
index c9a16bfbdaced..1246b138f9e5d 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java
@@ -904,10 +904,13 @@ static protected Builder createGatewayHouseKeepingDocumentClient() {
         options.setMaxRetryWaitTime(Duration.ofSeconds(SUITE_SETUP_TIMEOUT));
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(gatewayConnectionConfig);
         connectionPolicy.setThrottlingRetryOptions(options);
-        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
+        return new Builder()
+                .withServiceEndpoint(TestConfigurations.HOST)
                 .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                 .withConnectionPolicy(connectionPolicy)
-                .withConsistencyLevel(ConsistencyLevel.SESSION).withContentResponseOnWriteEnabled(true);
+                .withConsistencyLevel(ConsistencyLevel.SESSION)
+                .withContentResponseOnWriteEnabled(true)
+                .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig());
     }
 
     static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List preferredLocations, boolean contentResponseOnWriteEnabled) {
@@ -915,11 +918,13 @@ static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consiste
         ConnectionPolicy connectionPolicy = new ConnectionPolicy(gatewayConnectionConfig);
         connectionPolicy.setMultipleWriteRegionsEnabled(multiMasterEnabled);
         connectionPolicy.setPreferredRegions(preferredLocations);
-        return new Builder().withServiceEndpoint(TestConfigurations.HOST)
-                            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
-                            .withConnectionPolicy(connectionPolicy)
-                            .withConsistencyLevel(consistencyLevel)
-                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
+        return new Builder()
+                .withServiceEndpoint(TestConfigurations.HOST)
+                .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+                .withConnectionPolicy(connectionPolicy)
+                .withConsistencyLevel(consistencyLevel)
+                .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled)
+                .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig());
     }
 
     static protected Builder createGatewayRxDocumentClient() {
@@ -949,7 +954,9 @@ static protected Builder createDirectRxDocumentClient(ConsistencyLevel consisten
                             .withConnectionPolicy(connectionPolicy)
                             .withConsistencyLevel(consistencyLevel)
                             .withConfigs(configs)
-                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled);
+                            .withContentResponseOnWriteEnabled(contentResponseOnWriteEnabled)
+                            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig());
+
     }
 
     protected int expectedNumberOfPages(int totalExpectedResult, int maxPageSize) {
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
index 12d1b024ca04e..5fda02545ee8f 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java
@@ -237,6 +237,7 @@ private IAuthorizationTokenProvider getIAuthorizationTokenProvider() {
                 new AsyncDocumentClient.Builder()
                         .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
                         .withServiceEndpoint(TestConfigurations.HOST)
+                        .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
                         .build();
     }
 
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
index 6cb23e4fbdf9f..34c395767b6c9 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/DCDocumentCrudTest.java
@@ -6,6 +6,7 @@
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.DirectConnectionConfig;
 import com.azure.cosmos.implementation.AsyncDocumentClient.Builder;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.Configs;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
@@ -80,7 +81,8 @@ static Builder createDCBuilder(Protocol protocol) {
             .withConnectionPolicy(connectionPolicy)
             .withConsistencyLevel(ConsistencyLevel.SESSION)
             .withContentResponseOnWriteEnabled(true)
-            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY);
+            .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
+            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig());
     }
 
     @Factory(dataProvider = "directClientBuilder")
diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
index 4daca069ea51e..bc0cf881e7435 100644
--- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
+++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ResourceTokenTest.java
@@ -5,6 +5,7 @@
 import com.azure.cosmos.ConnectionMode;
 import com.azure.cosmos.ConsistencyLevel;
 import com.azure.cosmos.implementation.AsyncDocumentClient;
+import com.azure.cosmos.implementation.ClientTelemetryConfig;
 import com.azure.cosmos.implementation.ConnectionPolicy;
 import com.azure.cosmos.implementation.Database;
 import com.azure.cosmos.implementation.DatabaseForTest;
@@ -255,9 +256,14 @@ public void readCollectionFromPermissionFeed(String collectionUrl, Permission pe
         try {
             List permissionFeed = new ArrayList<>();
             permissionFeed.add(permission);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                            .build();
             Mono> readObservable = asyncClientResourceToken
                     .readCollection(collectionUrl, null);
 
@@ -282,9 +288,14 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
             permissionFeed.add(permission);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(defaultPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                            .build();
             RequestOptions options = new RequestOptions();
             if (StringUtils.isNotEmpty(partitionKey)) {
                 options.setPartitionKey(new PartitionKey(partitionKey));
@@ -310,10 +321,14 @@ public void readDocumentFromPermissionFeed(String documentUrl, Permission permis
     public void readDocumentFromResouceToken(String resourceToken) throws Exception {
         AsyncDocumentClient asyncClientResourceToken = null;
         try {
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withMasterKeyOrResourceToken(resourceToken)
-                    .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy()).withConsistencyLevel(ConsistencyLevel.SESSION)
-                    .build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withMasterKeyOrResourceToken(resourceToken)
+                            .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                            .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(PartitionKey.NONE);
             Mono> readObservable = asyncClientResourceToken
@@ -340,9 +355,14 @@ public void readDocumentOfParKeyFromTwoCollPermissionWithDiffPartitionKeys(Strin
             permissionFeed.add(collPermission2);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(defaultPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                            .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
             Mono> readObservable = asyncClientResourceToken
@@ -369,9 +389,14 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_ResourceNotFound(
             permissionFeed.add(permission);
             ConnectionPolicy defaultPolicy = ConnectionPolicy.getDefaultPolicy();
             defaultPolicy.setConnectionMode(ConnectionMode.GATEWAY);
-            asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
-                    .withPermissionFeed(permissionFeed).withConnectionPolicy(defaultPolicy)
-                    .withConsistencyLevel(ConsistencyLevel.SESSION).build();
+            asyncClientResourceToken =
+                    new AsyncDocumentClient.Builder()
+                            .withServiceEndpoint(TestConfigurations.HOST)
+                            .withPermissionFeed(permissionFeed)
+                            .withConnectionPolicy(defaultPolicy)
+                            .withConsistencyLevel(ConsistencyLevel.SESSION)
+                            .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
+                            .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(partitionKey));
             Mono> readObservable = asyncClientResourceToken
@@ -400,6 +425,7 @@ public void readDocumentFromCollPermissionWithDiffPartitionKey_WithException() t
                 .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
                 .withPermissionFeed(permissionFeed)
+                .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
                 .build();
             RequestOptions options = new RequestOptions();
             options.setPartitionKey(new PartitionKey(PARTITION_KEY_VALUE_2));
@@ -425,6 +451,7 @@ public void queryItemFromResourceToken(DocumentCollection documentCollection, Pe
                 .withConnectionPolicy(ConnectionPolicy.getDefaultPolicy())
                 .withConsistencyLevel(ConsistencyLevel.SESSION)
                 .withMasterKeyOrResourceToken(permission.getToken())
+                .withClientTelemetryConfig(ClientTelemetryConfig.getDefaultConfig())
                 .build();
 
             CosmosQueryRequestOptions queryRequestOptions = new CosmosQueryRequestOptions();

From e44ab42f925badc379a7a601aa5a8f10c08dbffa Mon Sep 17 00:00:00 2001
From: annie-mac 
Date: Thu, 26 May 2022 12:06:30 -0700
Subject: [PATCH 12/12] resolve comments

---
 .../linkedin/data/ClientTelemetrySampleTest.java       |  1 +
 sdk/cosmos/azure-cosmos/CHANGELOG.md                   |  1 -
 .../cosmos/implementation/ClientTelemetryConfig.java   | 10 ++++------
 .../java/com/azure/cosmos/implementation/Configs.java  |  3 +++
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/linkedin/data/ClientTelemetrySampleTest.java b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/linkedin/data/ClientTelemetrySampleTest.java
index 5d005f429cd20..c47b3bd77b731 100644
--- a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/linkedin/data/ClientTelemetrySampleTest.java
+++ b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/linkedin/data/ClientTelemetrySampleTest.java
@@ -31,6 +31,7 @@ private void enableClientTelemetry() {
         String clientTelemetryStagingEndpoint = "https://tools-staging.cosmos.azure.com/api/clienttelemetry/trace/";
         String clientTelemetryTestEndpoint = "https://juno-test.documents-dev.windows-int.net/api/clienttelemetry/trace/";
         System.setProperty("COSMOS.CLIENT_TELEMETRY_ENDPOINT", clientTelemetryStagingEndpoint);
+        System.setProperty("COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG", "{\"type\":\"HTTP\", \"host\": \"localhost\", \"port\": 8080}");
 
         CosmosClient cosmosClient = new CosmosClientBuilder()
             .endpoint(TestConfigurations.HOST)
diff --git a/sdk/cosmos/azure-cosmos/CHANGELOG.md b/sdk/cosmos/azure-cosmos/CHANGELOG.md
index d3d82ff97cf82..d975a9d8890be 100644
--- a/sdk/cosmos/azure-cosmos/CHANGELOG.md
+++ b/sdk/cosmos/azure-cosmos/CHANGELOG.md
@@ -9,7 +9,6 @@
 #### Bugs Fixed
 
 #### Other Changes
-* Added support for config Proxy for `ClientTelemetry` - See [PR 29022](https://github.com/Azure/azure-sdk-for-java/pull/29022)
 
 ### 4.30.0 (2022-05-20)
 #### Bugs Fixed
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
index c6f760f8cf716..7b2295739da3d 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientTelemetryConfig.java
@@ -68,7 +68,7 @@ private ProxyOptions getProxyOptions() {
 
         if (StringUtils.isNotEmpty(config)) {
             try {
-                ProxyOptionsConfig proxyOptionsConfig = Utils.getSimpleObjectMapper().readValue(config, ProxyOptionsConfig.class);
+                JsonProxyOptionsConfig proxyOptionsConfig = Utils.getSimpleObjectMapper().readValue(config, JsonProxyOptionsConfig.class);
                 ProxyOptions.Type type = ProxyOptions.Type.valueOf(proxyOptionsConfig.type);
 
                 if (type != ProxyOptions.Type.HTTP) {
@@ -84,8 +84,6 @@ private ProxyOptions getProxyOptions() {
                 }
 
                 return new ProxyOptions(type, new InetSocketAddress(proxyOptionsConfig.host, proxyOptionsConfig.port));
-            } catch (JsonMappingException e) {
-                logger.error("Failed to parse client telemetry proxy option config", e);
             } catch (JsonProcessingException e) {
                 logger.error("Failed to parse client telemetry proxy option config", e);
             }
@@ -94,7 +92,7 @@ private ProxyOptions getProxyOptions() {
         return null;
     }
 
-    private static class ProxyOptionsConfig {
+    private static class JsonProxyOptionsConfig {
         @JsonProperty
         private String host;
         @JsonProperty
@@ -102,8 +100,8 @@ private static class ProxyOptionsConfig {
         @JsonProperty
         private String type;
 
-        private ProxyOptionsConfig() {}
-        private ProxyOptionsConfig(String host, int port, String type) {
+        private JsonProxyOptionsConfig() {}
+        private JsonProxyOptionsConfig(String host, int port, String type) {
             this.host = host;
             this.port = port;
             this.type = type;
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
index fc8ba88604d79..1d191bd26253b 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java
@@ -42,6 +42,9 @@ public class Configs {
     private static final String QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.QUERY_PLAN_RESPONSE_TIMEOUT_IN_SECONDS";
     private static final String ADDRESS_REFRESH_RESPONSE_TIMEOUT_IN_SECONDS = "COSMOS.ADDRESS_REFRESH_RESPONSE_TIMEOUT_IN_SECONDS";
 
+    // Example for customer how to setup the proxy:
+    // System.setProperty(
+    //  "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG","{\"type\":\"HTTP\", \"host\": \"localhost\", \"port\": 8080}")
     private static final String CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG = "COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG";
     // In the future, the following two client telemetry related configs will be part of the database account info
     // Before that day comes, use JVM properties