Skip to content

Commit

Permalink
Add enable/disable flag and change submitEndpoint based on code revie…
Browse files Browse the repository at this point in the history
…w feedback
  • Loading branch information
leigu committed Jan 31, 2014
1 parent ef3aefb commit 9007346
Showing 1 changed file with 58 additions and 18 deletions.
76 changes: 58 additions & 18 deletions brave-impl/src/main/java/com/github/kristofa/brave/BraveTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
public class BraveTracer {
private static final String REQUEST_ANNOTATION = "request";
private static final String FAILURE_ANNOTATION = "failure";
private final static Logger LOGGER = LoggerFactory.getLogger(BraveTracerTest.class);

private final static Logger LOGGER = LoggerFactory.getLogger(BraveTracer.class);

ClientTracer clientTracer;
ServerTracer serverTracer;
EndPointSubmitter endPointSubmitter;
boolean enabled = true;

public BraveTracer(ClientTracer clientTracer,
ServerTracer serverTracer, EndPointSubmitter endPointSubmitter) {
Expand All @@ -23,48 +25,86 @@ public BraveTracer(ClientTracer clientTracer,
this.serverTracer = serverTracer;
this.endPointSubmitter = endPointSubmitter;
}

public BraveTracer(ClientTracer clientTracer,
ServerTracer serverTracer, EndPointSubmitter endPointSubmitter, boolean enabled) {
this(clientTracer, serverTracer, endPointSubmitter);
this.enabled = enabled;
}

public void submitFailure()
{
clientTracer.submitAnnotation(FAILURE_ANNOTATION);
if (enabled)
{
clientTracer.submitAnnotation(FAILURE_ANNOTATION);
}
}

public void submitBinaryAnnotation(String name, int value)
{
clientTracer.submitBinaryAnnotation(name, value);
if (enabled)
{
clientTracer.submitBinaryAnnotation(name, value);
}
}
public void submitBinaryAnnotation(String name, String value)
{
clientTracer.submitBinaryAnnotation(name, value);
if (enabled)
{
clientTracer.submitBinaryAnnotation(name, value);
}
}
public void submitAnnotation(String name, String value)
{
clientTracer.submitAnnotation(value);
if (enabled)
{
clientTracer.submitAnnotation(value);
}
}
public void stopServerTracer()
{
serverTracer.setServerSend();
if (enabled)
{
serverTracer.setServerSend();
}
}
public void startClientTracer(String clientContext)
{
clientTracer.startNewSpan(clientContext);
clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, clientContext);
clientTracer.setClientSent();
if (enabled)
{
clientTracer.startNewSpan(clientContext);
clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, clientContext);
clientTracer.setClientSent();
}
}
public void stopClientTracer()
{
clientTracer.setClientReceived();
if (enabled)
{
clientTracer.setClientReceived();
}
}
public void startServerTracer(String contextPath)
{
submitEndpoint(contextPath);
LOGGER.debug("Received no span state.");
serverTracer.setStateUnknown(contextPath);
serverTracer.setServerReceived();
if (enabled)
{
submitEndpoint(contextPath);
LOGGER.debug("Received no span state.");
serverTracer.setStateUnknown(contextPath);
serverTracer.setServerReceived();
}
}
public void submitEndpoint(String contextPath) {
final String localAddr = "localhost";
final int localPort =0;
LOGGER.debug("Setting endpoint: addr: {}, port: {}, contextpath: {}", localAddr, localPort, contextPath);
endPointSubmitter.submit(localAddr, localPort, contextPath);
if (enabled)
{
final String localAddr = "localhost";
final int localPort =0;
LOGGER.debug("Setting endpoint: addr: {}, port: {}, contextpath: {}", localAddr, localPort, contextPath);
if (!endPointSubmitter.endPointSubmitted())
{
endPointSubmitter.submit(localAddr, localPort, contextPath);
}
}
}

}

0 comments on commit 9007346

Please sign in to comment.