FirebasePerformance

@Singleton
public classFirebasePerformance


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)
public annotationFirebasePerformance.HttpMethod

Valid HttpMethods for manual network APIs

Constants

static final int

Maximum allowed length of the Key of theTrace attribute

static final int

Maximum allowed length of the Value of theTrace attribute

static final int

Maximum allowed number of attributes allowed in a trace.

static final int

Maximum allowed length of the name of theTrace

static final int

Maximum allowed length of the name of theTrace

Public methods

static @NonNullFirebasePerformance

Returns a singleton of FirebasePerformance.

boolean

Determines whether performance monitoring is enabled or disabled.

@NonNullHttpMetric

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

@NonNullHttpMetric

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

@NonNullTrace
newTrace(@NonNullString traceName)

Creates a Trace object with given name.

void

Enables or disables performance monitoring.

static @NonNullTrace

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 theTrace attribute

MAX_ATTRIBUTE_VALUE_LENGTH

public static final int MAX_ATTRIBUTE_VALUE_LENGTH = 100

Maximum allowed length of the Value of theTrace 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 theTrace

MAX_TRACE_NAME_LENGTH

public static final int MAX_TRACE_NAME_LENGTH = 100

Maximum allowed length of the name of theTrace

Public methods

getInstance

public static @NonNullFirebasePerformance getInstance()

Returns a singleton of FirebasePerformance.

Returns
@NonNullFirebasePerformance

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 @NonNullHttpMetric newHttpMetric(
    @NonNullString url,
    @FirebasePerformance.HttpMethod @NonNullString httpMethod
)

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

Parameters
@NonNullString url

a valid url String, cannot be empty

@FirebasePerformance.HttpMethod @NonNullString httpMethod

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

Returns
@NonNullHttpMetric

the new HttpMetric object.

newHttpMetric

public @NonNullHttpMetric newHttpMetric(
    @NonNullURL url,
    @FirebasePerformance.HttpMethod @NonNullString httpMethod
)

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

Parameters
@NonNullURL url

a valid URL object

@FirebasePerformance.HttpMethod @NonNullString httpMethod

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

Returns
@NonNullHttpMetric

the new HttpMetric object.

newTrace

public @NonNullTrace newTrace(@NonNullString traceName)

Creates a Trace object with given name.

Parameters
@NonNullString traceName

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

Returns
@NonNullTrace

the new Trace object.

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 />
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
boolean enable

Should performance monitoring be enabled

startTrace

public static @NonNullTrace startTrace(@NonNullString traceName)

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

Parameters
@NonNullString traceName

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

Returns
@NonNullTrace

the new Trace object.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.