{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public final class Tracing
Tracing is a singleton to interact with registered Tracer implementations.
Support for actual tracing libraries is done by implementing wrappers following the Tracer interface. The actual Tracer implementations must be registered using registerTracer.
The Tracing singleton is also an entry point used to create the root span for any tests by invoking the beginSpan method. The returned Span object must be properly closed by invoking the Span#close() method or wrapping them in a try-resource block.
Public constructors |
|
|---|---|
Tracing() |
|
Public methods |
|
|---|---|
Tracer.Span |
Returns a new Span as a managed resource in a try{} block. |
static Tracing |
Static getter for external access to the singleton. |
void |
registerTracer(Tracer tracer)Registers a new tracer. |
void |
unregisterTracer(Tracer tracer)Unregisters a tracer. |
public Tracer.Span beginSpan(String name)
Returns a new Span as a managed resource in a try{} block. Span#close() is automatically called when the resource is released.
| Parameters | |
|---|---|
String name |
A non-null name describing this span. |
public static Tracing getInstance()
Static getter for external access to the singleton. Preferred method for internal Espresso is getting this singleton via dagger injection.
public void registerTracer(Tracer tracer)
Registers a new tracer.
Once a tracer is registered, it starts being invoked for new root beginSpan calls. Existing in-flight spans do not invoke the new tracer.
| Parameters | |
|---|---|
Tracer tracer |
A non-null Tracer object. A previously registered instance is ignored. |
public void unregisterTracer(Tracer tracer)
Unregisters a tracer.
Once a tracer is unregistered, it will stop being invoked for any new root beginSpan calls made or any new Span#beginChildSpan(String). However the tracer is still be called for any in-flight spans being closed.
| Parameters | |
|---|---|
Tracer tracer |
A Tracer object. A null reference or non-registered instance is ignored. |