22// Licensed under the MIT License.
33package com .azure .cosmos .implementation ;
44
5- import com .azure .cosmos .CosmosException ;
65import com .azure .cosmos .implementation .apachecommons .lang .StringUtils ;
76import com .azure .cosmos .implementation .cpu .CpuMemoryMonitor ;
8- import com .azure .cosmos .implementation .directconnectivity .DirectBridgeInternal ;
9- import com .azure .cosmos .implementation .directconnectivity .StoreResponse ;
10- import com .azure .cosmos .implementation .directconnectivity .StoreResult ;
7+ import com .azure .cosmos .implementation .directconnectivity .StoreResponseDiagnostics ;
8+ import com .azure .cosmos .implementation .directconnectivity .StoreResultDiagnostics ;
119import com .fasterxml .jackson .core .JsonGenerator ;
1210import com .fasterxml .jackson .databind .SerializerProvider ;
1311import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
@@ -43,7 +41,6 @@ public class ClientSideRequestStatistics {
4341 private Set <URI > locationEndpointsContacted ;
4442 private RetryContext retryContext ;
4543 private GatewayStatistics gatewayStatistics ;
46- private RequestTimeline gatewayRequestTimeline ;
4744 private MetadataDiagnosticsContext metadataDiagnosticsContext ;
4845 private SerializationDiagnosticsContext serializationDiagnosticsContext ;
4946
@@ -93,13 +90,13 @@ public DiagnosticsClientContext.DiagnosticsClientConfig getDiagnosticsClientConf
9390 return diagnosticsClientConfig ;
9491 }
9592
96- public void recordResponse (RxDocumentServiceRequest request , StoreResult storeResult , GlobalEndpointManager globalEndpointManager ) {
93+ public void recordResponse (RxDocumentServiceRequest request , StoreResultDiagnostics storeResultDiagnostics , GlobalEndpointManager globalEndpointManager ) {
9794 Objects .requireNonNull (request , "request is required and cannot be null." );
9895 Instant responseTime = Instant .now ();
9996
10097 StoreResponseStatistics storeResponseStatistics = new StoreResponseStatistics ();
10198 storeResponseStatistics .requestResponseTimeUTC = responseTime ;
102- storeResponseStatistics .storeResult = StoreResult . createSerializableStoreResult ( storeResult ) ;
99+ storeResponseStatistics .storeResult = storeResultDiagnostics ;
103100 storeResponseStatistics .requestOperationType = request .getOperationType ();
104101 storeResponseStatistics .requestResourceType = request .getResourceType ();
105102 activityId = request .getActivityId ().toString ();
@@ -117,8 +114,7 @@ public void recordResponse(RxDocumentServiceRequest request, StoreResult storeRe
117114 this .requestEndTimeUTC = responseTime ;
118115 }
119116
120- // TODO (kuthapar): globalEndpointManager != null check is just for safety for hotfix. Remove it after further investigation
121- if (locationEndPoint != null && globalEndpointManager != null ) {
117+ if (locationEndPoint != null ) {
122118 this .regionsContacted .add (globalEndpointManager .getRegionName (locationEndPoint , request .getOperationType ()));
123119 this .locationEndpointsContacted .add (locationEndPoint );
124120 }
@@ -133,8 +129,7 @@ public void recordResponse(RxDocumentServiceRequest request, StoreResult storeRe
133129 }
134130
135131 public void recordGatewayResponse (
136- RxDocumentServiceRequest rxDocumentServiceRequest , StoreResponse storeResponse ,
137- CosmosException exception , GlobalEndpointManager globalEndpointManager ) {
132+ RxDocumentServiceRequest rxDocumentServiceRequest , StoreResponseDiagnostics storeResponseDiagnostics , GlobalEndpointManager globalEndpointManager ) {
138133 Instant responseTime = Instant .now ();
139134
140135 synchronized (this ) {
@@ -148,8 +143,7 @@ public void recordGatewayResponse(
148143 }
149144 this .recordRetryContextEndTime ();
150145
151- // TODO (kuthapar): globalEndpointManager != null check is just for safety for hotfix. Remove it after further investigation
152- if (locationEndPoint != null && globalEndpointManager != null ) {
146+ if (locationEndPoint != null ) {
153147 this .regionsContacted .add (globalEndpointManager .getRegionName (locationEndPoint , rxDocumentServiceRequest .getOperationType ()));
154148 this .locationEndpointsContacted .add (locationEndPoint );
155149 }
@@ -159,34 +153,18 @@ public void recordGatewayResponse(
159153 this .gatewayStatistics .operationType = rxDocumentServiceRequest .getOperationType ();
160154 this .gatewayStatistics .resourceType = rxDocumentServiceRequest .getResourceType ();
161155 }
162- if (storeResponse != null ) {
163- this .gatewayStatistics .statusCode = storeResponse .getStatus ();
164- this .gatewayStatistics .subStatusCode = DirectBridgeInternal .getSubStatusCode (storeResponse );
165- this .gatewayStatistics .sessionToken = storeResponse
166- .getHeaderValue (HttpConstants .HttpHeaders .SESSION_TOKEN );
167- this .gatewayStatistics .requestCharge = storeResponse
168- .getHeaderValue (HttpConstants .HttpHeaders .REQUEST_CHARGE );
169- this .gatewayStatistics .requestTimeline = DirectBridgeInternal .getRequestTimeline (storeResponse );
170- this .gatewayStatistics .partitionKeyRangeId = storeResponse .getPartitionKeyRangeId ();
171- this .activityId = storeResponse .getHeaderValue (HttpConstants .HttpHeaders .ACTIVITY_ID );
172- } else if (exception != null ) {
173- this .gatewayStatistics .statusCode = exception .getStatusCode ();
174- this .gatewayStatistics .subStatusCode = exception .getSubStatusCode ();
175- this .gatewayStatistics .requestTimeline = this .gatewayRequestTimeline ;
176- this .gatewayStatistics .requestCharge = String .valueOf (exception .getRequestCharge ());
177- this .activityId =exception .getActivityId ();
178- }
156+ this .gatewayStatistics .statusCode = storeResponseDiagnostics .getStatusCode ();
157+ this .gatewayStatistics .subStatusCode = storeResponseDiagnostics .getSubStatusCode ();
158+ this .gatewayStatistics .sessionToken = storeResponseDiagnostics .getSessionTokenAsString ();
159+ this .gatewayStatistics .requestCharge = storeResponseDiagnostics .getRequestCharge ();
160+ this .gatewayStatistics .requestTimeline = storeResponseDiagnostics .getRequestTimeline ();
161+ this .gatewayStatistics .partitionKeyRangeId = storeResponseDiagnostics .getPartitionKeyRangeId ();
162+ this .gatewayStatistics .exceptionMessage = storeResponseDiagnostics .getExceptionMessage ();
163+ this .gatewayStatistics .exceptionResponseHeaders = storeResponseDiagnostics .getExceptionResponseHeaders ();
164+ this .activityId = storeResponseDiagnostics .getActivityId ();
179165 }
180166 }
181167
182- public void setGatewayRequestTimeline (RequestTimeline transportRequestTimeline ) {
183- this .gatewayRequestTimeline = transportRequestTimeline ;
184- }
185-
186- public RequestTimeline getGatewayRequestTimeline () {
187- return this .gatewayRequestTimeline ;
188- }
189-
190168 public String recordAddressResolutionStart (
191169 URI targetEndpoint ,
192170 boolean forceRefresh ,
@@ -209,7 +187,7 @@ public String recordAddressResolutionStart(
209187 return identifier ;
210188 }
211189
212- public void recordAddressResolutionEnd (String identifier , String errorMessage ) {
190+ public void recordAddressResolutionEnd (String identifier , String exceptionMessage ) {
213191 if (StringUtils .isEmpty (identifier )) {
214192 return ;
215193 }
@@ -227,7 +205,7 @@ public void recordAddressResolutionEnd(String identifier, String errorMessage) {
227205
228206 AddressResolutionStatistics resolutionStatistics = this .addressResolutionStatistics .get (identifier );
229207 resolutionStatistics .endTimeUTC = responseTime ;
230- resolutionStatistics .errorMessage = errorMessage ;
208+ resolutionStatistics .exceptionMessage = exceptionMessage ;
231209 resolutionStatistics .inflightRequest = false ;
232210 }
233211 }
@@ -297,16 +275,16 @@ public GatewayStatistics getGatewayStatistics() {
297275 }
298276
299277 public static class StoreResponseStatistics {
300- @ JsonSerialize (using = StoreResult . StoreResultSerializer .class )
301- private StoreResult storeResult ;
278+ @ JsonSerialize (using = StoreResultDiagnostics . StoreResultDiagnosticsSerializer .class )
279+ private StoreResultDiagnostics storeResult ;
302280 @ JsonSerialize (using = DiagnosticsInstantSerializer .class )
303281 private Instant requestResponseTimeUTC ;
304282 @ JsonSerialize
305283 private ResourceType requestResourceType ;
306284 @ JsonSerialize
307285 private OperationType requestOperationType ;
308286
309- public StoreResult getStoreResult () {
287+ public StoreResultDiagnostics getStoreResult () {
310288 return storeResult ;
311289 }
312290
@@ -409,7 +387,7 @@ public static class AddressResolutionStatistics {
409387 @ JsonSerialize
410388 private String targetEndpoint ;
411389 @ JsonSerialize
412- private String errorMessage ;
390+ private String exceptionMessage ;
413391 @ JsonSerialize
414392 private boolean forceRefresh ;
415393 @ JsonSerialize
@@ -433,8 +411,8 @@ public String getTargetEndpoint() {
433411 return targetEndpoint ;
434412 }
435413
436- public String getErrorMessage () {
437- return errorMessage ;
414+ public String getExceptionMessage () {
415+ return exceptionMessage ;
438416 }
439417
440418 public boolean isInflightRequest () {
@@ -456,9 +434,11 @@ public static class GatewayStatistics {
456434 private ResourceType resourceType ;
457435 private int statusCode ;
458436 private int subStatusCode ;
459- private String requestCharge ;
437+ private double requestCharge ;
460438 private RequestTimeline requestTimeline ;
461439 private String partitionKeyRangeId ;
440+ private String exceptionMessage ;
441+ private String exceptionResponseHeaders ;
462442
463443 public String getSessionToken () {
464444 return sessionToken ;
@@ -476,7 +456,7 @@ public int getSubStatusCode() {
476456 return subStatusCode ;
477457 }
478458
479- public String getRequestCharge () {
459+ public double getRequestCharge () {
480460 return requestCharge ;
481461 }
482462
@@ -491,6 +471,14 @@ public ResourceType getResourceType() {
491471 public String getPartitionKeyRangeId () {
492472 return partitionKeyRangeId ;
493473 }
474+
475+ public String getExceptionMessage () {
476+ return exceptionMessage ;
477+ }
478+
479+ public String getExceptionResponseHeaders () {
480+ return exceptionResponseHeaders ;
481+ }
494482 }
495483
496484 public static SystemInformation fetchSystemInformation () {
0 commit comments