Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier way to log custom timed metrics #11

Open
mdvorscak opened this issue Jan 8, 2018 · 3 comments
Open

Easier way to log custom timed metrics #11

mdvorscak opened this issue Jan 8, 2018 · 3 comments

Comments

@mdvorscak
Copy link

mdvorscak commented Jan 8, 2018

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?

@ebidel
Copy link
Owner

ebidel commented Jan 8, 2018

Not sure I follow completely. .log() is just meant as a convenient helper for writing the console.log statement yourself. It should really throw if start and end were never called. If you want to log a custom metric, maybe just console.log what you want :) ?

@mdvorscak
Copy link
Author

Yeah, of course I can write the log statement myself. I just thought it would be nicer if I could use metric.log to remain consistent. Rather than switching between metric.log and console.log, if I want to keep my log messages the same it means that I must know the internals of how metric is doing it's logging (and format my console.log the same).

Maybe metric.log really should throw an error if there is no duration associated to it?

@ebidel
Copy link
Owner

ebidel commented Jan 9, 2018

Maybe metric.log really should throw an error if there is no duration associated to it?

Yea exactly :) That ways it's not ambiguous and you don't need to understand the internal details. I'm happy to take a PR for that btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants