org.htrace
Class Trace

java.lang.Object
  extended by org.htrace.Trace

public class Trace
extends Object

The primary way to interact with the library. Provides methods to start spans, as well as set necessary tracing information.


Constructor Summary
Trace()
           
 
Method Summary
static void addKVAnnotation(byte[] key, byte[] value)
          Adds a data annotation to the current span if tracing is currently on.
static void addReceiver(SpanReceiver rcvr)
          Adds the given SpanReceiver to the current Tracer instance's list of SpanReceivers.
static void addTimelineAnnotation(String msg)
          Annotate the current span with the given message.
static TraceScope continueSpan(Span s)
          Pick up an existing span from another thread.
static Span currentSpan()
          If we are tracing, return the current span, else null
static boolean isTracing()
          Returns true if the current thread is a part of a trace, false otherwise.
static void removeReceiver(SpanReceiver rcvr)
          Removes the given SpanReceiver from the list of SpanReceivers.
static void setProcessId(String processId)
          Set the processId to be used for all Spans created by this Tracer.
static TraceScope startSpan(String description)
          Starts and returns a new span as the child of the current span if the default sampler (TrueIfTracingSampler) returns true, otherwise returns the NullSpan.
static
<T> TraceScope
startSpan(String description, Sampler<T> s)
           
static
<T> TraceScope
startSpan(String description, Sampler<T> s, T info)
           
static TraceScope startSpan(String description, Sampler<TraceInfo> s, TraceInfo tinfo)
           
static TraceScope startSpan(String description, Span parent)
          Starts and returns a new span as the child of the parameter 'parent'.
static TraceScope startSpan(String description, TraceInfo tinfo)
           
static
<V> Callable<V>
wrap(Callable<V> callable)
          Wrap the callable in a TraceCallable, if tracing.
static Runnable wrap(Runnable runnable)
          Wrap the runnable in a TraceRunnable, if tracing
static Runnable wrap(String description, Runnable runnable)
          Wrap the runnable in a TraceRunnable, if tracing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Trace

public Trace()
Method Detail

startSpan

public static TraceScope startSpan(String description)
Starts and returns a new span as the child of the current span if the default sampler (TrueIfTracingSampler) returns true, otherwise returns the NullSpan.

Parameters:
description - Description of the span to be created.
Returns:

startSpan

public static TraceScope startSpan(String description,
                                   Span parent)
Starts and returns a new span as the child of the parameter 'parent'. This will always return a new span, even if tracing wasn't previously enabled for this thread.

Parameters:
description - Description of the span to be created.
parent - The parent that should be used to create the child span that is to be returned.
Returns:

startSpan

public static TraceScope startSpan(String description,
                                   TraceInfo tinfo)

startSpan

public static <T> TraceScope startSpan(String description,
                                       Sampler<T> s)

startSpan

public static TraceScope startSpan(String description,
                                   Sampler<TraceInfo> s,
                                   TraceInfo tinfo)

startSpan

public static <T> TraceScope startSpan(String description,
                                       Sampler<T> s,
                                       T info)

continueSpan

public static TraceScope continueSpan(Span s)
Pick up an existing span from another thread.


setProcessId

public static void setProcessId(String processId)
Set the processId to be used for all Spans created by this Tracer.

Parameters:
processId -
See Also:
Span.java

removeReceiver

public static void removeReceiver(SpanReceiver rcvr)
Removes the given SpanReceiver from the list of SpanReceivers.

Parameters:
rcvr -

addReceiver

public static void addReceiver(SpanReceiver rcvr)
Adds the given SpanReceiver to the current Tracer instance's list of SpanReceivers.

Parameters:
rcvr -

addKVAnnotation

public static void addKVAnnotation(byte[] key,
                                   byte[] value)
Adds a data annotation to the current span if tracing is currently on.


addTimelineAnnotation

public static void addTimelineAnnotation(String msg)
Annotate the current span with the given message.


isTracing

public static boolean isTracing()
Returns true if the current thread is a part of a trace, false otherwise.

Returns:

currentSpan

public static Span currentSpan()
If we are tracing, return the current span, else null

Returns:
Span representing the current trace, or null if not tracing.

wrap

public static <V> Callable<V> wrap(Callable<V> callable)
Wrap the callable in a TraceCallable, if tracing.

Parameters:
callable -
Returns:
The callable provided, wrapped if tracing, 'callable' if not.

wrap

public static Runnable wrap(Runnable runnable)
Wrap the runnable in a TraceRunnable, if tracing

Parameters:
runnable -
Returns:
The runnable provided, wrapped if tracing, 'runnable' if not.

wrap

public static Runnable wrap(String description,
                            Runnable runnable)
Wrap the runnable in a TraceRunnable, if tracing

Parameters:
description - name of the span to be created.
runnable -
Returns:
The runnable provided, wrapped if tracing, 'runnable' if not.


Copyright © 2014. All Rights Reserved.