Created
July 14, 2016 00:13
-
-
Save NegatioN/ae41290bb38a0aed1d8e8864620a3f99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class BraveRxJavaSchedulersHook extends RxJavaSchedulersHook { | |
@Override | |
public Action0 onSchedule(Action0 action) { | |
ServerSpanThreadBinder binder = ZipkinHolder.getInstance().serverSpanThreadBinder(); | |
ServerSpan span = binder.getCurrentServerSpan(); | |
return () -> { | |
binder.setCurrentSpan(span); | |
action.call(); | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ZipkinHolder { | |
static { | |
System.setProperty( | |
"rxjava.plugin.RxJavaSchedulersHook.implementation", | |
BraveRxJavaSchedulersHook.class.getCanonicalName()); | |
} | |
private static volatile FINNHystrixHooks finnHystrixHooks = new NoopFINNHystrixHooks(); | |
public static synchronized void registerFINNHystrixHooks(FINNHystrixHooks hooks){ | |
finnHystrixHooks = hooks; | |
} | |
private static final Log LOG = LogFactory.getLog(ZipkinHolder.class); | |
private static volatile Brave BRAVE; | |
public static Brave getInstance() { | |
if (BRAVE == null) { | |
BRAVE = new Brave.Builder(getServiceName()) | |
.spanCollector(FailSilentlyCollector.wrap(ZipkinHolder::createSpanCollector)) | |
.traceSampler(createSampler()) | |
.build(); | |
setupRx(); | |
} | |
return BRAVE; | |
} | |
private static void setupRx() { | |
try { | |
LOG.info("Setting up Hystrix and RxJava hools..."); | |
final RxJavaSchedulersHook hook = RxJavaPlugins.getInstance().getSchedulersHook(); | |
LOG.info("RxJavaSchedulersHook = " + hook.getClass().getCanonicalName()); | |
final HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); | |
LOG.info("HystrixConcurrencyStrategy = " + concurrencyStrategy.getClass().getCanonicalName()); | |
} catch(IllegalStateException ex) { | |
LOG.warn("Couldn't register Hystrix/RX scheduler hooks.", ex); | |
} | |
} | |
} |
onSchedule should clear current span in a finally, right?
Probably. This code doen't clean up after itself, it assumes that the next span that is started overwrites the state. (effectively cleaning up after the previous span)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool stuff!
onSchedule should clear current span in a finally, right?