M.2. Client Modifications

In order to turn on tracing in your client code, you must initialize the module sending spans to receiver once per client process.

private SpanReceiverHost spanReceiverHost;

...

  Configuration conf = HBaseConfiguration.create();
  SpanReceiverHost spanReceiverHost = SpanReceiverHost.getInstance(conf);

Then you simply start tracing span before requests you think are interesting, and close it when the request is done. For example, if you wanted to trace all of your get operations, you change this:

HTable table = new HTable(conf, "t1");
Get get = new Get(Bytes.toBytes("r1"));
Result res = table.get(get);

into:

TraceScope ts = Trace.startSpan("Gets", Sampler.ALWAYS);
try {
  HTable table = new HTable(conf, "t1");
  Get get = new Get(Bytes.toBytes("r1"));
  Result res = table.get(get);
} finally {
  ts.close();
}

If you wanted to trace half of your 'get' operations, you would pass in:

new ProbabilitySampler(0.5)

in lieu of Sampler.ALWAYS to Trace.startSpan(). See the HTrace README for more information on Samplers.

comments powered by Disqus