InMemoryMetricsFactory implements MetricsFactory { public long getCounter(String name, String tags) { return getValue(counters, name, tags); }  @Override Counter createCounter(String name, Map<String, String> tags); @Override Timer createTimer(final String name, final Map<String, String> tags); @Override Gauge createGauge(final String name, final Map<String, String> tags); long getCounter(String name, String tags); long getCounter(String name, Map<String, String> tags); long getGauge(String name, String tags); long getGauge(String name, Map<String, String> tags); long getTimer(String name, String tags); long getTimer(String name, Map<String, String> tags);  }
@Test public void emptyValueForTag() { InMemoryMetricsFactory metricsFactory = new InMemoryMetricsFactory(); JaegerTracer tracer = new JaegerTracer.Builder("metricsFactoryTest") .withReporter(new InMemoryReporter()) .withSampler(new ConstSampler(true)) .withMetrics(new Metrics(metricsFactory)) .build(); tracer.buildSpan("theoperation").start(); assertEquals(-1, metricsFactory.getCounter("jaeger_tracer_started_spans", "sampled")); assertEquals(-1, metricsFactory.getCounter("jaeger_tracer_started_spans", "")); }
@Test public void canBeUsedWithMetrics() { InMemoryMetricsFactory metricsFactory = new InMemoryMetricsFactory(); JaegerTracer tracer = new JaegerTracer.Builder("metricsFactoryTest") .withReporter(new InMemoryReporter()) .withSampler(new ConstSampler(true)) .withMetrics(new Metrics(metricsFactory)) .build(); tracer.buildSpan("theoperation").start(); assertEquals(1, metricsFactory.getCounter("jaeger_tracer_started_spans", "sampled=y")); assertEquals(0, metricsFactory.getCounter("jaeger_tracer_started_spans", "sampled=n")); assertEquals(1, metricsFactory.getCounter("jaeger_tracer_traces", "sampled=y,state=started")); assertEquals(0, metricsFactory.getCounter("jaeger_tracer_traces", "sampled=n,state=started")); }