Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" NoWarn="NU1903" PrivateAssets="All" />
</ItemGroup>

<!-- Code Analyzers -->
<ItemGroup>
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" NoWarn="NU1903" PrivateAssets="All" />
</ItemGroup>

<!-- Code Analyzers -->
<ItemGroup>
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.0.102" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

<!-- Code Analyzers -->
<ItemGroup>
<PackageReference Include="Microsoft.Codex.Analyzers" Version="1.0.5" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Condition=" '$(ProjectRef)' != 'True' ">
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
Expand Down
14 changes: 7 additions & 7 deletions Microsoft.Azure.Cosmos/src/Authorization/TokenCredentialCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ private async ValueTask<AccessToken> RefreshCachedTokenWithRetryHelperAsync(
lastException = requestFailedException;
getTokenTrace.AddDatum(
$"RequestFailedException at {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}",
requestFailedException);
requestFailedException.Message);

DefaultTrace.TraceError($"TokenCredential.GetToken() failed with RequestFailedException. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException}");
DefaultTrace.TraceError($"TokenCredential.GetToken() failed with RequestFailedException. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException.Message}");

// Don't retry on auth failures
if (requestFailedException.Status == (int)HttpStatusCode.Unauthorized ||
Expand All @@ -236,10 +236,10 @@ private async ValueTask<AccessToken> RefreshCachedTokenWithRetryHelperAsync(
lastException = operationCancelled;
getTokenTrace.AddDatum(
$"OperationCanceledException at {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}",
operationCancelled);
operationCancelled.Message);

DefaultTrace.TraceError(
$"TokenCredential.GetTokenAsync() failed. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException}");
$"TokenCredential.GetTokenAsync() failed. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException.Message}");

throw CosmosExceptionFactory.CreateRequestTimeoutException(
message: ClientResources.FailedToGetAadToken,
Expand All @@ -255,10 +255,10 @@ private async ValueTask<AccessToken> RefreshCachedTokenWithRetryHelperAsync(
lastException = exception;
getTokenTrace.AddDatum(
$"Exception at {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}",
exception);
exception.Message);

DefaultTrace.TraceError(
$"TokenCredential.GetTokenAsync() failed. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException}");
$"TokenCredential.GetTokenAsync() failed. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException.Message}");
}
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ private async void StartBackgroundTokenRefreshLoop()

DefaultTrace.TraceWarning(
"BackgroundTokenRefreshLoop() - Unable to refresh token credential cache. Exception: {0}",
ex.ToString());
ex.Message);

// Since it failed retry again in with half the token life span again.
if (!this.userDefinedBackgroundTokenCredentialRefreshInterval.HasValue && this.cachedAccessToken.HasValue)
Expand Down
10 changes: 6 additions & 4 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ private async Task OpenPrivateAsync(CancellationToken cancellationToken)
enableAsyncCacheExceptionNoSharing: this.enableAsyncCacheExceptionNoSharing);
this.partitionKeyRangeCache = new PartitionKeyRangeCache(this, this.GatewayStoreModel, this.collectionCache, this.GlobalEndpointManager, this.enableAsyncCacheExceptionNoSharing);

DefaultTrace.TraceWarning("{0} occurred while OpenAsync. Exception Message: {1}", ex.ToString(), ex.Message);
DefaultTrace.TraceWarning("Exception occurred while OpenAsync. Exception Message: {0}", ex.Message);
}
}

