FirebasePerformance

@Singleton
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)
annotation FirebasePerformance.HttpMethod

Valid HttpMethods for manual network APIs

Constants

const Int

Maximum allowed length of the Key of the Trace attribute

const Int

Maximum allowed length of the Value of the Trace attribute

const Int

Maximum allowed number of attributes allowed in a trace.

const Int

Maximum allowed length of the name of the Trace

const Int

Maximum allowed length of the name of the Trace

Public functions

java-static FirebasePerformance

Returns a singleton of FirebasePerformance.

Boolean

Determines whether performance monitoring is enabled or disabled.

HttpMetric
newHttpMetric(
    url: String,
    @FirebasePerformance.HttpMethod httpMethod: String
)

Creates a HttpMetric object for collecting network performance data for one request/response

HttpMetric

Creates a HttpMetric object for collecting network performance data for one request/response

Trace
newTrace(traceName: String)

Creates a Trace object with given name.

Unit

Enables or disables performance monitoring.

java-static Trace
startTrace(traceName: String)

Creates a Trace object with given name and start the trace.

Constants

MAX_ATTRIBUTE_KEY_LENGTH

const val MAX_ATTRIBUTE_KEY_LENGTH = 40: Int

Maximum allowed length of the Key of the Trace attribute

MAX_ATTRIBUTE_VALUE_LENGTH

const val MAX_ATTRIBUTE_VALUE_LENGTH = 100: Int

Maximum allowed length of the Value of the Trace attribute

MAX_TRACE_CUSTOM_ATTRIBUTES

const val MAX_TRACE_CUSTOM_ATTRIBUTES = 5: Int

Maximum allowed number of attributes allowed in a trace.

MAX_TRACE_NAME_LENGTH

const val MAX_TRACE_NAME_LENGTH = 100: Int

Maximum allowed length of the name of the Trace

MAX_TRACE_NAME_LENGTH

const val MAX_TRACE_NAME_LENGTH = 100: Int

Maximum allowed length of the name of the Trace

Public functions

getInstance

java-static fun getInstance(): FirebasePerformance

Returns a singleton of FirebasePerformance.

Returns
FirebasePerformance

the singleton FirebasePerformance object.

isPerformanceCollectionEnabled

fun isPerformanceCollectionEnabled(): Boolean

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

fun newHttpMetric(
    url: String,
    @FirebasePerformance.HttpMethod httpMethod: String
): HttpMetric

Creates a HttpMetric object for collecting network performance data for one request/response

Parameters
url: String

a valid url String, cannot be empty

@FirebasePerformance.HttpMethod httpMethod: String

One of the values GET, PUT, POST, DELETE, HEAD, PATCH, OPTIONS, TRACE, or CONNECT

Returns
HttpMetric

the new HttpMetric object.

newHttpMetric

fun newHttpMetric(url: URL, @FirebasePerformance.HttpMethod httpMethod: String): HttpMetric

Creates a HttpMetric object for collecting network performance data for one request/response

Parameters
url: URL

a valid URL object

@FirebasePerformance.HttpMethod httpMethod: String

One of the values GET, PUT, POST, DELETE, HEAD, PATCH, OPTIONS, TRACE, or CONNECT

Returns
HttpMetric

the new HttpMetric object.

newTrace

fun newTrace(traceName: String): Trace

Creates a Trace object with given name.

Parameters
traceName: String

name of the trace, requires no leading or trailing whitespace, no leading underscore '_' character, max length is MAX_TRACE_NAME_LENGTH characters.

Returns
Trace

the new Trace object.

setPerformanceCollectionEnabled

fun setPerformanceCollectionEnabled(enable: Boolean): Unit

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 />
to your application’s manifest. Changing the value during runtime will override the manifest value.

If you want to permanently disable sending performance metrics, add

<meta-data android:name="firebase_performance_collection_deactivated" android:value="true" />
to your application's manifest. Changing the value during runtime will not override the manifest value.

This is separate from enabling/disabling instrumentation in Gradle properties.

Parameters
enable: Boolean

Should performance monitoring be enabled

startTrace

java-static fun startTrace(traceName: String): Trace

Creates a Trace object with given name and start the trace.

Parameters
traceName: String

name of the trace. Requires no leading or trailing whitespace, no leading underscore [_] character, max length of MAX_TRACE_NAME_LENGTH characters.

Returns
Trace

the new Trace object.