/** * Wrapper method to create new TraceScope with the given description * @return TraceScope or null when not tracing */ public static TraceScope createTrace(String description) { return (tracer == null) ? null : tracer.newScope(description); }
/** * Wrapper method to add timeline annotiation to current span with given message */ public static void addTimelineAnnotation(String msg) { Span span = Tracer.getCurrentSpan(); if (span != null) { span.addTimelineAnnotation(msg); } }
@VisibleForTesting public static synchronized void clear() { if (instance == null) { return; } try { instance.close(); } finally { instance = null; } }
LOG.debug("GroupCacheLoader - load."); TraceScope scope = null; Tracer tracer = Tracer.curThreadTracer(); if (tracer != null) { scope = tracer.newScope("Groups#fetchGroupList"); scope.addKVAnnotation("user", user);
int opsDone; try (final TraceScope span = tracer.newScope(CLIENT_WORKLOAD_SPAN)) { threads.put(new Thread(tracer.wrap(client, "ClientThread")), client); try (final TraceScope span = tracer.newScope(CLIENT_CLEANUP_SPAN)) { try (final TraceScope span = tracer.newScope(CLIENT_EXPORT_MEASUREMENTS_SPAN)) { exportMeasurements(props, opsDone, en - st);
@Test public void TestSimpleScope() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestSimpleScope"). tracerPool(new TracerPool("TestSimpleScope")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")). build(); POJOSpanReceiver receiver = new POJOSpanReceiver(HTraceConfiguration.EMPTY); tracer.getTracerPool().addReceiver(receiver); TraceScope scope = tracer.newScope("Foo"); scope.close(); tracer.close(); Assert.assertEquals(1, receiver.getSpans().size()); Span span = receiver.getSpans().iterator().next(); Assert.assertEquals(0, span.getParents().length); }
conf(new HBaseHTraceConfiguration(HBaseConfiguration.create())). build(); tracer.addSampler(Sampler.ALWAYS); TraceScope parent = tracer.newScope("HBaseSpanReceiver.main.parent"); Thread.sleep(10); long traceid = parent.getSpan().getSpanId().getHigh(); TraceScope child1 = tracer.newScope("HBaseSpanReceiver.main.child.1"); Thread.sleep(10); child1.close(); TraceScope child2 = tracer.newScope("HBaseSpanReceiver.main.child.2"); Thread.sleep(10); TraceScope gchild = tracer.newScope("HBaseSpanReceiver.main.grandchild"); gchild.addTimelineAnnotation("annotation 1."); Thread.sleep(10); Thread.sleep(10); parent.close(); tracer.close(); System.out.println("trace id: " + traceid);
final ThreadFactory tf = new NamingThreadFactory(); ses = Executors.newScheduledThreadPool(TASK_COUNT, tf); ses = tracer.newTraceExecutorService(ses); try (TraceScope scope = tracer.newScope("TestRunnable")) { Collection<Future<String>> futures = new ArrayList<>(); Tracer.getCurrentSpan().getTimelineAnnotations().isEmpty()); assertEquals("Duplicated child span descriptions.", TASK_COUNT, results.size());
/** * Wrap runnable with current tracer and description * @param runnable to wrap * @return wrapped runnable or original runnable when not tracing */ public static Runnable wrap(Runnable runnable, String description) { return (tracer == null) ? runnable : tracer.wrap(runnable, description); } }
SingleServerRequestRunnable runnable = createSingleServerRequest( multiAction, numAttempt, server, callsInProgress); Tracer tracer = Tracer.curThreadTracer(); return Collections.singletonList(tracer.wrap(runnable, "AsyncProcess.sendMultiAction"));
private List<SpanReceiver> createSpanReceivers(String classes) { Tracer tracer = new Tracer.Builder(). name("MyTracer"). tracerPool(new TracerPool("createSpanReceivers")). conf(HTraceConfiguration.fromKeyValuePairs( "span.receiver.classes", classes)). build(); SpanReceiver[] receivers = tracer.getTracerPool().getReceivers(); tracer.close(); LinkedList<SpanReceiver> receiverList = new LinkedList<SpanReceiver>(); for (SpanReceiver item: receivers) { receiverList.add(item); } return receiverList; }
private Sampler[] getSamplersFromConf(HTraceConfiguration conf) { Tracer tracer = new Tracer.Builder(). name("MyTracer"). tracerPool(new TracerPool("getSamplersFromConf")). conf(conf). build(); Sampler[] samplers = tracer.getSamplers(); tracer.close(); return samplers; }
/** * Wrapper method to remove receiver from actual tracerpool * @return true if removed, false if doesn't exist */ public static boolean removeReceiver(SpanReceiver rcvr) { return (tracer == null) ? false : tracer.getTracerPool().removeReceiver(rcvr); }
/** * Wrapper method to add new sampler to the default tracer * @return true if added, false if it was already added */ public static boolean addSampler(Sampler sampler) { if (sampler == null) { return false; } return (tracer == null) ? false : tracer.addSampler(sampler); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { long startTime = 0; if (LOG.isDebugEnabled()) { startTime = Time.monotonicNow(); } // if Tracing is on then start a new span for this rpc. // guard it in the if statement to make sure there isn't // any extra string manipulation. Tracer tracer = Tracer.curThreadTracer(); TraceScope traceScope = null; if (tracer != null) { traceScope = tracer.newScope(RpcClientUtil.methodToTraceString(method)); } ObjectWritable value; try { value = (ObjectWritable) client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args), remoteId, fallbackToSimpleAuth); } finally { if (traceScope != null) traceScope.close(); } if (LOG.isDebugEnabled()) { long callTime = Time.monotonicNow() - startTime; LOG.debug("Call: " + method.getName() + " " + callTime); } return value.get(); }
POJOSpanReceiver receiver = new POJOSpanReceiver(HTraceConfiguration.EMPTY); tracer.getTracerPool().addReceiver(receiver); final ScopeHolder scopeHolder = new ScopeHolder(); Thread th = new Thread(new Runnable() { TraceScope nested = tracer.newScope("nested"); nested.close(); TraceScope nested2 = tracer.newScope("nested2"); nested2.close(); TraceScope lateChildScope = tracer.newScope("lateChild", workerScopeId); lateChildScope.close(); tracer.close();
/** * Creates the demo trace (will create different traces from call to call). */ public void createThreadedTrace() { try (TraceScope s = tracer.newScope(THREADED_TRACE_ROOT)) { Random r = ThreadLocalRandom.current(); int numThreads = r.nextInt(4) + 1; Thread[] threads = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { threads[i] = new Thread(tracer.wrap(new MyRunnable(), null)); } for (int i = 0; i < numThreads; i++) { threads[i].start(); } for (int i = 0; i < numThreads; i++) { try { threads[i].join(); } catch (InterruptedException e) { } } importantWork1(); } }
/** * Wrap runnable with current tracer and description * @param runnable to wrap * @return wrapped runnable or original runnable when not tracing */ public static Runnable wrap(Runnable runnable, String description) { return (tracer == null) ? runnable : tracer.wrap(runnable, description); } }