@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(); }
RpcClientUtil.toTraceName(rpcRequest.toString()), parentSpanId); traceScope.detach();
public FileStatus[] glob() throws IOException { TraceScope scope = tracer.newScope("Globber#glob"); scope.addKVAnnotation("pattern", pathPattern.toUri().getPath()); try { return doGlob(); } finally { scope.close(); } }
call.traceScope.reattach(); traceScope = call.traceScope; traceScope.getSpan().addTimelineAnnotation("called"); LOG.info(Thread.currentThread().getName() + " unexpectedly interrupted", e); if (traceScope != null) { traceScope.getSpan().addTimelineAnnotation("unexpectedly interrupted: " + StringUtils.stringifyException(e)); LOG.info(Thread.currentThread().getName() + " caught an exception", e); if (traceScope != null) { traceScope.getSpan().addTimelineAnnotation("Exception: " + StringUtils.stringifyException(e));
traceScope.addTimelineAnnotation("Call got exception: " + e.toString()); if (traceScope != null) traceScope.close();
TraceUtil.addSampler(loopSampler); for (int i = 0; i < numIterations; ++i) { assert Tracer.getCurrentSpan() == threadScope.getSpan() : "Span leak detected."; try (TraceScope loopScope = TraceUtil.createTrace("runLoopIter" + i)) { long now = System.nanoTime();
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); gchild.addTimelineAnnotation("annotation 2."); gchild.close(); Thread.sleep(10); child2.close(); Thread.sleep(10); parent.close(); tracer.close(); System.out.println("trace id: " + traceid);
HashMap<Integer,SpanId> spanIdHashMap = new HashMap<>(); SpanId parentID = new SpanId(100L, 200L); spanIdHashMap.put(activeScope.getSpanId().hashCode(),activeScope.getSpanId()); spanIdHashMap.put(parentID.hashCode(),parentID); TraceScope childScope = tracer. newScope("ChildScope", parentID); Assert.assertNotNull(childScope); Assert.assertEquals(childScope.getSpan().getParents().length, 2); Assert.assertNotNull(spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode())); Assert.assertEquals(childScope.getSpan().getParents()[0].getHigh(), spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getHigh()); Assert.assertEquals(childScope.getSpan().getParents()[0].getLow(), spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getLow()); Assert.assertNotNull(spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode())); Assert.assertEquals(childScope.getSpan().getParents()[1].getHigh(), spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getHigh()); Assert.assertEquals(childScope.getSpan().getParents()[1].getLow(), spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getLow()); childScope.close(); activeScope.close();
void closeScope(TraceScope scope) { TraceScope curScope = threadLocalScope.get(); if (curScope != scope) { throwClientError("Can't close TraceScope for " + scope.getSpan().toJson() + " because it is not the current " + "TraceScope in thread " + Thread.currentThread().getName()); } if (tracerPool == null) { throwClientError(toString() + " is closed."); } SpanReceiver[] receivers = tracerPool.getReceivers(); if (receivers == null) { throwClientError(toString() + " is closed."); } ThreadContext context = threadContext.get(); context.popScope(); threadLocalScope.set(scope.getParent()); scope.setParent(null); Span span = scope.getSpan(); span.stop(); for (SpanReceiver receiver : receivers) { receiver.receiveSpan(span); } }
void detachScope(TraceScope scope) { TraceScope curScope = threadLocalScope.get(); if (curScope != scope) { throwClientError("Can't detach TraceScope for " + scope.getSpan().toJson() + " because it is not the current " + "TraceScope in thread " + Thread.currentThread().getName()); } ThreadContext context = threadContext.get(); context.popScope(); threadLocalScope.set(scope.getParent()); }
/** * Test calling reattach() two times on a scope object. */ @Test public void TestDoubleReattachIsCaught() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestDoubleReattach"). tracerPool(new TracerPool("TestDoubleReattachIsCaught")). conf(HTraceConfiguration. fromKeyValuePairs("sampler.classes", "AlwaysSampler")).build(); boolean gotException = false; TraceScope myScope = tracer.newScope("myScope"); myScope.detach(); myScope.reattach(); try { myScope.reattach(); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("it is not detached.")); gotException = true; } assertTrue("Expected to get exception because of double TraceScope " + "reattach.", gotException); tracer.close(); }
/** * @param tracer The Tracer to use for tracing. * @param parent The TraceScope to read parent span ID from. * @param runnable The Runnable that will be executed. * @param description An optional description to set on the trace when executing. * @deprecated Use {@link #TraceRunnable(Tracer, SpanId, Runnable, String)} instead. */ @Deprecated public TraceRunnable(Tracer tracer, TraceScope parent, Runnable runnable, String description) { this(tracer, parent.getSpanId(), runnable, description); }
/** * Create and initialize a new instance of a FileSystem. * @param uri URI containing the FS schema and FS details * @param conf configuration to use to look for the FS instance declaration * and to pass to the {@link FileSystem#initialize(URI, Configuration)}. * @return the initialized filesystem. * @throws IOException problems loading or initializing the FileSystem */ private static FileSystem createFileSystem(URI uri, Configuration conf) throws IOException { Tracer tracer = FsTracer.get(conf); try(TraceScope scope = tracer.newScope("FileSystem#createFileSystem")) { scope.addKVAnnotation("scheme", uri.getScheme()); Class<?> clazz = getFileSystemClass(uri.getScheme(), conf); FileSystem fs = (FileSystem)ReflectionUtils.newInstance(clazz, conf); fs.initialize(uri, conf); return fs; } }
try (TraceScope scope = TraceUtil.createTrace(getSpanName())) { if (scope != null) { span = scope.getSpan();
if (tracer != null) { scope = tracer.newScope("Groups#fetchGroupList"); scope.addKVAnnotation("user", user); } finally { if (scope != null) { scope.close();