GlobalTracer implements Tracer { public static synchronized boolean registerIfAbsent(final Callable<Tracer> provider) { requireNonNull(provider, "Cannot register GlobalTracer from provider <null>."); if (!isRegistered()) { try { final Tracer suppliedTracer = requireNonNull(provider.call(), "Cannot register GlobalTracer <null>."); if (!(suppliedTracer instanceof GlobalTracer)) { GlobalTracer.tracer = suppliedTracer; isRegistered = true; return true; } } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { throw new IllegalStateException("Exception obtaining tracer from provider: " + ex.getMessage(), ex); } } return false; } private  GlobalTracer(); static Tracer get(); static boolean isRegistered(); static synchronized boolean registerIfAbsent(final Callable<Tracer> provider); static synchronized boolean registerIfAbsent(final Tracer tracer); @Deprecated static void register(final Tracer tracer); @Override ScopeManager scopeManager(); @Override SpanBuilder buildSpan(String operationName); @Override void inject(SpanContext spanContext, Format<C> format, C carrier); @Override SpanContext extract(Format<C> format, C carrier); @Override Span activeSpan(); @Override Scope activateSpan(Span span); @Override void close(); @Override String toString();  }
@Test public void testRegisterIfAbsent_runtimeException() { RuntimeException thrownRuntimeException = new IllegalStateException("Expected runtime exception"); try { GlobalTracer.registerIfAbsent(throwing(thrownRuntimeException)); fail("Runtime exception expected"); } catch (RuntimeException expected) { assertThat(expected, is(sameInstance(thrownRuntimeException))); } }
@Test public void testRegisterIfAbsent_checkedException() { Exception thrownCheckedException = new Exception("Expected checked exception"); try { GlobalTracer.registerIfAbsent(throwing(thrownCheckedException)); fail("Runtime exception expected"); } catch (RuntimeException expected) { assertThat(expected.getCause(), is(sameInstance((Throwable) thrownCheckedException))); } }