@Test public void testSingleSpan() throws Exception { LOG.info("testSingleSpan TableName: " + tracingTableName); Properties props = new Properties(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); latch = new CountDownLatch(1); testTraceWriter.start(); // create a simple metrics record long traceid = 987654; Span span = createNewSpan(traceid, Span.ROOT_SPAN_ID, 10, "root", 12, 13, "Some process", "test annotation for a span"); Tracer.getInstance().deliver(span); assertTrue("Updates not written in table", latch.await(60, TimeUnit.SECONDS)); // start a reader validateTraces(Collections.singletonList(span), conn, traceid, tracingTableName); }
/** * Finish the current trace. */ public static void off() { org.apache.htrace.Span span = org.apache.htrace.Trace.currentSpan(); if (span != null) { span.stop(); // close() will no-op, but ensure safety if the implementation changes org.apache.htrace.Tracer.getInstance().continueSpan(null).close(); } }
/** * Adds the given SpanReceiver to the current Tracer instance's list of * SpanReceivers. * * @param rcvr */ public static void addReceiver(SpanReceiver rcvr) { Tracer.getInstance().addReceiver(rcvr); }
/** * Remove this span as the current thread, but don't stop it yet or * send it for collection. This is useful if the span object is then * passed to another thread for use with Trace.continueTrace(). * * @return the same Span object */ public Span detach() { detached = true; Span cur = Tracer.getInstance().currentSpan(); if (cur != span) { Tracer.LOG.debug("Closing trace span " + span + " but " + cur + " was top-of-stack"); } else { Tracer.getInstance().setCurrentSpan(savedSpan); } return span; }
/** * Returns true if the current thread is a part of a trace, false otherwise. * * @return */ public static boolean isTracing() { return Tracer.getInstance().isTracing(); }
/** * Removes the given SpanReceiver from the list of SpanReceivers. * * @param rcvr */ public static void removeReceiver(SpanReceiver rcvr) { Tracer.getInstance().removeReceiver(rcvr); }
/** * If we are tracing, return the current span, else null * * @return Span representing the current trace, or null if not tracing. */ public static Span currentSpan() { return Tracer.getInstance().currentSpan(); }
public static <T> TraceScope startSpan(String description, Sampler<T> s, T info) { Span span = null; if (isTracing() || s.next(info)) { span = Tracer.getInstance().createNew(description); } return continueSpan(span); }
public TraceScope continueSpan(Span s) { Span oldCurrent = currentSpan(); setCurrentSpan(s); return new TraceScope(s, oldCurrent); }
protected Span createNew(String description) { Span parent = currentSpan.get(); if (parent == null) { return new MilliSpan(description, /* traceId = */ random.nextLong(), /* parentSpanId = */ Span.ROOT_SPAN_ID, /* spanId = */ random.nextLong(), getProcessId()); } else { return parent.child(description); } }
public static TraceScope startSpan(String description, TraceInfo tinfo) { if (tinfo == null) return continueSpan(null); Span newSpan = new MilliSpan(description, tinfo.traceId, tinfo.spanId, random.nextLong(), Tracer.getProcessId()); return continueSpan(newSpan); }
@Test public void testIntegerAnnotations(){ Span span = getSpan(); // add annotation through the phoenix interfaces TracingUtils.addAnnotation(span, "message", 10); TraceSpanReceiver source = new TraceSpanReceiver(); Trace.addReceiver(source); Tracer.getInstance().deliver(span); assertTrue(source.getNumSpans() == 1); }
/** * Pick up an existing span from another thread. */ public static TraceScope continueSpan(Span s) { // Return an empty TraceScope that does nothing on close if (s == null) return NullScope.INSTANCE; return Tracer.getInstance().continueSpan(s); }
public static TraceScope startSpan(String description, Sampler<TraceInfo> s, TraceInfo tinfo) { Span span = null; if (isTracing() || s.next(tinfo)) { span = new MilliSpan(description, tinfo.traceId, tinfo.spanId, random.nextLong(), Tracer.getProcessId()); } return continueSpan(span); }
/** * For PHOENIX-1126, Phoenix originally assumed all the annotation values were integers, * but HBase writes some strings as well, so we need to be able to handle that too */ @Test public void testNonIntegerAnnotations(){ Span span = getSpan(); // make sure its less than the length of an integer byte[] value = Bytes.toBytes("a"); byte[] someInt = Bytes.toBytes(1); assertTrue(someInt.length > value.length); // an annotation that is not an integer span.addKVAnnotation(Bytes.toBytes("key"), value); // Create the sink and write the span TraceSpanReceiver source = new TraceSpanReceiver(); Trace.addReceiver(source); Tracer.getInstance().deliver(span); assertTrue(source.getNumSpans() == 1); }
public static void endThread(Span span) { if (span != null) { span.stop(); // close() will no-op, but ensure safety if the implementation changes org.apache.htrace.Tracer.getInstance().continueSpan(null).close(); } }
Tracer.getInstance().deliver(span1);
/** * Finish the current trace. */ public static void off() { org.apache.htrace.Span span = org.apache.htrace.Trace.currentSpan(); if (span != null) { span.stop(); // close() will no-op, but ensure safety if the implementation changes org.apache.htrace.Tracer.getInstance().continueSpan(null).close(); } }
processid, annotation); Tracer.getInstance().deliver(span); assertTrue("Span never committed to table", latch.await(30, TimeUnit.SECONDS));
@Override public synchronized void stop() { if (end == 0) { if (begin == 0) throw new IllegalStateException("Span for " + description + " has not been started"); end = System.currentTimeMillis(); Tracer.getInstance().deliver(this); } }