Disable/fix console time logs and errors on prod
Problem
Sentry has been logging many errors due to console.time
call label collisions or mismatches: https://push-notifications-sentry.web.cern.ch/sentry/backend/issues/1067/?referrer=alert_email
This is could be due to some service implementations (like get all channels), which have console.time
calls for performance monitoring, and if two instances are fired concurrently, then two labels overlap, or one might try to close a time logging that was already closed (supposition).
Example:
Instances of find-all-channels
A: starts
B: starts
A: console.time('get-all-channels:total:' + this.authorizationBag.userName)
running console time process with label get-all-channels:total:username
B: console.time('get-all-channels:total:' + this.authorizationBag.userName)
tries to run new console time process with label get-all-channels:total:username
which already exists
ERROR
Similar for console.timeEnd
.\
Proposed solution 1:
Wrap console.time
and console.timeEnd
in a function which is called instead. This function shall check process.env
and skip the timing if in prod.
Proposed solution 2:
With the help of a randomly generated number/alphanumeric (could be v4 from 'uuid' or a subset of it), create a tag for the running instance, and incorporate it in the label, effectively each label close to unique for whichever call.
const timeLabel: string = 'get-all-channels:' + v4().substring(0, 4) + this.authorizationBag.userName;
Then change calls to be of the format
console.time(timeLabel + <action>);