private Tracer newTracer() { return new Tracer.Builder(). name("FlumeTracer"). tracerPool(new TracerPool("newTracer")). conf(HTraceConfiguration.fromKeyValuePairs( FlumeSpanReceiver.FLUME_PORT_KEY, Integer.toString(flumeServer.getPort()), "span.receiver.classes", FlumeSpanReceiver.class.getName(), "sampler.classes", AlwaysSampler.class.getName() )).build(); }
Tracer tracer = new Tracer.Builder(). name("TestCreateSpans"). tracerPool(new TracerPool("TestCreateSpans")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")).
Tracer tracer = new Tracer.Builder(). name("testHBaseSpanReceiver"). tracerPool(new TracerPool("testHBaseSpanReceiver")). conf(HTraceConfiguration.fromKeyValuePairs( HBaseSpanReceiver.COLLECTOR_QUORUM_KEY,
final Tracer tracer = new Tracer.Builder(). name("TestPassingSpanBetweenThreads"). tracerPool(new TracerPool("TestPassingSpanBetweenThreads")). conf(HTraceConfiguration. fromKeyValuePairs("sampler.classes", "AlwaysSampler")).build();
.tracerPool(new TracerPool("test-tracer-pool")) .conf(hTraceConfiguration) .build();
tracerPool(new TracerPool("testNewScopeWithParentID")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")).build();
/** * 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 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 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 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()); } }
@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(timeout=60000) public void testRootSpansHaveNonZeroSpanId() throws Exception { Tracer tracer = new Tracer.Builder(). name("testRootSpansHaveNonZeroSpanId"). tracerPool(new TracerPool("testRootSpansHaveNonZeroSpanId")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")).build(); TraceScope scope = tracer. newScope("myRootSpan", new SpanId(100L, 200L)); Assert.assertNotNull(scope); Assert.assertEquals("myRootSpan", scope.getSpan().getDescription()); Assert.assertTrue(scope.getSpan().getSpanId().isValid()); Assert.assertEquals(100L, scope.getSpan().getSpanId().getHigh()); Assert.assertNotEquals(0L, scope.getSpan().getSpanId().getLow()); scope.close(); } }
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 Tracer newTracer(final Transport transport) { TracerPool pool = new TracerPool("newTracer"); pool.addReceiver(new ZipkinSpanReceiver(HTraceConfiguration.EMPTY) { @Override protected Transport createTransport(HTraceConfiguration conf) { return transport; } }); return new Tracer.Builder("ZipkinTracer"). tracerPool(pool). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", AlwaysSampler.class.getName() )). build(); }
@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 testNullScope() { Tracer tracer = new Tracer.Builder(). name("testNullScope"). tracerPool(new TracerPool("testNullScope")). conf(HTraceConfiguration.EMPTY). build(); verifyNullScope(tracer.newScope("testNullScope")); verifyNullScope(tracer.newNullScope()); } }
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; }