@VisibleForTesting public static synchronized void clear() { if (instance == null) { return; } try { instance.close(); } finally { instance = null; } }
tracer.close(); return exitCode;
tracer.close(); tracer = null;
@VisibleForTesting public static synchronized void clear() { if (instance == null) { return; } try { instance.close(); } finally { instance = null; } }
tracer.close(); return exitCode;
Thread.sleep(10); parent.close(); tracer.close(); System.out.println("trace id: " + traceid);
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; }
@Test public void testWriteToLocalFile() throws IOException { String traceFileName = LocalFileSpanReceiver.getUniqueLocalTraceFileName(); Tracer tracer = new Tracer.Builder(). name("testWriteToLocalFileTracer"). tracerPool(new TracerPool("testWriteToLocalFile")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler", "span.receiver.classes", LocalFileSpanReceiver.class.getName(), "local.file.span.receiver.path", traceFileName, "tracer.id", "%{tname}")). build(); TraceScope scope = tracer.newScope("testWriteToLocalFile"); scope.close(); tracer.close(); ObjectMapper mapper = new ObjectMapper(); MilliSpan span = mapper.readValue(new File(traceFileName), MilliSpan.class); assertEquals("testWriteToLocalFile", span.getDescription()); assertEquals("testWriteToLocalFileTracer", span.getTracerId()); } }
traceCreator.createSimpleTrace(); traceCreator.createThreadedTrace(); tracer.close(); TraceGraph traceGraph = new TraceGraph(receiver.getSpans()); Collection<Span> roots = traceGraph.getSpansByParent().find(SpanId.INVALID);
@Test public void TestTracerCreateAndClose() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestSimpleScope"). tracerPool(new TracerPool("TestTracerCreateAndClose")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")). build(); POJOSpanReceiver receiver = new POJOSpanReceiver(HTraceConfiguration.EMPTY); tracer.getTracerPool().addReceiver(receiver); tracer.close(); Assert.assertTrue(receiver.getSpans().isEmpty()); }
@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); }
/** * Test calling detach() two times on a scope object. */ @Test public void TestDoubleDetachIsCaught() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestDoubleDetach"). tracerPool(new TracerPool("TestDoubleDetachIsCaught")). conf(HTraceConfiguration. fromKeyValuePairs("sampler.classes", "AlwaysSampler")).build(); boolean gotException = false; TraceScope myScope = tracer.newScope("myScope"); myScope.detach(); try { myScope.detach(); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("it is already detached.")); gotException = true; } assertTrue("Expected to get exception because of double TraceScope " + "detach.", gotException); tracer.close(); }
/** * Test calling detach() two times on a scope object. */ @Test public void TestDoubleDetachOnNullScope() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestDoubleDetachOnNullScope"). tracerPool(new TracerPool("TestDoubleDetachOnNullScope")). conf(HTraceConfiguration. fromKeyValuePairs("sampler.classes", "NeverSampler")).build(); boolean gotException = false; TraceScope myScope = tracer.newScope("myScope"); myScope.detach(); try { myScope.detach(); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("it is already detached.")); gotException = true; } assertTrue("Expected to get exception because of double TraceScope " + "detach on NullScope.", gotException); tracer.close(); }
/** * Test closing an outer scope when an inner one is still active. */ @Test public void TestClosingOuterScope() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestClosingOuterScopeTracer"). tracerPool(new TracerPool("TestClosingOuterScope")). conf(HTraceConfiguration. fromKeyValuePairs("sampler.classes", "AlwaysSampler")).build(); boolean gotException = false; TraceScope outerScope = tracer.newScope("outer"); TraceScope innerScope = tracer.newScope("inner"); try { outerScope.close(); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("it is not the current TraceScope")); gotException = true; } assertTrue("Expected to get exception because of improper " + "scope closure.", gotException); innerScope.close(); tracer.close(); }
/** * 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(); }
@Test(timeout=120000) public void testSimpleTraces() throws IOException, InterruptedException { Tracer tracer = newTracer(); Span rootSpan = new MilliSpan.Builder(). description("root"). spanId(new SpanId(100, 100)). tracerId("test"). begin(System.currentTimeMillis()). build(); TraceScope rootScope = tracer.newScope("root"); TraceScope innerOne = tracer.newScope("innerOne"); TraceScope innerTwo = tracer.newScope("innerTwo"); innerTwo.close(); Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("innerTwo")); innerOne.close(); Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("innerOne")); rootSpan.addKVAnnotation("foo", "bar"); rootSpan.addTimelineAnnotation("timeline"); rootScope.close(); Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("root")); tracer.close(); }
@Test public void testSimpleTraces() throws IOException, InterruptedException { FakeZipkinTransport transport = new FakeZipkinTransport(); Tracer tracer = newTracer(transport); Span rootSpan = new MilliSpan.Builder(). description("root"). spanId(new SpanId(100, 100)). tracerId("test"). begin(System.currentTimeMillis()). build(); TraceScope rootScope = tracer.newScope("root"); TraceScope innerOne = tracer.newScope("innerOne"); TraceScope innerTwo = tracer.newScope("innerTwo"); innerTwo.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerTwo")); innerOne.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerOne")); rootSpan.addKVAnnotation("foo", "bar"); rootSpan.addTimelineAnnotation("timeline"); rootScope.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("root")); tracer.close(); }