Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Add a Tracer.close() method (#78)
Browse files Browse the repository at this point in the history
- shuts down the reporter and sampler used by the tracer
  • Loading branch information
vprithvi authored Oct 20, 2016
1 parent 64ee845 commit 1122ab7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions jaeger-core/src/main/java/com/uber/jaeger/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ public <T> io.opentracing.SpanContext extract(Format<T> format, T carrier) {
return extractor.extract(carrier);
}

/**
* Shuts down the {@link Reporter} and {@link Sampler}
*/
public void close(){
reporter.close();
sampler.close();
}

private class SpanBuilder implements io.opentracing.Tracer.SpanBuilder {

private String operationName = null;
Expand Down
22 changes: 17 additions & 5 deletions jaeger-core/src/test/java/com/uber/jaeger/TracerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
*/
package com.uber.jaeger;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import com.uber.jaeger.metrics.InMemoryStatsReporter;
import com.uber.jaeger.propagation.Injector;
import com.uber.jaeger.reporters.InMemoryReporter;
import com.uber.jaeger.reporters.Reporter;
import com.uber.jaeger.samplers.ConstSampler;
import com.uber.jaeger.samplers.Sampler;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.propagation.TextMapExtractAdapter;
Expand All @@ -36,11 +43,6 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class TracerTest {

Tracer tracer;
Expand Down Expand Up @@ -132,4 +134,14 @@ public void testServiceNameNotNull() {
public void testServiceNameNotEmptyNull() {
new Tracer.Builder(" ", new InMemoryReporter(), new ConstSampler(true));
}

@Test
public void testClose(){
Reporter reporter = mock(Reporter.class);
Sampler sampler = mock(Sampler.class);
tracer = new Tracer.Builder("bonda", reporter, sampler).build();
tracer.close();
verify(reporter).close();
verify(sampler).close();
}
}

0 comments on commit 1122ab7

Please sign in to comment.