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

Trace

Trace allows you to time the beginning to end of a certain action in your app with additional metric values and attributes.

Methods

getAttribute

getAttribute(attribute: string): string | null;

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

Example

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

getMetric

getMetric(metricName: string): number;

Gets the value of the metric with the given name in the current trace. If the metric doesn't exist, it will not be created and a 0 is returned.

Example

const metric = trace.getMetric('hits');
Parameters
  • metricName
    Name of the metric to get.

getMetrics

getMetrics(): { [key: string]: number };

Returns an object of all the currently added metrics and their number values.

Example

const metrics = trace.getMetrics();
metrics.forEach(($) => {
console.log($);
});

incrementMetric

incrementMetric(metricName: string, incrementBy: number): any;

Increments the named metric by the incrementBy value.

If a metric with the given name doesn't exist, a new one will be created starting with the value of incrementBy.

trace.incrementMetric('hits', 1);
Parameters
  • metricName
    Name of the metric to increment. Must not have a leading or trailing whitespace, no leading underscore '_' character and have a max length of 32 characters.
  • incrementBy
    The value the metric should be incremented by.

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

trace.putAttribute('userId', '123456789');
Parameters
  • attribute
    Name of the attribute. Max length is 40 chars.
  • value
    Value of the attribute. Max length is 100 chars.

putMetric

putMetric(metricName: string, value: number): any;

Sets the value of the named metric with the provided number.

If a metric with the given name exists it will be overwritten. If a metric with the given name doesn't exist, a new one will be created.

Example

trace.putMetric('hits', 1);
Parameters
  • metricName
    Name of the metric to set. Must not have a leading or trailing whitespace, no leading underscore '_' character and have a max length of 32 characters.
  • value
    The value the metric should be set to.

removeMetric

removeMetric(metricName: string): any;

Removes a metric by name if it exists.

Example

trace.removeMetric('hits');
Parameters
  • metricName
    Name of the metric to remove.

start

start(): Promise<null>;

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

Example

const trace = firebase.perf().newTrace('example');
await trace.start();

stop

stop(): Promise<null>;

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

  • Example

const trace = firebase.perf().newTrace('example');
await trace.start();
trace.putMetric('hits', 1);
await trace.stop();