Skip to content

Commit

Permalink
[Internal]Add diagnostics cfg to CosmosClientBuilder logs (Azure#35454)
Browse files Browse the repository at this point in the history
* Added option to override the MicroBatchPayloadSize in bytes in Cosmos DB Spark connector

Added option to override the MicroBatchPayloadSize in bytes from Spark connector to accommodate better efficiency when documents are large > 110KB

* Update BulkWriter.scala

* Update BulkWriter.scala

* Fixing test build breaks

* Added changelog

* Update configuration-reference.md

* Changed the system usage in CosmodDiagnosticsContext to be a Map<string, String>

* Update CHANGELOG.md

* Update module-info.java

* Update module-info.java

* Update module-info.java

* Changing property bag to Map<String, Object>

* Adding diagnostics config to CosmosClientBuilder logs

* Update CosmosClientTelemetryConfig.java
  • Loading branch information
FabianMeiswinkel authored Jun 14, 2023
1 parent 9140d5b commit 5a78a64
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class CosmosClient implements Closeable {
private final CosmosAsyncClient asyncClientWrapper;

CosmosClient(CosmosClientBuilder builder) {
this.asyncClientWrapper = builder.buildAsyncClient();
this.asyncClientWrapper = builder.buildAsyncClient(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.azure.cosmos.implementation.Configs;
import com.azure.cosmos.implementation.ConnectionPolicy;
import com.azure.cosmos.implementation.CosmosClientMetadataCachesSnapshot;
import com.azure.cosmos.implementation.DiagnosticsProvider;
import com.azure.cosmos.implementation.ImplementationBridgeHelpers;
import com.azure.cosmos.implementation.WriteRetryPolicy;
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
Expand Down Expand Up @@ -958,6 +959,15 @@ public CosmosClientBuilder clientTelemetryConfig(CosmosClientTelemetryConfig tel
* @return CosmosAsyncClient
*/
public CosmosAsyncClient buildAsyncClient() {
return buildAsyncClient(true);
}

/**
* Builds a cosmos async client with the provided properties
*
* @return CosmosAsyncClient
*/
CosmosAsyncClient buildAsyncClient(boolean logStartupInfo) {
StopWatch stopwatch = new StopWatch();
stopwatch.start();
validateConfig();
Expand All @@ -980,7 +990,9 @@ public CosmosAsyncClient buildAsyncClient() {
cosmosAsyncClient.recordOpenConnectionsAndInitCachesCompleted(new ArrayList<>());
}

logStartupInfo(stopwatch, cosmosAsyncClient);
if (logStartupInfo) {
logStartupInfo(stopwatch, cosmosAsyncClient);
}
return cosmosAsyncClient;
}

Expand Down Expand Up @@ -1094,15 +1106,26 @@ private void logStartupInfo(StopWatch stopwatch, CosmosAsyncClient client) {

if (logger.isInfoEnabled()) {
long time = stopwatch.getTime();
String diagnosticsCfg = "";
String tracingCfg = "";
if (client.getClientTelemetryConfig() != null) {
diagnosticsCfg = client.getClientTelemetryConfig().toString();
}

DiagnosticsProvider provider = client.getDiagnosticsProvider();
if (provider != null) {
tracingCfg = provider.isEnabled() + ", " + provider.isRealTracer();
}

// NOTE: if changing the logging below - do not log any confidential info like master key credentials etc.
logger.info("Cosmos Client with (Correlation) ID [{}] started up in [{}] ms with the following " +
"configuration: serviceEndpoint [{}], preferredRegions [{}], connectionPolicy [{}], " +
"consistencyLevel [{}], contentResponseOnWriteEnabled [{}], sessionCapturingOverride [{}], " +
"connectionSharingAcrossClients [{}], clientTelemetryEnabled [{}], proactiveContainerInit [{}].",
"connectionSharingAcrossClients [{}], clientTelemetryEnabled [{}], proactiveContainerInit [{}], diagnostics [{}], tracing [{}]",
client.getContextClient().getClientCorrelationId(), time, getEndpoint(), getPreferredRegions(),
getConnectionPolicy(), getConsistencyLevel(), isContentResponseOnWriteEnabled(),
isSessionCapturingOverrideEnabled(), isConnectionSharingAcrossClientsEnabled(),
isClientTelemetryEnabled(), getProactiveContainerInitConfig());
isClientTelemetryEnabled(), getProactiveContainerInitConfig(), diagnosticsCfg, tracingCfg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ boolean isFailureCondition(int statusCode, int subStatusCode) {
}
}

@Override
public String toString() {
return "{" +
"pointOperationLatencyThreshold=" + this.pointOperationLatencyThreshold +
", nonPointOperationLatencyThreshold=" + this.nonPointOperationLatencyThreshold +
", requestChargeThreshold=" + this.requestChargeThreshold +
", payloadSizeInBytesThreshold=" + this.payloadSizeInBytesThreshold +
", customFailureHandler=" + (this.failureHandler != DEFAULT.failureHandler) +
"}";
}

///////////////////////////////////////////////////////////////////////////////////////////
// the following helper/accessor only helps to access this class outside of this package.//
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -414,6 +415,29 @@ public CosmosClientTelemetryConfig sampleDiagnostics(double samplingRate) {
return this;
}

@Override
public String toString() {

String handlers = "()";
if (!this.customDiagnosticHandlers.isEmpty()) {
handlers = "(" + this.customDiagnosticHandlers
.stream()
.map(h -> h.getClass().getCanonicalName())
.collect(Collectors.joining(", ")) + ")";
}

return "{" +
"samplingRate=" + this.samplingRate +
", thresholds=" + this.diagnosticsThresholds +
", clientCorrelationId=" + this.clientCorrelationId +
", clientTelemetryEnabled=" + this.effectiveIsClientTelemetryEnabled +
", clientMetricsEnabled=" + this.isClientMetricsEnabled +
", transportLevelTracingEnabled=" + this.isTransportLevelTracingEnabled +
", customTracerProvided=" + (this.tracer != null) +
", customDiagnosticHandlers=" + handlers +
"}";
}

Tracer getOrCreateTracer() {
if (this.tracer != null) {
return this.tracer;
Expand Down

0 comments on commit 5a78a64

Please sign in to comment.