Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Breaking: improve JS Error reports #2334

Merged
merged 11 commits into from
Sep 15, 2016
Merged

Conversation

zazabe
Copy link
Contributor

@zazabe zazabe commented Sep 13, 2016

  • more data are reported for JS error:
{
  uid: string,             // unique ID, useful to get previous errors since the page load
  counter: int,            // error counter, since the page load
  previousLog: string,     // previous cm.logger logs (includes cm.debug.log / cm.error.log)
  url: string,             // page url
  error: {
    message: string,          // error message
    type: string,             // error class name
    stack: string,            // error stacktrace
    metaInfo: object|null,    // metainfo (for CM_Exception*)
    source: {                 // error source file / line / column
      url: string,
      line: int,
      col: int
    }
  }
}
  • the same data structure is used on the client and on the server side
  • JS Error are logged on the server side with the prefix JS Error - + error.message
  • js-logger is used as a logger facility
  • all logs are always recorded on the client side, with a 5min retention, but console.* is only used when cm.logger.configure({dev: true})

@zazabe zazabe self-assigned this Sep 13, 2016
@zazabe
Copy link
Contributor Author

zazabe commented Sep 13, 2016

@vogdb please review

cc @tomaszdurka

@vogdb
Copy link
Contributor

vogdb commented Sep 13, 2016

Looks very good. Few notes:

  • do we need 'status' => 'ok' in $this->_setContent(json_encode(['status' => 'ok'])); ?

  • it might overwrite options

    this._options = _.defaults(options || {}, {
  • This name setHandler kind of misleads me cause it sets messages in handlers rather than handler. I think I didn't understand clearly its purpose.

      Logger.setHandler(function(messages, context) {
  • Is it ok that we don't pass error.stacktrace in Logger.addRecordError ?

@zazabe
Copy link
Contributor Author

zazabe commented Sep 13, 2016

do we need 'status' => 'ok'

Not really, just thought it's strange to not replying something :)

it might overwrite options

I don't think so, it's the opposite of _.extend(), see http://underscorejs.org/#defaults

This name setHandler kind of misleads

The usage is described here: https://github.com/jonnyreeves/js-logger#default-log-handler-function.

If it's about if (!isDev || (options.dev && isDev))..., i don't think there's another solution with js-logger, because the handler is something defined globally, we can't have multiple Logger instances with specific handlers...
I thought also that the log level could be checked by each handler, but actually, it's the Logger itself that do the check...

Finally, this js-logger is quite limited ;(

Is it ok that we don't pass error.stacktrace in Logger.addRecordError

agree, the stacktrace might be useful, see 1289137

@njam
Copy link
Member

njam commented Sep 13, 2016

Maybe another library to improve stacktraces should be used? Oftentimes the default stacktrace is not very useful, but there are some techniques to improve them.
E.g. https://www.stacktracejs.com/

$context->setException($exception);
$this->getServiceManager()->getLogger()->warning('Javascript error', $context);
$context->setExtra($query);
$this->getServiceManager()->getLogger()->warning('JS Error - ' . $query['error']['message'], $context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite an important change. We will have a separate log message for every JS error that is recorded. I think it's good, just to keep it in mind.
cc @tomaszdurka

@zazabe
Copy link
Contributor Author

zazabe commented Sep 13, 2016

https://www.stacktracejs.com/

Would be awesome with stacktracejs/stacktrace-gps#4, because in prod, users will not have the sourcemaps.
Maybe it could be done on the server side, with cm-bundler ;) ?

@vogdb
Copy link
Contributor

vogdb commented Sep 13, 2016

I don't think so, it's the opposite of _.extend(), see http://underscorejs.org/#defaults

You are right. It might just fill undefined of the original options

lgtm!

@zazabe
Copy link
Contributor Author

zazabe commented Sep 15, 2016

about the stacktrace improvement: #2336

@zazabe zazabe merged commit 71853ba into cargomedia:master Sep 15, 2016
@zazabe zazabe removed the selfmade label Sep 15, 2016
@zazabe zazabe changed the title Improve JS Error reports Breaking: improve JS Error reports Sep 15, 2016
@vogdb
Copy link
Contributor

vogdb commented Sep 15, 2016

(deleted)

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

Successfully merging this pull request may close these issues.

3 participants