Invertase
Invertase

Notice: This documentation is currently a work in progress for the upcoming v6 release and some content may be missing or incomplete. If you're not interested in testing out the alpha version of v6 then please click here to be taken to the v5 documentation.

message  Send Feedback

HttpMetric

Metric used to collect data for network requests/responses. A new instance must be used for every request/response.

Methods

getAttribute

getAttribute(attribute: string): string | null;

Returns the value of an attribute. Returns null if it does not exist.

Example

const attribute = metric.getAttribute('user_role');
Parameters
  • attribute
    Name of the attribute to fetch the value of

getAttributes

getAttributes(): { [key: string]: string };

Returns an object of all the currently added attributes.

Example

const attributes = metric.getAttributes();
attributes.forEach(($) => {
console.log($);
});

putAttribute

putAttribute(attribute: string, value: string): any;

Sets a String value for the specified attribute. Updates the value of the attribute if it already exists. The maximum number of attributes that can be added is 5.

Example

metric.putAttribute('user_role', 'admin');
Parameters
  • attribute
    Name of the attribute. Max length is 40 chars.
  • value
    Value of the attribute. Max length is 100 chars.

removeAttribute

removeAttribute(attribute: string): any;

Removes an already added attribute. Does nothing if attribute does not exist.

Example

metric.removeAttribute('user_role');
Parameters
  • attribute
    Name of the attribute to be removed.

setHttpResponseCode

setHttpResponseCode(code: number | null): any;

Sets the httpResponse code of the request.

Example

const response = await fetch(url);
metric.setHttpResponseCode(response.status);

This is required for every request, if you do not provide this your metric will not be captured.

Parameters
  • code
    Value must be greater than 0. Set to null to remove. Invalid usage will be logged natively.

setRequestPayloadSize

setRequestPayloadSize(bytes: number | null): any;

Sets the size of the request payload.

Example

const response = await fetch(url);
metric.setRequestPayloadSize(response.headers.get('Content-Type'));
Parameters
  • bytes
    Value must be greater than 0. Set to null to remove. Invalid usage will be logged natively.

setResponseContentType

setResponseContentType(contentType: string | null): any;

Content type of the response e.g. text/html or application/json.

Example

const response = await fetch(url);
metric.setResponsePayloadSize(response.headers.get('Content-Type'));
Parameters
  • contentType
    Valid string of MIME type. Set to null to remove. Invalid usage will be logged natively.

setResponsePayloadSize

setResponsePayloadSize(bytes: number | null): any;

Sets the size of the response payload.

Example

const response = await fetch(url);
metric.setResponsePayloadSize(response.headers.get('Content-Length'));
Parameters
  • bytes
    Value must be greater than 0. Set to null to remove. Invalid usage will be logged natively.

start

start(): Promise<null>;

Marks the start time of the request. Does nothing if already started.

Example

const metric = firebase.perf().newHttpMetric('https://api.com/login', 'POST');
await metric.start();

stop

stop(): Promise<null>;

Marks the end time of the response and queues the network request metric on the device for transmission. Does nothing if already stopped.

Example

const metric = firebase.perf().newHttpMetric('https://api.com/login', 'POST');
await metric.start();
metric.putAttribute('user_role', 'admin');
await metric.stop();