Christopher Blum

Christopher Blum on 16.04.2009 at 16:03h CET

As with most web 2.0 platforms, a large part of the platform interaction on XING is handled via JavaScript. In total, 25,000 lines of code render dynamic content on our platform. Dragging and dropping the boxes of your start page, editing settings in your profile, a live search selecting your contacts when you type a new message – AJAX is just about everywhere.

The challenge: debugging user-sided script
Although this has many advantages, it’s also quite a challenge. In web 1.0 times, quality assurance consisted of ensuring a consistent design of the mostly static HTML on the user’s browser and debugging the code meant going through the CGI scripts running on your server – with known hardware, software and preferences.

A platform relying heavily on JavaScript changes this. The scripts run on many different browsers in many different versions whose JavaScript implementation may vary a lot. My colleague Ingo Chao wrote about the problem of degradation without grace. Now, where a non-standard interpretation of CSS might merely lead to an broken design, a script waiting for an event not set in the browser could lead to a drastically reduced functionality of some features. Plus, engineers are (despite to all rumors:) humans and thus make mistakes.

Compiling an error report
So how do we log JavaScript errors? Besides the internal testing on several browsers in different versions, we actually record all error messages that occur on the user’s side.

To do this, we use the event handler window.onerror:

window.onerror = function(errorMessage, url, line) {
  var loggerUrl = "https://www.xing.com/js/logger";
  var parameters = "?description=" + escape(errorMessage)
      + "&url=" + escape(url)
      + "&line=" + escape(line)
      + "&parent_url=" + escape(document.location.href)
      + "&user_agent=" + escape(navigator.userAgent);
 
  /** Send error to server */
  new Image().src = loggerUrl + parameters;
};

So, whenever an error occurs, we record the user’s browser, the URL of both the script file and the HTML container, the code line and the error message in a log file. Private data such as the user id, the company, a possible premium membership or anything else that falls into that category is not transmitted. We record every error, from division by zero (unless you are Chuck Norris) to infinite loops. The only errors left out are those appearing in Internet Explorer 5.5 and earlier.

Based on the above mentioned URL and error message, the server then builds a hash as a unique id for this error. The catalogized errors are counted and sorted in descending order.

Error 1: illegal character

A cronjob initiates that an error report showing all messages and their frequency of occurence to the frontend engineering department so the team knows where it needs to focus. This way, we receive a list of errors that are often not even perceived by the end user, and we also know which errors are most pressing.


Trackback from http://sovit.biz/networkxing-the-corporate-blog-of-xing-%c2%bb-how-to-log-javascript/

[...] View original here:  net.work.xing – The corporate blog of XING » How to log JavaScript … [...]

net.work.xing - The corporate blog of XING » How to log JavaScript …Read more in

Recorded on 16.04.2009 at 21:45h CET

6
Comments
Leave a comment
Peter Claus Lamprecht on 16.04.2009 at 17:36h CET

Hi Christopher,
the concept of this logging function is very clever.
May I use it for my debugging projects?
By the way: the variable ‘url’ seems to be defined twice.
PC’L

Christopher Blum on 16.04.2009 at 17:40h CET

Hey Peter,

Feel free to use it in your own projects.
…and thanks for the note on the variable “url”.

Cheers,
Christopher

Matthias Reuter on 17.04.2009 at 08:21h CET

One question remains: how do you determine the line number? I can only think of hard coding, but that would be stupid, because it’s hard to maintain.

And shouldn’t you use encodeURIComponent instead of escape? (OK that was a second question, but since it’s a rhetorical one you could count that as a statement.)

Christopher Blum on 17.04.2009 at 18:34h CET

Hi Matthias,

the line numer is given by the browser. There’s no need to determine it manually.
Regarding your second question:
Thanks for the hint. We used “escape” in the beginning to track errors in old browsers that doesn’t support encodeURIComponent. This became obsolete after we decided to stop logging errors that were happening in old user agents.

Cheers,
Christopher

Bastian Fenske on 30.04.2009 at 15:26h CET

How do you protect your logger against abuse?

http://www.xing.com/js/logger?description=I%20hate%20this%20blog%20comment%21

Bastian

Christopher Blum on 03.05.2009 at 23:28h CET

Hi Bastian,

we have set a limit of errors logged each day and our daily report only contains errors that occured more than a given number.

Cheers,
Christopher

RSS-Feeds RSS feed for comments on this post.

Leave a comment

If you have a Word Press Account, please sign in