22
22
import com .google .api .client .util .StreamingContent ;
23
23
import com .google .api .client .util .StringUtils ;
24
24
import com .google .common .util .concurrent .ThreadFactoryBuilder ;
25
- import io .opencensus .common .Scope ;
26
- import io .opencensus .contrib .http .util .HttpTraceAttributeConstants ;
27
- import io .opencensus .trace .AttributeValue ;
28
- import io .opencensus .trace .Span ;
29
- import io .opencensus .trace .Tracer ;
30
25
import java .io .IOException ;
31
26
import java .io .InputStream ;
32
27
import java .util .Properties ;
@@ -199,9 +194,6 @@ public final class HttpRequest {
199
194
/** Sleeper. */
200
195
private Sleeper sleeper = Sleeper .DEFAULT ;
201
196
202
- /** OpenCensus tracing component. */
203
- private final Tracer tracer = OpenCensusUtils .getTracer ();
204
-
205
197
/**
206
198
* Determines whether {@link HttpResponse#getContent()} of this request should return raw input
207
199
* stream or not.
@@ -860,13 +852,7 @@ public HttpResponse execute() throws IOException {
860
852
Preconditions .checkNotNull (requestMethod );
861
853
Preconditions .checkNotNull (url );
862
854
863
- Span span =
864
- tracer
865
- .spanBuilder (OpenCensusUtils .SPAN_NAME_HTTP_REQUEST_EXECUTE )
866
- .setRecordEvents (OpenCensusUtils .isRecordEvent ())
867
- .startSpan ();
868
855
do {
869
- span .addAnnotation ("retry #" + (numRetries - retriesRemaining ));
870
856
// Cleanup any unneeded response from a previous iteration
871
857
if (response != null ) {
872
858
response .ignore ();
@@ -881,10 +867,6 @@ public HttpResponse execute() throws IOException {
881
867
}
882
868
// build low-level HTTP request
883
869
String urlString = url .build ();
884
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_METHOD , requestMethod );
885
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_HOST , url .getHost ());
886
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_PATH , url .getRawPath ());
887
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_URL , urlString );
888
870
889
871
LowLevelHttpRequest lowLevelHttpRequest = transport .buildRequest (requestMethod , urlString );
890
872
Logger logger = HttpTransport .LOGGER ;
@@ -914,14 +896,11 @@ public HttpResponse execute() throws IOException {
914
896
if (!suppressUserAgentSuffix ) {
915
897
if (originalUserAgent == null ) {
916
898
headers .setUserAgent (USER_AGENT_SUFFIX );
917
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_USER_AGENT , USER_AGENT_SUFFIX );
918
899
} else {
919
900
String newUserAgent = originalUserAgent + " " + USER_AGENT_SUFFIX ;
920
901
headers .setUserAgent (newUserAgent );
921
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_USER_AGENT , newUserAgent );
922
902
}
923
903
}
924
- OpenCensusUtils .propagateTracingContext (span , headers );
925
904
926
905
// headers
927
906
HttpHeaders .serializeHeaders (headers , logbuf , curlbuf , logger , lowLevelHttpRequest );
@@ -1004,18 +983,8 @@ public HttpResponse execute() throws IOException {
1004
983
lowLevelHttpRequest .setTimeout (connectTimeout , readTimeout );
1005
984
lowLevelHttpRequest .setWriteTimeout (writeTimeout );
1006
985
1007
- // switch tracing scope to current span
1008
- @ SuppressWarnings ("MustBeClosedChecker" )
1009
- Scope ws = tracer .withSpan (span );
1010
- OpenCensusUtils .recordSentMessageEvent (span , lowLevelHttpRequest .getContentLength ());
1011
986
try {
1012
987
LowLevelHttpResponse lowLevelHttpResponse = lowLevelHttpRequest .execute ();
1013
- if (lowLevelHttpResponse != null ) {
1014
- OpenCensusUtils .recordReceivedMessageEvent (span , lowLevelHttpResponse .getContentLength ());
1015
- span .putAttribute (
1016
- HttpTraceAttributeConstants .HTTP_STATUS_CODE ,
1017
- AttributeValue .longAttributeValue (lowLevelHttpResponse .getStatusCode ()));
1018
- }
1019
988
// Flag used to indicate if an exception is thrown before the response is constructed.
1020
989
boolean responseConstructed = false ;
1021
990
try {
@@ -1033,17 +1002,13 @@ public HttpResponse execute() throws IOException {
1033
1002
if (!retryOnExecuteIOException
1034
1003
&& (ioExceptionHandler == null
1035
1004
|| !ioExceptionHandler .handleIOException (this , retryRequest ))) {
1036
- // static analysis shows response is always null here
1037
- span .end (OpenCensusUtils .getEndSpanOptions (null ));
1038
1005
throw e ;
1039
1006
}
1040
1007
// Save the exception in case the retries do not work and we need to re-throw it later.
1041
1008
executeException = e ;
1042
1009
if (loggable ) {
1043
1010
logger .log (Level .WARNING , "exception thrown while executing request" , e );
1044
1011
}
1045
- } finally {
1046
- ws .close ();
1047
1012
}
1048
1013
1049
1014
// Flag used to indicate if an exception is thrown before the response has completed
@@ -1100,8 +1065,6 @@ public HttpResponse execute() throws IOException {
1100
1065
}
1101
1066
}
1102
1067
} while (retryRequest );
1103
- span .end (OpenCensusUtils .getEndSpanOptions (response == null ? null : response .getStatusCode ()));
1104
-
1105
1068
if (response == null ) {
1106
1069
// Retries did not help resolve the execute exception, re-throw it.
1107
1070
throw executeException ;
@@ -1218,12 +1181,6 @@ public HttpRequest setSleeper(Sleeper sleeper) {
1218
1181
return this ;
1219
1182
}
1220
1183
1221
- private static void addSpanAttribute (Span span , String key , String value ) {
1222
- if (value != null ) {
1223
- span .putAttribute (key , AttributeValue .stringAttributeValue (value ));
1224
- }
1225
- }
1226
-
1227
1184
private static String getVersion () {
1228
1185
// attempt to read the library's version from a properties file generated during the build
1229
1186
// this value should be read and cached for later use
0 commit comments