HttpMetric | Doclava
public class

HttpMetric

extends Object
java.lang.Object
   ↳ com.google.firebase.perf.metrics.HttpMetric

Class Overview

Metric used to collect data for network requests/responses. A new object must be used for every request/response. This class is not thread safe.

Summary

Constants
int MAX_ATTRIBUTE_KEY_LENGTH Maximum allowed length of the Key of the Trace attribute
int MAX_ATTRIBUTE_VALUE_LENGTH Maximum allowed length of the Value of the Trace attribute
int MAX_TRACE_CUSTOM_ATTRIBUTES Maximum allowed number of attributes allowed in a trace.
int MAX_TRACE_NAME_LENGTH Maximum allowed length of the name of the Trace
Public Methods
String getAttribute(String attribute)
Returns the value of an attribute.
Map<String, String> getAttributes()
Returns the map of all the attributes added to this HttpMetric.
void putAttribute(String attribute, String value)
Sets a String value for the specified attribute.
void removeAttribute(String attribute)
Removes an already added attribute from the HttpMetric.
void setHttpResponseCode(int responseCode)
Sets the httpResponse code of the request
void setRequestPayloadSize(long bytes)
Sets the size of the request payload
void setResponseContentType(String contentType)
Content type of the response such as text/html, application/json, etc...
void setResponsePayloadSize(long bytes)
Sets the size of the response payload
void start()
Marks the start time of the request
void stop()
Marks the end time of the response and queues the network request metric on the device for transmission.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MAX_ATTRIBUTE_KEY_LENGTH

Maximum allowed length of the Key of the Trace attribute

Constant Value: 40 (0x00000028)

public static final int MAX_ATTRIBUTE_VALUE_LENGTH

Maximum allowed length of the Value of the Trace attribute

Constant Value: 100 (0x00000064)

public static final int MAX_TRACE_CUSTOM_ATTRIBUTES

Maximum allowed number of attributes allowed in a trace.

Constant Value: 5 (0x00000005)

public static final int MAX_TRACE_NAME_LENGTH

Maximum allowed length of the name of the Trace

Constant Value: 100 (0x00000064)

Public Methods

public String getAttribute (String attribute)

Returns the value of an attribute.

Parameters
attribute String: name of the attribute to fetch the value for
Returns
String The value of the attribute if it exists or null otherwise.

public Map<String, String> getAttributes ()

Returns the map of all the attributes added to this HttpMetric.

Returns
Map<String, String> map of attributes and its values currently added to this HttpMetric

public void putAttribute (String attribute, String value)

Sets a String value for the specified attribute. Updates the value of the attribute if the attribute already exists. If the HttpMetric has been stopped, this method returns without adding the attribute. The maximum number of attributes that can be added to a HttpMetric are .MAX_TRACE_CUSTOM_ATTRIBUTES.

Parameters
attribute String: name of the attribute
value String: value of the attribute
Returns
void true if the attribute was added, false otherwise.

public void removeAttribute (String attribute)

Removes an already added attribute from the HttpMetric. If the HttpMetric has already been stopped, this method returns without removing the attribute.

Parameters
attribute String: name of the attribute to be removed from the running Traces.

public void setHttpResponseCode (int responseCode)

Sets the httpResponse code of the request

Parameters
responseCode int: valid values are greater than 0. Invalid usage will be logged.

public void setRequestPayloadSize (long bytes)

Sets the size of the request payload

Parameters
bytes long: valid values are greater than or equal to 0. Invalid usage will be logged.

public void setResponseContentType (String contentType)

Content type of the response such as text/html, application/json, etc...

Parameters
contentType String: valid string of MIME type. Invalid usage will be logged.

public void setResponsePayloadSize (long bytes)

Sets the size of the response payload

Parameters
bytes long: valid values are greater than or equal to 0. Invalid usage will be logged.

public void start ()

Marks the start time of the request

public void stop ()

Marks the end time of the response and queues the network request metric on the device for transmission. Check logcat for transmission info.