use of io.opentracing.util.AutoFinishScope in project opentracing-java by opentracing.
the class RunnableAction method run.
/**
* Can be used continuation.activate().deactivate() chain only. It is splitted for testing
* purposes (span should not be finished before deactivate() called here).
*/
@Override
public void run() {
logger.info("Action started");
AutoFinishScope scope = continuation.activate();
try {
// without sleep first action can finish before second is started
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
// set random tag starting with 'test_tag_' to test that finished span has all of them
scope.span().setTag("test_tag_" + ThreadLocalRandom.current().nextInt(), "random");
scope.close();
logger.info("Action finished");
}
use of io.opentracing.util.AutoFinishScope in project opentracing-java by opentracing.
the class Client method send.
public Future<Object> send(final Object message, final long milliseconds) {
Scope scope = tracer.scopeManager().active();
final Continuation cont = ((AutoFinishScope) scope).capture();
return executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
logger.info("Child thread with message '{}' started", message);
try (Scope parentScope = cont.activate()) {
try (Scope subtaskScope = tracer.buildSpan("subtask").startActive(false)) {
// Simulate work.
sleep(milliseconds);
}
}
logger.info("Child thread with message '{}' finished", message);
return message + "::response";
}
});
}
Aggregations