Skip to content

Easier way to log custom timed metrics #11

@mdvorscak

Description

@mdvorscak

In the first paint example

/**
 * Returns the browser's first paint metric (if available).
 * @return {number} The first paint time in ms.
 */
function getFirstPaintIfSupported() {/* ... */}

// Take measurement after page load.
window.addEventListener('load', function() {
  const fp = getFirstPaintIfSupported();
  if (fp) {
    const metric = new Metric('firstpaint');
    //If I call log here
    metric.log(); // I get firstpaint -1 ms
    // No need to call start()/end(). Can send a value, directly.
    metric.sendToAnalytics('load', metric.name, fp);
  }
});

Of course I can manually generate the log, but it could be nice if the log could take an overridable duration parameter (like sendToAnalytics):

  log(duration = this.duration) {
    console.info(this.name, this.duration, 'ms');
    return this;
  }

Or maybe a way to set the duration itself for these types of events?

set duration(duration){
  this.customDuration = duration;
  return this;
}

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions