Skip to content

Commit

Permalink
[Internal] Telemetry: Refactors to paramaterized for lazy materializa…
Browse files Browse the repository at this point in the history
…tion (#2839)

* Moving to string interpolation for lazy materialization

* Moving to paramaterized formatting

Co-authored-by: j82w <[email protected]>
Co-authored-by: kirankumarkolli <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2021
1 parent b1fba88 commit 5001696
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
29 changes: 15 additions & 14 deletions Microsoft.Azure.Cosmos/src/Telemetry/ClientTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public static ClientTelemetry CreateAndStartBackgroundTelemetry(DocumentClient d
DefaultTrace.TraceInformation("Initiating telemetry with background task.");

ClientTelemetry clientTelemetry = new ClientTelemetry(documentClient,
userAgent,
connectionMode,
authorizationTokenProvider,
diagnosticsHelper,
preferredRegions);
userAgent,
connectionMode,
authorizationTokenProvider,
diagnosticsHelper,
preferredRegions);

clientTelemetry.StartObserverTask();

Expand Down Expand Up @@ -117,7 +117,8 @@ private void StartObserverTask()
/// <returns>Async Task</returns>
private async Task EnrichAndSendAsync()
{
DefaultTrace.TraceInformation("Telemetry Job Started with Observing window : " + observingWindow);
DefaultTrace.TraceInformation("Telemetry Job Started with Observing window : {0}", observingWindow);

try
{
while (!this.cancellationTokenSource.IsCancellationRequested)
Expand Down Expand Up @@ -146,7 +147,7 @@ private async Task EnrichAndSendAsync()
if (this.cancellationTokenSource.IsCancellationRequested)
{
DefaultTrace.TraceInformation("Observer Task Cancelled.");
return;
break;
}

this.RecordSystemUtilization();
Expand All @@ -163,7 +164,7 @@ private async Task EnrichAndSendAsync()
}
catch (Exception ex)
{
DefaultTrace.TraceError("Exception in EnrichAndSendAsync() : " + ex.Message);
DefaultTrace.TraceError("Exception in EnrichAndSendAsync() : {0}", ex.Message);
}

DefaultTrace.TraceInformation("Telemetry Job Stopped.");
Expand Down Expand Up @@ -223,7 +224,7 @@ internal void Collect(CosmosDiagnostics cosmosDiagnostics,
}
catch (Exception ex)
{
DefaultTrace.TraceError("Latency Recording Failed by Telemetry. Exception : " + ex.Message);
DefaultTrace.TraceError("Latency Recording Failed by Telemetry. Exception : {0}", ex.Message);
}

long requestChargeToRecord = (long)(requestCharge * ClientTelemetryOptions.HistogramPrecisionFactor);
Expand All @@ -233,7 +234,7 @@ internal void Collect(CosmosDiagnostics cosmosDiagnostics,
}
catch (Exception ex)
{
DefaultTrace.TraceError("Request Charge Recording Failed by Telemetry. Request Charge Value : " + requestChargeToRecord + " Exception : " + ex.Message);
DefaultTrace.TraceError("Request Charge Recording Failed by Telemetry. Request Charge Value : {0} Exception : {1} ", requestChargeToRecord, ex.Message);
}
}

Expand Down Expand Up @@ -266,7 +267,7 @@ private void RecordSystemUtilization()
}
catch (Exception ex)
{
DefaultTrace.TraceError("System Usage Recording Error : " + ex.Message);
DefaultTrace.TraceError("System Usage Recording Error : {0}", ex.Message);
}
}

Expand All @@ -286,7 +287,7 @@ private async Task SendAsync()

try
{
DefaultTrace.TraceInformation("Sending Telemetry Data to " + endpointUrl.AbsoluteUri);
DefaultTrace.TraceInformation("Sending Telemetry Data to {0}", endpointUrl.AbsoluteUri);

string json = JsonConvert.SerializeObject(this.clientTelemetryInfo, ClientTelemetryOptions.JsonSerializerSettings);

Expand Down Expand Up @@ -329,7 +330,7 @@ await this.tokenProvider.AddAuthorizationHeaderAsync(

if (!response.IsSuccessStatusCode)
{
DefaultTrace.TraceError("Juno API response not successful. Status Code : " + response.StatusCode + ", Message : " + response.ReasonPhrase);
DefaultTrace.TraceError("Juno API response not successful. Status Code : {0}, Message : {1}", response.StatusCode, response.ReasonPhrase);
}
else
{
Expand All @@ -339,7 +340,7 @@ await this.tokenProvider.AddAuthorizationHeaderAsync(
}
catch (Exception ex)
{
DefaultTrace.TraceError("Exception while sending telemetry data : " + ex.Message);
DefaultTrace.TraceError("Exception while sending telemetry data : {0}", ex.Message);
}
finally
{
Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos/src/Telemetry/ClientTelemetryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static async Task<AccountProperties> SetAccountNameAsync(DocumentClient
}
catch (Exception ex)
{
DefaultTrace.TraceError("Exception while getting account information in client telemetry : " + ex.Message);
DefaultTrace.TraceError("Exception while getting account information in client telemetry : {0}", ex.Message);
}

return null;
Expand Down Expand Up @@ -79,7 +79,7 @@ static ValueTask<HttpRequestMessage> CreateRequestMessage()
}
catch (Exception ex)
{
DefaultTrace.TraceError("Exception in LoadAzureVmMetaDataAsync() " + ex.Message);
DefaultTrace.TraceError("Exception in LoadAzureVmMetaDataAsync() {0}", ex.Message);
}
}

Expand All @@ -106,7 +106,7 @@ internal static (SystemInfo cpuInfo, SystemInfo memoryInfo) RecordSystemUsage(Sy
return (null, null);
}

DefaultTrace.TraceInformation("System Usage recorded by telemetry is : " + systemUsageHistory);
DefaultTrace.TraceInformation("System Usage recorded by telemetry is : {0}", systemUsageHistory);

foreach (SystemUsageLoad systemUsage in systemUsageHistory.Values)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal static Uri GetClientTelemetryEndpoint()
clientTelemetryEndpoint = new Uri(uriProp);
}

DefaultTrace.TraceInformation("Telemetry Endpoint URL is " + uriProp);
DefaultTrace.TraceInformation("Telemetry Endpoint URL is {0}", uriProp);
}
return clientTelemetryEndpoint;
}
Expand Down

0 comments on commit 5001696

Please sign in to comment.