-
Notifications
You must be signed in to change notification settings - Fork 494
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the required format: "[Internal] Category: (Adds|Fixes|Refactors) Description"
Examples:
Diagnostics: Adds GetElapsedClientLatency to CosmosDiagnostics
PartitionKey: Fixes null reference when using default(PartitionKey)
[v4] Client Encryption: Refactors code to external project
[Internal] Query: Adds code generator for CosmosNumbers for easy additions in the future.
Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the required format: "[Internal] Category: (Adds|Fixes|Refactors) Description"
Examples:
Diagnostics: Adds GetElapsedClientLatency to CosmosDiagnostics
PartitionKey: Fixes null reference when using default(PartitionKey)
[v4] Client Encryption: Refactors code to external project
[Internal] Query: Adds code generator for CosmosNumbers for easy additions in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -158,7 +158,7 @@ public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTra | |||
this.jsonWriter.WriteStringValue("PointOperationStatistics"); | |||
|
|||
this.jsonWriter.WriteFieldName("ActivityId"); | |||
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.ActivityId); | |||
this.WriteStringValueOrNull(pointOperationStatisticsTraceDatum.ActivityId); | |||
|
|||
this.jsonWriter.WriteFieldName("ResponseTimeUtc"); | |||
this.jsonWriter.WriteStringValue(pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString("o", CultureInfo.InvariantCulture)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WriteStringValueOrNull
There was a problem hiding this comment.
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.
Preview TraceWriter: Fixes NRE
Description
The trace datum classes don't have a strong contract with null. Values like endpoint are sometimes allowed to be null. In the old trace writer we would call on Newtonsoft's JsonWriter.WriteValue(value), which is tolerant of null values. Currently we use Cosmos.Json.JsonWriter.WriteStringValue() which does not handle null. The fix is to just handle null in the writer. We can not push the invariants up to the type, since we don't know what code in production might set a value to null and don't want to cause a NullArgumentException at runtime. As we see diagnostics with nulls we can investigate what caused it and hunt down the values.