Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview TraceWriter: Fixes Argument Null Exception / Null Reference Exception #2246

Merged
merged 3 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -158,7 +158,7 @@ public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTra
this.jsonWriter.WriteStringValue("PointOperationStatistics");

this.jsonWriter.WriteFieldName("ActivityId");
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.ActivityId);
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.ActivityId ?? "<null>");
bchong95 marked this conversation as resolved.
Show resolved Hide resolved

this.jsonWriter.WriteFieldName("ResponseTimeUtc");
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString("o", CultureInfo.InvariantCulture));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteStringValueOrNull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is after the diff.

Expand All @@ -173,7 +173,7 @@ public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTra
this.jsonWriter.WriteNumber64Value(pointOperationStatisticsTraceDatum.RequestCharge);

this.jsonWriter.WriteFieldName("RequestUri");
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.RequestUri);
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.RequestUri ?? "<null>");

if (!string.IsNullOrEmpty(pointOperationStatisticsTraceDatum.ErrorMessage))
{
Expand Down Expand Up @@ -250,7 +250,7 @@ private static void VisitAddressResolutionStatistics(
}

jsonWriter.WriteFieldName("TargetEndpoint");
jsonWriter.WriteStringValue(addressResolutionStatistics.TargetEndpoint);
jsonWriter.WriteStringValue(addressResolutionStatistics.TargetEndpoint ?? "<null>");

jsonWriter.WriteObjectEnd();
}
Expand All @@ -271,7 +271,7 @@ private static void VisitStoreResponseStatistics(
jsonWriter.WriteStringValue(storeResponseStatistics.RequestOperationType.ToString());

jsonWriter.WriteFieldName("LocationEndpoint");
jsonWriter.WriteStringValue(storeResponseStatistics.LocationEndpoint.ToString());
jsonWriter.WriteStringValue(storeResponseStatistics.LocationEndpoint?.ToString() ?? "<null>");

if (storeResponseStatistics.StoreResult != null)
{
Expand Down Expand Up @@ -301,7 +301,7 @@ private void WriteJsonUriArray(string propertyName, IEnumerable<Uri> uris)
{
foreach (Uri contactedReplica in uris)
{
this.jsonWriter.WriteStringValue(contactedReplica.ToString());
this.jsonWriter.WriteStringValue(contactedReplica?.ToString() ?? "<null>");
}
}

Expand All @@ -326,6 +326,11 @@ private void WriteJsonUriArrayWithDuplicatesCounted(string propertyName, IReadOn
for (int i = 0; i < totalCount; i++)
{
Uri contactedReplica = uris[i];
if (contactedReplica == null)
{
continue;
}

if (contactedReplica.Equals(previous))
{
duplicateCount++;
Expand All @@ -345,7 +350,7 @@ private void WriteJsonUriArrayWithDuplicatesCounted(string propertyName, IReadOn
this.jsonWriter.WriteFieldName("Count");
this.jsonWriter.WriteNumber64Value(duplicateCount);
this.jsonWriter.WriteFieldName("Uri");
this.jsonWriter.WriteStringValue(contactedReplica.ToString());
this.jsonWriter.WriteStringValue(contactedReplica?.ToString() ?? "<null>");
this.jsonWriter.WriteObjectEnd();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ public void Visit(QueryMetricsTraceDatum queryMetricsTraceDatum)
public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTraceDatum)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Activity ID: {pointOperationStatisticsTraceDatum.ActivityId}");
stringBuilder.AppendLine($"Activity ID: {pointOperationStatisticsTraceDatum.ActivityId ?? "<null>"}");
bchong95 marked this conversation as resolved.
Show resolved Hide resolved
stringBuilder.AppendLine($"Status Code: {pointOperationStatisticsTraceDatum.StatusCode}/{pointOperationStatisticsTraceDatum.SubStatusCode}");
stringBuilder.AppendLine($"Response Time: {pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"Request Charge: {pointOperationStatisticsTraceDatum.RequestCharge}");
stringBuilder.AppendLine($"Request URI: {pointOperationStatisticsTraceDatum.RequestUri}");
stringBuilder.AppendLine($"Session Tokens: {pointOperationStatisticsTraceDatum.RequestSessionToken} / {pointOperationStatisticsTraceDatum.ResponseSessionToken}");
stringBuilder.AppendLine($"Request URI: {pointOperationStatisticsTraceDatum.RequestUri ?? "<null>"}");
bchong95 marked this conversation as resolved.
Show resolved Hide resolved
stringBuilder.AppendLine($"Session Tokens: {pointOperationStatisticsTraceDatum.RequestSessionToken ?? "<null>"} / {pointOperationStatisticsTraceDatum.ResponseSessionToken ?? "<null>"}");
if (pointOperationStatisticsTraceDatum.ErrorMessage != null)
{
stringBuilder.AppendLine($"Error Message: {pointOperationStatisticsTraceDatum.ErrorMessage}");
Expand All @@ -349,6 +349,11 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
Dictionary<Uri, int> uriAndCounts = new Dictionary<Uri, int>();
foreach (Uri uri in clientSideRequestStatisticsTraceDatum.ContactedReplicas)
{
if (uri == null)
{
continue;
}

if (!uriAndCounts.TryGetValue(uri, out int count))
{
count = 0;
Expand All @@ -359,19 +364,19 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist

foreach (KeyValuePair<Uri, int> uriAndCount in uriAndCounts)
{
stringBuilder.AppendLine($"{space}{uriAndCount.Key}: {uriAndCount.Value}");
stringBuilder.AppendLine($"{space}{uriAndCount.Key?.ToString() ?? "<null>"}: {uriAndCount.Value}");
}

stringBuilder.AppendLine("Failed to Contact Replicas");
foreach (Uri failedToContactReplica in clientSideRequestStatisticsTraceDatum.FailedReplicas)
{
stringBuilder.AppendLine($"{space}{failedToContactReplica}");
stringBuilder.AppendLine($"{space}{failedToContactReplica?.ToString() ?? "<null>"}");
}

stringBuilder.AppendLine("Regions Contacted");
foreach (Uri regionContacted in clientSideRequestStatisticsTraceDatum.ContactedReplicas)
{
stringBuilder.AppendLine($"{space}{regionContacted}");
stringBuilder.AppendLine($"{space}{regionContacted?.ToString() ?? "<null>"}");
}

stringBuilder.AppendLine("Address Resolution Statistics");
Expand Down Expand Up @@ -409,8 +414,8 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
if (stat.StoreResult != null)
{
stringBuilder.AppendLine($"{space}Store Result");
stringBuilder.AppendLine($"{space}{space}Activity Id: {stat.StoreResult.ActivityId}");
stringBuilder.AppendLine($"{space}{space}Store Physical Address: {stat.StoreResult.StorePhysicalAddress}");
stringBuilder.AppendLine($"{space}{space}Activity Id: {stat.StoreResult.ActivityId ?? "<null>"}");
stringBuilder.AppendLine($"{space}{space}Store Physical Address: {stat.StoreResult.StorePhysicalAddress?.ToString() ?? "<null>"}");
stringBuilder.AppendLine($"{space}{space}Status Code: {stat.StoreResult.StatusCode}/{stat.StoreResult.SubStatusCode}");
stringBuilder.AppendLine($"{space}{space}Is Valid: {stat.StoreResult.IsValid}");
stringBuilder.AppendLine($"{space}{space}LSN Info");
Expand All @@ -419,7 +424,7 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
stringBuilder.AppendLine($"{space}{space}{space}Global LSN: {stat.StoreResult.GlobalCommittedLSN}");
stringBuilder.AppendLine($"{space}{space}{space}Quorum Acked LSN: {stat.StoreResult.QuorumAckedLSN}");
stringBuilder.AppendLine($"{space}{space}{space}Using LSN: {stat.StoreResult.UsingLocalLSN}");
stringBuilder.AppendLine($"{space}{space}Session Token: {stat.StoreResult.SessionToken.ConvertToString()}");
stringBuilder.AppendLine($"{space}{space}Session Token: {stat.StoreResult.SessionToken?.ConvertToString() ?? "<null>"}");
stringBuilder.AppendLine($"{space}{space}Quorum Info");
stringBuilder.AppendLine($"{space}{space}{space}Current Replica Set Size: {stat.StoreResult.CurrentReplicaSetSize}");
stringBuilder.AppendLine($"{space}{space}{space}Current Write Quorum: {stat.StoreResult.CurrentWriteQuorum}");
Expand Down
Loading