@@ -1065,61 +1065,50 @@ public String sendHTTPRequest(@SpanAttribute String uri, @SpanAttribute String m
1065
1065
1066
1066
URL url = new URL (getBaseUrl () + (uri != null && uri .startsWith ("/" ) ? "" : "/" ) + uri );
1067
1067
1068
- /*Span sendHTTPReqSpan = GlobalOpenTelemetry.get().getTracer(BaseHPCCWsClient.PROJECT_NAME)
1069
- .spanBuilder(method.toUpperCase() + " " + url.toExternalForm())
1070
- .setAttribute(ServerAttributes.SERVER_ADDRESS, getHost())
1071
- .setAttribute(ServerAttributes.SERVER_PORT, Long.getLong(getPort()))
1072
- .setAttribute(HttpAttributes.HTTP_REQUEST_METHOD, method)
1073
- .setSpanKind(SpanKind.CLIENT)
1074
- .startSpan();
1075
- */
1076
1068
HttpURLConnection httpURLConnection = (HttpURLConnection ) url .openConnection (); //throws IOException
1077
1069
1078
1070
Connection .log .info ("Sending HTTP " + method + "Request to:" + url .toString ());
1079
1071
1072
+ boolean isTraced = Span .current ().isRecording ();
1080
1073
if (hasCredentials ())
1081
1074
{
1082
1075
httpURLConnection .setRequestProperty ("Authorization" , getBasicAuthString ());
1083
- //sendHTTPReqSpan.setAttribute("hasCredentials", true);
1076
+ if (isTraced )
1077
+ Span .current ().setAttribute ("hasCredentials" , true );
1084
1078
}
1085
- //else
1086
- //{
1087
- //sendHTTPReqSpan.setAttribute("hasCredentials", false);
1088
- //}
1089
-
1090
- //try (Scope scope = sendHTTPReqSpan.makeCurrent())
1079
+ else
1091
1080
{
1092
- httpURLConnection .setRequestProperty ("traceparent" , Utils .getCurrentSpanTraceParentHeader ());
1093
- httpURLConnection .setRequestMethod (method ); //throws ProtocolException
1081
+ if (isTraced )
1082
+ Span .current ().setAttribute ("hasCredentials" , false );
1083
+ }
1094
1084
1095
- int responseCode = httpURLConnection .getResponseCode (); //throws IOException
1096
- //sendHTTPReqSpan.setAttribute("http.response.status_code", responseCode);
1097
- Connection .log .info ("HTTP Response code: " + responseCode );
1085
+ if (isTraced )
1086
+ httpURLConnection .setRequestProperty ("traceparent" , Utils .getCurrentSpanTraceParentHeader ());
1098
1087
1099
- if (responseCode == HttpURLConnection .HTTP_OK ) //success
1100
- {
1101
- BufferedReader in = new BufferedReader (new InputStreamReader (httpURLConnection .getInputStream ())); //throws IOException
1102
- String inputLine ;
1103
- StringBuffer response = new StringBuffer ();
1088
+ httpURLConnection .setRequestMethod (method ); //throws ProtocolException
1104
1089
1105
- while ((inputLine = in .readLine ()) != null ) // throws IOException
1106
- {
1107
- response .append (inputLine );
1108
- }
1090
+ int responseCode = httpURLConnection .getResponseCode (); //throws IOException
1109
1091
1110
- in .close (); //throws IOException
1111
- // sendHTTPReqSpan.setStatus(StatusCode.OK);
1112
- return response .toString ();
1113
- }
1114
- else
1092
+ Connection .log .info ("HTTP Response code: " + responseCode );
1093
+
1094
+ if (responseCode == HttpURLConnection .HTTP_OK ) //success
1095
+ {
1096
+ BufferedReader in = new BufferedReader (new InputStreamReader (httpURLConnection .getInputStream ())); //throws IOException
1097
+ String inputLine ;
1098
+ StringBuffer response = new StringBuffer ();
1099
+
1100
+ while ((inputLine = in .readLine ()) != null ) // throws IOException
1115
1101
{
1116
- //sendHTTPReqSpan.setStatus(StatusCode.ERROR);
1117
- throw new IOException ("HTTP request failed! Code (" + responseCode + ") " + httpURLConnection .getResponseMessage () );
1102
+ response .append (inputLine );
1118
1103
}
1104
+
1105
+ in .close (); //throws IOException
1106
+
1107
+ return response .toString ();
1108
+ }
1109
+ else
1110
+ {
1111
+ throw new IOException ("HTTP request failed! Code (" + responseCode + ") " + httpURLConnection .getResponseMessage () );
1119
1112
}
1120
- //finally
1121
- //{
1122
- // sendHTTPReqSpan.end();
1123
- //}
1124
1113
}
1125
1114
}
0 commit comments