23
23
import com .google .api .client .util .StreamingContent ;
24
24
import com .google .api .client .util .StringUtils ;
25
25
import com .google .common .util .concurrent .ThreadFactoryBuilder ;
26
- import io .opencensus .common .Scope ;
27
- import io .opencensus .contrib .http .util .HttpTraceAttributeConstants ;
28
- import io .opencensus .trace .AttributeValue ;
29
- import io .opencensus .trace .Span ;
30
- import io .opencensus .trace .Tracer ;
31
26
import java .io .IOException ;
32
27
import java .io .InputStream ;
33
28
import java .util .Properties ;
@@ -197,9 +192,6 @@ public final class HttpRequest {
197
192
/** Sleeper. */
198
193
private Sleeper sleeper = Sleeper .DEFAULT ;
199
194
200
- /** OpenCensus tracing component. */
201
- private final Tracer tracer = OpenCensusUtils .getTracer ();
202
-
203
195
/**
204
196
* Determines whether {@link HttpResponse#getContent()} of this request should return raw input
205
197
* stream or not.
@@ -843,13 +835,7 @@ public HttpResponse execute() throws IOException {
843
835
Preconditions .checkNotNull (requestMethod );
844
836
Preconditions .checkNotNull (url );
845
837
846
- Span span =
847
- tracer
848
- .spanBuilder (OpenCensusUtils .SPAN_NAME_HTTP_REQUEST_EXECUTE )
849
- .setRecordEvents (OpenCensusUtils .isRecordEvent ())
850
- .startSpan ();
851
838
do {
852
- span .addAnnotation ("retry #" + (numRetries - retriesRemaining ));
853
839
// Cleanup any unneeded response from a previous iteration
854
840
if (response != null ) {
855
841
response .ignore ();
@@ -864,10 +850,6 @@ public HttpResponse execute() throws IOException {
864
850
}
865
851
// build low-level HTTP request
866
852
String urlString = url .build ();
867
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_METHOD , requestMethod );
868
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_HOST , url .getHost ());
869
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_PATH , url .getRawPath ());
870
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_URL , urlString );
871
853
872
854
LowLevelHttpRequest lowLevelHttpRequest = transport .buildRequest (requestMethod , urlString );
873
855
Logger logger = HttpTransport .LOGGER ;
@@ -897,14 +879,11 @@ public HttpResponse execute() throws IOException {
897
879
if (!suppressUserAgentSuffix ) {
898
880
if (originalUserAgent == null ) {
899
881
headers .setUserAgent (USER_AGENT_SUFFIX );
900
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_USER_AGENT , USER_AGENT_SUFFIX );
901
882
} else {
902
883
String newUserAgent = originalUserAgent + " " + USER_AGENT_SUFFIX ;
903
884
headers .setUserAgent (newUserAgent );
904
- addSpanAttribute (span , HttpTraceAttributeConstants .HTTP_USER_AGENT , newUserAgent );
905
885
}
906
886
}
907
- OpenCensusUtils .propagateTracingContext (span , headers );
908
887
909
888
// headers
910
889
HttpHeaders .serializeHeaders (headers , logbuf , curlbuf , logger , lowLevelHttpRequest );
@@ -988,15 +967,8 @@ public HttpResponse execute() throws IOException {
988
967
lowLevelHttpRequest .setTimeout (connectTimeout , readTimeout );
989
968
lowLevelHttpRequest .setWriteTimeout (writeTimeout );
990
969
991
- // switch tracing scope to current span
992
- @ SuppressWarnings ("MustBeClosedChecker" )
993
- Scope ws = tracer .withSpan (span );
994
- OpenCensusUtils .recordSentMessageEvent (span , lowLevelHttpRequest .getContentLength ());
995
970
try {
996
971
LowLevelHttpResponse lowLevelHttpResponse = lowLevelHttpRequest .execute ();
997
- if (lowLevelHttpResponse != null ) {
998
- OpenCensusUtils .recordReceivedMessageEvent (span , lowLevelHttpResponse .getContentLength ());
999
- }
1000
972
// Flag used to indicate if an exception is thrown before the response is constructed.
1001
973
boolean responseConstructed = false ;
1002
974
try {
@@ -1014,17 +986,13 @@ public HttpResponse execute() throws IOException {
1014
986
if (!retryOnExecuteIOException
1015
987
&& (ioExceptionHandler == null
1016
988
|| !ioExceptionHandler .handleIOException (this , retryRequest ))) {
1017
- // static analysis shows response is always null here
1018
- span .end (OpenCensusUtils .getEndSpanOptions (null ));
1019
989
throw e ;
1020
990
}
1021
991
// Save the exception in case the retries do not work and we need to re-throw it later.
1022
992
executeException = e ;
1023
993
if (loggable ) {
1024
994
logger .log (Level .WARNING , "exception thrown while executing request" , e );
1025
995
}
1026
- } finally {
1027
- ws .close ();
1028
996
}
1029
997
1030
998
// Flag used to indicate if an exception is thrown before the response has completed
@@ -1081,8 +1049,6 @@ public HttpResponse execute() throws IOException {
1081
1049
}
1082
1050
}
1083
1051
} while (retryRequest );
1084
- span .end (OpenCensusUtils .getEndSpanOptions (response == null ? null : response .getStatusCode ()));
1085
-
1086
1052
if (response == null ) {
1087
1053
// Retries did not help resolve the execute exception, re-throw it.
1088
1054
throw executeException ;
@@ -1197,12 +1163,6 @@ public HttpRequest setSleeper(Sleeper sleeper) {
1197
1163
return this ;
1198
1164
}
1199
1165
1200
- private static void addSpanAttribute (Span span , String key , String value ) {
1201
- if (value != null ) {
1202
- span .putAttribute (key , AttributeValue .stringAttributeValue (value ));
1203
- }
1204
- }
1205
-
1206
1166
private static String getVersion () {
1207
1167
String version = HttpRequest .class .getPackage ().getImplementationVersion ();
1208
1168
// in a non-packaged environment (local), there's no implementation version to read
0 commit comments