React Native Firebase
    Preparing search index...

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

    Index

    Constructors

    Methods

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

      const attribute = trace.getAttribute('userId');
      

      Parameters

      • attribute: string

        Name of the attribute to fetch the value of.

      Returns string | null

    • 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.

      const metric = trace.getMetric('hits');
      

      Parameters

      • metricName: string

        Name of the metric to get.

      Returns number

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

      const metrics = trace.getMetrics();

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

      Returns { [key: string]: number }

    • 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: string

        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: number

        The value the metric should be incremented by.

      Returns void

    • 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.

      trace.putAttribute('userId', '123456789');
      

      Parameters

      • attribute: string

        Name of the attribute. Max length is 40 chars.

      • value: string

        Value of the attribute. Max length is 100 chars.

      Returns void

    • 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.

      trace.putMetric('hits', 1);
      

      Parameters

      • metricName: string

        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: number

        The value the metric should be set to.

      Returns void

    • Removes a metric by name if it exists.

      trace.removeMetric('hits');
      

      Parameters

      • metricName: string

        Name of the metric to remove.

      Returns void

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

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

      Returns Promise<null>

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

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

      Returns Promise<null>