Expand Down Expand Up @@ -1030,7 +1030,9 @@ internal virtual void Initialize(Uri serviceEndpoint,
// UnobservedTaskException by using ContinueWith method w/ TaskContinuationOptions.OnlyOnFaulted
// and accessing the Exception property on the target task.
#pragma warning disable VSTHRD110 // Observe result of async calls
#pragma warning disable CDX1000 // DontConvertExceptionToObject
initTask.ContinueWith(t => DefaultTrace.TraceWarning("initializeTask failed {0}", t.Exception), TaskContinuationOptions.OnlyOnFaulted);
Comment thread
aavasthy marked this conversation as resolved.
#pragma warning restore CDX1000 // DontConvertExceptionToObject
#pragma warning restore VSTHRD110 // Observe result of async calls

this.traceId = Interlocked.Increment(ref DocumentClient.idCounter);
Expand Down Expand Up @@ -1355,7 +1357,7 @@ public void Dispose()
catch (Exception exception)
{
DefaultTrace.TraceWarning("Exception {0} thrown during dispose of HttpClient, this could happen if there are inflight request during the dispose of client",
exception);
exception.Message);
}

this.httpClient = null;
Expand Down Expand Up @@ -1623,8 +1625,8 @@ internal virtual async Task EnsureValidClientAsync(ITrace trace)
}
catch (Exception e)
{
DefaultTrace.TraceWarning("EnsureValidClientAsync initializeTask failed {0}", e);
childTrace.AddDatum("initializeTask failed", e);
DefaultTrace.TraceWarning("EnsureValidClientAsync initializeTask failed {0}", e.Message);
childTrace.AddDatum("initializeTask failed", e.Message);
throw;
}

Expand Down
8 changes: 4 additions & 4 deletions Microsoft.Azure.Cosmos/src/Telemetry/ClientTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ConcurrentDictionary<CacheRefreshInfo, LongConcurrentHistogram> cacheRefreshInfo
}
catch (Exception ex)
{
DefaultTrace.TraceError("Exception in EnrichAndSendAsync() : {0}", ex);
DefaultTrace.TraceError("Exception in EnrichAndSendAsync() : {0}", ex.Message);
}

