Skip to content

Commit 658d5e6

Browse files
committed
Address comment
1 parent 73ee541 commit 658d5e6

File tree

1 file changed

+7
-7
lines changed
  • instrumentation/httpurlconnection/library/src/main/java/io/opentelemetry/instrumentation/library/httpurlconnection

1 file changed

+7
-7
lines changed

instrumentation/httpurlconnection/library/src/main/java/io/opentelemetry/instrumentation/library/httpurlconnection/HttpUrlReplacements.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.os.SystemClock;
1010
import androidx.annotation.RequiresApi;
1111
import io.opentelemetry.context.Context;
12+
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1213
import io.opentelemetry.instrumentation.library.httpurlconnection.internal.HttpUrlConnectionSingletons;
1314
import io.opentelemetry.instrumentation.library.httpurlconnection.internal.RequestPropertySetter;
1415
import java.io.IOException;
@@ -28,6 +29,7 @@ public class HttpUrlReplacements {
2829
new ConcurrentHashMap<>();
2930
private static final Logger logger = Logger.getLogger("HttpUrlReplacements");
3031
public static final int UNKNOWN_RESPONSE_CODE = -1;
32+
private static Instrumenter<URLConnection, Integer> httpURLInstrumenter = null;
3133

3234
public static void replacementForDisconnect(HttpURLConnection connection) {
3335
// Ensure ending of un-ended spans while connection is still alive
@@ -281,24 +283,22 @@ private static void endTracing(URLConnection connection, int responseCode, Throw
281283
HttpURLConnectionInfo info = activeURLConnections.get(connection);
282284
if (info != null && !info.reported) {
283285
Context context = info.context;
284-
HttpUrlConnectionSingletons.instrumenter()
285-
.end(context, connection, responseCode, error);
286+
httpURLInstrumenter.end(context, connection, responseCode, error);
286287
info.reported = true;
287288
activeURLConnections.remove(connection);
288289
}
289290
}
290291

291292
private static void startTracingAtFirstConnection(URLConnection connection) {
292293
Context parentContext = Context.current();
293-
if (HttpUrlConnectionSingletons.instrumenter() == null
294-
|| !HttpUrlConnectionSingletons.instrumenter()
295-
.shouldStart(parentContext, connection)) {
294+
httpURLInstrumenter = HttpUrlConnectionSingletons.instrumenter();
295+
if (httpURLInstrumenter == null
296+
|| !httpURLInstrumenter.shouldStart(parentContext, connection)) {
296297
return;
297298
}
298299

299300
if (!activeURLConnections.containsKey(connection)) {
300-
Context context =
301-
HttpUrlConnectionSingletons.instrumenter().start(parentContext, connection);
301+
Context context = httpURLInstrumenter.start(parentContext, connection);
302302
activeURLConnections.put(connection, new HttpURLConnectionInfo(context));
303303
try {
304304
injectContextToRequest(connection, context);

0 commit comments

Comments
 (0)