public void logHttpRequestTelemetryEvent ( String eventName , HttpRequestBase request , int injectSocketTimeout , AtomicBoolean canceling , boolean withoutCookies , boolean includeRetryParameters , boolean includeRequestGuid , CloseableHttpResponse response , final Exception savedEx , String breakRetryReason , long retryTimeout , int retryCount , String sqlState , int errorCode ) { if ( enabled ) { TelemetryEvent . LogBuilder logBuilder = new TelemetryEvent . LogBuilder ( ) ; JSONObject value = new JSONObject ( ) ; value . put ( "request" , request . toString ( ) ) ; value . put ( "retryTimeout" , retryTimeout ) ; value . put ( "injectSocketTimeout" , injectSocketTimeout ) ; value . put ( "canceling" , canceling == null ? "null" : canceling . get ( ) ) ; value . put ( "withoutCookies" , withoutCookies ) ; value . put ( "includeRetryParameters" , includeRetryParameters ) ; value . put ( "includeRequestGuid" , includeRequestGuid ) ; value . put ( "breakRetryReason" , breakRetryReason ) ; value . put ( "retryTimeout" , retryTimeout ) ; value . put ( "retryCount" , retryCount ) ; value . put ( "sqlState" , sqlState ) ; value . put ( "errorCode" , errorCode ) ; int responseStatusCode = - 1 ; if ( response != null ) { value . put ( "response" , response . toString ( ) ) ; value . put ( "responseStatusLine" , response . getStatusLine ( ) . toString ( ) ) ; if ( response . getStatusLine ( ) != null ) { responseStatusCode = response . getStatusLine ( ) . getStatusCode ( ) ; value . put ( "responseStatusCode" , responseStatusCode ) ; } } else { value . put ( "response" , null ) ; } if ( savedEx != null ) { value . put ( "exceptionMessage" , savedEx . getLocalizedMessage ( ) ) ; StringWriter sw = new StringWriter ( ) ; savedEx . printStackTrace ( new PrintWriter ( sw ) ) ; value . put ( "exceptionStackTrace" , sw . toString ( ) ) ; } TelemetryEvent log = logBuilder . withName ( eventName ) . withValue ( value ) . withTag ( "sqlState" , sqlState ) . withTag ( "errorCode" , errorCode ) . withTag ( "responseStatusCode" , responseStatusCode ) . build ( ) ; this . add ( log ) ; } }
log error http response to telemetry