DefaultTrace.TraceInformation("Telemetry Job Stopped.");
Expand Down Expand Up @@ -275,7 +275,7 @@ internal void PushCacheDatapoint(string cacheName, TelemetryInformation data)
}
catch (Exception ex)
{
DefaultTrace.TraceError("Latency Recording Failed by Telemetry. Exception : {0}", ex);
DefaultTrace.TraceError("Latency Recording Failed by Telemetry. Exception : {0}", ex.Message);
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ internal void PushOperationDatapoint(TelemetryInformation data)
}
catch (Exception ex)
{
DefaultTrace.TraceError("Latency Recording Failed by Telemetry. Exception : {0}", ex);
DefaultTrace.TraceError("Latency Recording Failed by Telemetry. Exception : {0}", ex.Message);
}

}
Expand All @@ -332,7 +332,7 @@ internal void PushOperationDatapoint(TelemetryInformation data)
}
catch (Exception ex)
{
DefaultTrace.TraceError("Request Charge Recording Failed by Telemetry. Request Charge Value : {0} Exception : {1} ", requestChargeToRecord, ex);
DefaultTrace.TraceError("Request Charge Recording Failed by Telemetry. Request Charge Value : {0} Exception : {1} ", requestChargeToRecord, ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal static List<SystemInfo> RecordSystemUtilization(DiagnosticsHandlerHelpe
}
catch (Exception ex)
{
DefaultTrace.TraceError("System Usage Recording Error : {0} ", ex);
DefaultTrace.TraceError("System Usage Recording Error : {0} ", ex.Message);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ await ClientTelemetryPayloadWriter.SerializedPayloadChunksAsync(
}
catch (Exception ex)
{
DefaultTrace.TraceError("Exception while serializing telemetry payload or sending data to service: {0}", ex);
DefaultTrace.TraceError("Exception while serializing telemetry payload or sending data to service: {0}", ex.Message);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void CollectCacheInfo(string cacheName, Func<TelemetryInformation> functi
}
catch (Exception ex)
{
DefaultTrace.TraceError("Error while collecting cache {0} telemetry. Exception : {1}", cacheName, ex);
DefaultTrace.TraceError("Error while collecting cache {0} telemetry. Exception : {1}", cacheName, ex.Message);
}
}

Expand All @@ -65,7 +65,7 @@ public void CollectOperationAndNetworkInfo(Func<TelemetryInformation> functionFo
}
catch (Exception ex)
{
DefaultTrace.TraceError("Error while collecting operation telemetry. Exception : {0}", ex);
DefaultTrace.TraceError("Error while collecting operation telemetry. Exception : {0}", ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public void PopulateAttributes(DiagnosticScope scope,

public void PopulateAttributes(DiagnosticScope scope, Exception exception)
{
#pragma warning disable CDX1002 // DontUseExceptionStackTrace
scope.AddAttribute(AppInsightClassicAttributeKeys.ExceptionStacktrace, exception.StackTrace);
Comment thread
aavasthy marked this conversation as resolved.
#pragma warning restore CDX1002 // DontUseExceptionStackTrace
scope.AddAttribute(AppInsightClassicAttributeKeys.ExceptionType, exception.GetType().Name);

// If Exception is not registered with open Telemetry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static void RecordHistogramMetric<T>(
}
catch (Exception ex)
{
DefaultTrace.TraceWarning($"Failed to record metric. {ex}");
DefaultTrace.TraceWarning($"Failed to record metric. {ex.Message}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal static void AdjustInstanceCount(Uri accountEndpoint, int adjustment)
}
catch (Exception ex)
{
DefaultTrace.TraceWarning($"Failed to adjust instance count. {ex.StackTrace}");
DefaultTrace.TraceWarning($"Failed to adjust instance count. {ex.Message}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ public void PopulateAttributes(DiagnosticScope scope,

public void PopulateAttributes(DiagnosticScope scope, Exception exception)
{
#pragma warning disable CDX1002 // DontUseExceptionStackTrace
scope.AddAttribute(OpenTelemetryAttributeKeys.ExceptionStacktrace, exception.StackTrace);
Comment thread
aavasthy marked this conversation as resolved.
#pragma warning restore CDX1002 // DontUseExceptionStackTrace
scope.AddAttribute(OpenTelemetryAttributeKeys.ExceptionType, exception.GetType().Name);

// If Exception is not registered with open Telemetry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static Headers GetHeader(TransactionalBatchResponse responseMessage)
}
catch (NotImplementedException ex)
{
DefaultTrace.TraceVerbose("Failed to get headers from TransactionalBatchResponse. Exception: {0}", ex);
DefaultTrace.TraceVerbose("Failed to get headers from TransactionalBatchResponse. Exception: {0}", ex.Message);
return null;
}
}
Expand All @@ -105,7 +105,7 @@ private static Headers GetHeader(ResponseMessage responseMessage)
}
catch (NotImplementedException ex)
{
DefaultTrace.TraceVerbose("Failed to get headers from ResponseMessage. Exception: {0}", ex);
DefaultTrace.TraceVerbose("Failed to get headers from ResponseMessage. Exception: {0}", ex.Message);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static Headers GetHeader(FeedResponse<T> responseMessage)
}
catch (NotImplementedException ex)
{
DefaultTrace.TraceWarning("Failed to get headers from FeedResponse<T>. Exception: {0}", ex);
DefaultTrace.TraceWarning("Failed to get headers from FeedResponse<T>. Exception: {0}", ex.Message);
return null;
}
}
Expand All @@ -87,7 +87,7 @@ private static Headers GetHeader(Response<T> responseMessage)
}
catch (NotImplementedException ex)
{
DefaultTrace.TraceWarning("Failed to get headers from Response<T>. Exception: {0}", ex);
DefaultTrace.TraceWarning("Failed to get headers from Response<T>. Exception: {0}", ex.Message);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private async Task RetrieveConfigAndInitiateTelemetryAsync(bool faultInjectionCl
}
else if (!this.cancellationTokenSource.IsCancellationRequested)
{
DefaultTrace.TraceWarning("Exception while calling client config {0} ", databaseAccountClientConfigs.Exception);
DefaultTrace.TraceWarning("Exception while calling client config {0} ", databaseAccountClientConfigs.Exception?.Message);
}

await Task.Delay(
Expand All @@ -125,7 +125,7 @@ await Task.Delay(
}
catch (Exception ex)
{
DefaultTrace.TraceWarning("Exception while running client config job: {0}", ex);
DefaultTrace.TraceWarning("Exception while running client config job: {0}", ex.Message);
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ private void InitializeClientTelemetry(AccountClientConfiguration clientConfig)
}
catch (Exception ex)
{
DefaultTrace.TraceWarning($"Error While starting Telemetry Job : {0}. Hence disabling Client Telemetry", ex);
DefaultTrace.TraceWarning($"Error While starting Telemetry Job : {0}. Hence disabling Client Telemetry", ex.Message);
this.connectionPolicy.CosmosClientTelemetryOptions.DisableSendingMetricsToService = true;
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ private void StopClientTelemetry()
}
catch (Exception ex)
{
DefaultTrace.TraceWarning("Error While stopping Telemetry Job : {0}", ex);
DefaultTrace.TraceWarning("Error While stopping Telemetry Job : {0}", ex.Message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/ThinClientStoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected override void Dispose(bool disposing)
catch (Exception exception)
{
DefaultTrace.TraceWarning("Exception {0} thrown during dispose of HttpClient, this could happen if there are inflight request during the dispose of client",
exception);
exception.Message);
}
this.thinClientStoreClient = null;
}
Expand Down
14 changes: 7 additions & 7 deletions Microsoft.Azure.Cosmos/src/Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal static ResponseMessage ToCosmosResponseMessage(this DocumentClientExcep
subStatusCode: cosmosException.Headers.SubStatusCode,
responseTimeUtc: DateTime.UtcNow,
requestCharge: cosmosException.Headers.RequestCharge,
errorMessage: documentClientException.ToString(),
errorMessage: documentClientException?.Message,
method: requestMessage?.Method,
requestUri: requestMessage?.RequestUriString,
requestSessionToken: requestMessage?.Headers?.Session,
Expand All @@ -160,7 +160,9 @@ internal static ResponseMessage ToCosmosResponseMessage(this DocumentClientExcep
if (requestMessage != null)
{
requestMessage.Properties.Remove(nameof(DocumentClientException));
#pragma warning disable CDX1000 // DontConvertExceptionToObject
requestMessage.Properties.Add(nameof(DocumentClientException), documentClientException);
#pragma warning restore CDX1000 // DontConvertExceptionToObject
}

return responseMessage;
Expand Down Expand Up @@ -202,21 +204,19 @@ private static void TraceExceptionInternal(Exception exception)
if (exception is SocketException socketException)
{
DefaultTrace.TraceWarning(
"Exception {0}: RequesteUri: {1}, SocketErrorCode: {2}, {3}, {4}",
"Exception {0}: RequesteUri: {1}, SocketErrorCode: {2}, {3}",
exception.GetType(),
requestUri,
socketException.SocketErrorCode,
exception.Message,
exception.StackTrace);
exception.Message);
}
else
{
DefaultTrace.TraceWarning(
"Exception {0}: RequestUri: {1}, {2}, {3}",
"Exception {0}: RequestUri: {1}, {2}",
exception.GetType(),
requestUri,
exception.Message,
exception.StackTrace);
exception.Message);
}

exception = exception.InnerException;
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/WebExceptionRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Task<ShouldRetryResult> ShouldRetryAsync(
this.currentBackoffSeconds *= WebExceptionRetryPolicy.backoffMultiplier;
}

DefaultTrace.TraceWarning("Received retriable web exception, will retry, {0}", exception);
DefaultTrace.TraceWarning("Received retriable web exception, will retry, {0}", exception.Message);

return Task.FromResult(ShouldRetryResult.RetryAfter(backoffTime));
}
Expand Down
Loading