FirebasePerformance
@Singleton
public class FirebasePerformance
The Firebase Performance Monitoring API.
It is automatically initialized by FirebaseApp.
This SDK uses FirebaseInstallations to identify the app instance and periodically sends data to the Firebase backend. To stop sending performance events, call FirebasePerformance.setPerformanceCollectionEnabled(false).
Summary
Nested types |
|---|
@Retention(value = RetentionPolicy.SOURCE)Valid HttpMethods for manual network APIs |
Constants |
|
|---|---|
static final int |
Maximum allowed length of the Key of the |
static final int |
Maximum allowed length of the Value of the |
static final int |
Maximum allowed number of attributes allowed in a trace. |
static final int |
MAX_TRACE_NAME_LENGTH = 100Maximum allowed length of the name of the |
static final int |
MAX_TRACE_NAME_LENGTH = 100Maximum allowed length of the name of the |
Public methods |
|
|---|---|
static @NonNull FirebasePerformance |
Returns a singleton of FirebasePerformance. |
boolean |
Determines whether performance monitoring is enabled or disabled. |
@NonNull HttpMetric |
newHttpMetric(Creates a HttpMetric object for collecting network performance data for one request/response |
@NonNull HttpMetric |
newHttpMetric(Creates a HttpMetric object for collecting network performance data for one request/response |
@NonNull Trace |
Creates a Trace object with given name. |
void |
setPerformanceCollectionEnabled(boolean enable)Enables or disables performance monitoring. |
static @NonNull Trace |
startTrace(@NonNull String traceName)Creates a Trace object with given name and start the trace. |
Constants
MAX_ATTRIBUTE_KEY_LENGTH
public static final int MAX_ATTRIBUTE_KEY_LENGTH = 40
Maximum allowed length of the Key of the Trace attribute
MAX_ATTRIBUTE_VALUE_LENGTH
public static final int MAX_ATTRIBUTE_VALUE_LENGTH = 100
Maximum allowed length of the Value of the Trace attribute
MAX_TRACE_CUSTOM_ATTRIBUTES
public static final int MAX_TRACE_CUSTOM_ATTRIBUTES = 5
Maximum allowed number of attributes allowed in a trace.
MAX_TRACE_NAME_LENGTH
public static final int MAX_TRACE_NAME_LENGTH = 100
Maximum allowed length of the name of the Trace
MAX_TRACE_NAME_LENGTH
public static final int MAX_TRACE_NAME_LENGTH = 100
Maximum allowed length of the name of the Trace
Public methods
getInstance
public static @NonNull FirebasePerformance getInstance()
Returns a singleton of FirebasePerformance.
| Returns | |
|---|---|
@NonNull FirebasePerformance |
the singleton FirebasePerformance object. |
isPerformanceCollectionEnabled
public boolean isPerformanceCollectionEnabled()
Determines whether performance monitoring is enabled or disabled. This respects the Firebase Performance specific values first, and if these aren't set, uses the Firebase wide data collection switch.
| Returns | |
|---|---|
boolean |
true if performance monitoring is enabled and false if performance monitoring is disabled. This is for dynamic enable/disable state. This does not reflect whether instrumentation is enabled/disabled in Gradle properties. |
newHttpMetric
public @NonNull HttpMetric newHttpMetric(
@NonNull String url,
@FirebasePerformance.HttpMethod @NonNull String httpMethod
)
Creates a HttpMetric object for collecting network performance data for one request/response
| Parameters | |
|---|---|
@NonNull String url |
a valid url String, cannot be empty |
@FirebasePerformance.HttpMethod @NonNull String httpMethod |
One of the values GET, PUT, POST, DELETE, HEAD, PATCH, OPTIONS, TRACE, or CONNECT |
| Returns | |
|---|---|
@NonNull HttpMetric |
the new HttpMetric object. |
newHttpMetric
public @NonNull HttpMetric newHttpMetric(
@NonNull URL url,
@FirebasePerformance.HttpMethod @NonNull String httpMethod
)
Creates a HttpMetric object for collecting network performance data for one request/response
| Parameters | |
|---|---|
@NonNull URL url |
a valid URL object |
@FirebasePerformance.HttpMethod @NonNull String httpMethod |
One of the values GET, PUT, POST, DELETE, HEAD, PATCH, OPTIONS, TRACE, or CONNECT |
| Returns | |
|---|---|
@NonNull HttpMetric |
the new HttpMetric object. |
newTrace
public @NonNull Trace newTrace(@NonNull String traceName)
Creates a Trace object with given name.
| Parameters | |
|---|---|
@NonNull String traceName |
name of the trace, requires no leading or trailing whitespace, no leading underscore '_' character, max length is |
setPerformanceCollectionEnabled
public void setPerformanceCollectionEnabled(boolean enable)
Enables or disables performance monitoring. This setting is persisted and applied on future invocations of your application. By default, performance monitoring is enabled. If you need to change the default (for example, because you want to prompt the user before collecting performance stats), add:
<meta-data android:name=firebase_performance_collection_enabled android:value=false />
If you want to permanently disable sending performance metrics, add
<meta-data android:name="firebase_performance_collection_deactivated" android:value="true" />
This is separate from enabling/disabling instrumentation in Gradle properties.
| Parameters | |
|---|---|
boolean enable |
Should performance monitoring be enabled |
startTrace
public static @NonNull Trace startTrace(@NonNull String traceName)
Creates a Trace object with given name and start the trace.
| Parameters | |
|---|---|
@NonNull String traceName |
name of the trace. Requires no leading or trailing whitespace, no leading underscore [_] character, max length of |