Skip to content

Commit

Permalink
CosmosDiagnostics: Fixes regression in ITrace where direct diagnostic…
Browse files Browse the repository at this point in the history
…s was not included in exception scenarios (#2375)

The ITrace was only adding the client side request stats to the ITrace on success scenarios. If there was any exception the ITrace would not be included. This changes the logic to always add the client side request stats to the ITrace.

The regression was introduced in 3.17.0 with PR #2097
  • Loading branch information
j82w authored Apr 9, 2021
1 parent 2ccc537 commit 2e15307
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Microsoft.Azure.Cosmos/src/Handler/TransportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ internal async Task<ResponseMessage> ProcessMessageAsync(
}

DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest();
serviceRequest.RequestContext.ClientRequestStatistics = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow);
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow);
serviceRequest.RequestContext.ClientRequestStatistics = clientSideRequestStatisticsTraceDatum;

//TODO: extrace auth into a separate handler
string authorization = await ((ICosmosAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationTokenAsync(
Expand All @@ -90,6 +91,7 @@ internal async Task<ResponseMessage> ProcessMessageAsync(
Tracing.TraceLevel.Info))
{
request.Trace = processMessageAsyncTrace;
processMessageAsyncTrace.AddDatum("Client Side Request Stats", clientSideRequestStatisticsTraceDatum);

DocumentServiceResponse response = request.OperationType == OperationType.Upsert
? await this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken)
Expand Down
5 changes: 0 additions & 5 deletions Microsoft.Azure.Cosmos/src/Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ internal static ResponseMessage ToCosmosResponseMessage(
Debug.Assert(requestMessage != null, nameof(requestMessage));
Headers headers = new Headers(documentServiceResponse.Headers);

if (documentServiceResponse.RequestStats is ClientSideRequestStatisticsTraceDatum traceDatum)
{
requestMessage.Trace.AddDatum("Client Side Request Stats", traceDatum);
}

if (requestChargeTracker != null && headers.RequestCharge < requestChargeTracker.TotalRequestCharge)
{
headers.RequestCharge = requestChargeTracker.TotalRequestCharge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ (
│ [Client Side Request Stats]
│ Redacted To Not Change The Baselines From Run To Run
│ [Point Operation Statistics]
│ Redacted To Not Change The Baselines From Run To Run
│ )
Expand Down Expand Up @@ -185,6 +187,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": []
Expand Down Expand Up @@ -724,12 +727,16 @@
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ (
│ [Client Side Request Stats]
│ Redacted To Not Change The Baselines From Run To Run
│ [Point Operation Statistics]
│ Redacted To Not Change The Baselines From Run To Run
│ )
Expand Down Expand Up @@ -868,6 +875,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -896,6 +904,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": []
Expand Down Expand Up @@ -1020,18 +1029,24 @@
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ (
│ [Client Side Request Stats]
│ Redacted To Not Change The Baselines From Run To Run
│ [Point Operation Statistics]
│ Redacted To Not Change The Baselines From Run To Run
│ )
Expand Down Expand Up @@ -1170,6 +1185,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -1198,6 +1214,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -1226,6 +1243,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": []
Expand Down Expand Up @@ -1354,30 +1372,40 @@
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ │ (
│ │ [Client Side Request Stats]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ [Point Operation Statistics]
│ │ Redacted To Not Change The Baselines From Run To Run
│ │ )
│ └── Send Async(00000000-0000-0000-0000-000000000000) RequestHandler-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ └── Microsoft.Azure.Documents.ServerStoreModel Transport Request(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
│ (
│ [Client Side Request Stats]
│ Redacted To Not Change The Baselines From Run To Run
│ [Point Operation Statistics]
│ Redacted To Not Change The Baselines From Run To Run
│ )
Expand Down Expand Up @@ -1516,6 +1544,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -1544,6 +1573,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -1572,6 +1602,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -1600,6 +1631,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": [
Expand Down Expand Up @@ -1628,6 +1660,7 @@
"start time": "12:00:00:000",
"duration in milliseconds": 0,
"data": {
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run",
"Point Operation Statistics": "Redacted To Not Change The Baselines From Run To Run"
},
"children": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,12 @@ public override Output ExecuteTest(Input input)
string text = TraceWriter.TraceToText(traceForBaselineTesting);
string json = TraceWriter.TraceToJson(traceForBaselineTesting);

// AssertTraceProperites(input.Trace);

//AssertTraceProperites(input.Trace);
Assert.IsTrue(text.Contains("Client Side Request Stats"), $"All diagnostics should have request stats: {text}");
Assert.IsTrue(json.Contains("Client Side Request Stats"), $"All diagnostics should have request stats: {json}");
Assert.IsTrue(text.Contains("Client Configuration"), $"All diagnostics should have Client Configuration: {text}");
Assert.IsTrue(json.Contains("Client Configuration"), $"All diagnostics should have Client Configuration: {json}");

return new Output(text, JToken.Parse(json).ToString(Newtonsoft.Json.Formatting.Indented));
}

Expand Down

0 comments on commit 2e15307

Please sign in to comment.