# Tracer.Companion

Artifact: [androidx.tracing:tracing](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/Tracer.kt+class:androidx.tracing.Tracer.Companion) Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

*** ** * ** ***


```
public static class Tracer.Companion
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer` | `https://developer.android.com/reference/androidx/tracing/Tracer#getGlobal()()` The Global tracer configured by the application. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer` | `https://developer.android.com/reference/androidx/tracing/Tracer#getStubTracer()()` |
| `static final void` | `@https://developer.android.com/reference/androidx/annotation/VisibleForTesting https://developer.android.com/reference/androidx/tracing/Tracer.Companion#resetGlobalTracer()()` Resets the `https://developer.android.com/reference/androidx/tracing/Tracer` for JVM and Android tests. |
| `static final void` | `@https://developer.android.com/reference/androidx/tracing/DelicateTracingApi https://developer.android.com/reference/androidx/tracing/Tracer#setGlobalTracer(androidx.tracing.Tracer)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer tracer)` Registers the **global** `https://developer.android.com/reference/androidx/tracing/Tracer` instance. |

## Public methods

### getGlobal

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public static final @NonNull Tracer getGlobal()
```

The Global tracer configured by the application.

This is the `https://developer.android.com/reference/androidx/tracing/Tracer` that should be used by both application and library developers. You should always use `https://developer.android.com/reference/androidx/tracing/Tracer.Companion#global()` and **not** cache references this field, given the `https://developer.android.com/reference/androidx/tracing/Tracer` being used, is updated after the application is initialized.

The `https://developer.android.com/reference/androidx/tracing/Tracer.Companion#global()` tracer is typically bootstrapped during process startup. When using `androidx.tracing:tracing-wire`, `androidx.tracing.profiler.ConnectedProfilerTracingInitializer` discovers the `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver.Factory`, and constructs the instance. It then registers a global `https://developer.android.com/reference/androidx/tracing/Tracer` by calling `https://developer.android.com/reference/androidx/tracing/Tracer#setGlobalTracer(androidx.tracing.Tracer)`.

Otherwise, construct `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver` during startup and register it via `https://developer.android.com/reference/androidx/tracing/Tracer#setGlobalTracer(androidx.tracing.Tracer)` so other components can discover and use it.

### getStubTracer

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public static final @NonNull Tracer getStubTracer()
```

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer` | a `https://developer.android.com/reference/androidx/tracing/Tracer` instance that is a stub (does nothing). This is useful as a placeholder when you want to enable / disable tracing for the program. |

### resetGlobalTracer

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
@VisibleForTesting
public static final void resetGlobalTracer()
```

Resets the `https://developer.android.com/reference/androidx/tracing/Tracer` for JVM and Android tests.

Note: This API should only be used in tests.

### setGlobalTracer

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
@DelicateTracingApi
public static final void setGlobalTracer(@NonNull Tracer tracer)
```

Registers the **global** `https://developer.android.com/reference/androidx/tracing/Tracer` instance.

This should only ever be done **once** per process lifecycle and by the application initializing the `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver`; typically during app startup.

This should **never** be called by **libraries**.