9
9
import android .os .SystemClock ;
10
10
import androidx .annotation .RequiresApi ;
11
11
import io .opentelemetry .context .Context ;
12
+ import io .opentelemetry .instrumentation .api .instrumenter .Instrumenter ;
12
13
import io .opentelemetry .instrumentation .library .httpurlconnection .internal .HttpUrlConnectionSingletons ;
13
14
import io .opentelemetry .instrumentation .library .httpurlconnection .internal .RequestPropertySetter ;
14
15
import java .io .IOException ;
@@ -28,6 +29,7 @@ public class HttpUrlReplacements {
28
29
new ConcurrentHashMap <>();
29
30
private static final Logger logger = Logger .getLogger ("HttpUrlReplacements" );
30
31
public static final int UNKNOWN_RESPONSE_CODE = -1 ;
32
+ private static Instrumenter <URLConnection , Integer > httpURLInstrumenter = null ;
31
33
32
34
public static void replacementForDisconnect (HttpURLConnection connection ) {
33
35
// Ensure ending of un-ended spans while connection is still alive
@@ -281,24 +283,22 @@ private static void endTracing(URLConnection connection, int responseCode, Throw
281
283
HttpURLConnectionInfo info = activeURLConnections .get (connection );
282
284
if (info != null && !info .reported ) {
283
285
Context context = info .context ;
284
- HttpUrlConnectionSingletons .instrumenter ()
285
- .end (context , connection , responseCode , error );
286
+ httpURLInstrumenter .end (context , connection , responseCode , error );
286
287
info .reported = true ;
287
288
activeURLConnections .remove (connection );
288
289
}
289
290
}
290
291
291
292
private static void startTracingAtFirstConnection (URLConnection connection ) {
292
293
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 )) {
296
297
return ;
297
298
}
298
299
299
300
if (!activeURLConnections .containsKey (connection )) {
300
- Context context =
301
- HttpUrlConnectionSingletons .instrumenter ().start (parentContext , connection );
301
+ Context context = httpURLInstrumenter .start (parentContext , connection );
302
302
activeURLConnections .put (connection , new HttpURLConnectionInfo (context ));
303
303
try {
304
304
injectContextToRequest (connection , context );
0 commit comments