SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
KNOW YOUR ERRORS
BECAUSE IT'S A JUNGLE OUT THERE
WHO AM I?
Diogo Antunes
Booking.com
Senior Client Side Developer
@dicode
OVERVIEW
logging JS errors
proof of concept
tools/services
SO WHY LOG JS ERRORS IF?
YOU DO TDD
YOU DO SELENIUM TESTS
YOU DO HEADLESS BROWSER TESTING
YOU HAVE A TESTING TEAM
IT WORKS ON MY MACHINE
IT'S A JUNGLE OUT THERE!
3RD PARTY SCRIPTS THAT YOU DON'T CONTROL
Twitter, Facebook, GA
YOU USE A CDN
even if it is just to load jquery
USERS INSTALL PLUGINS
YOUR MARKETING DEPARTMENT LIKES TRACKING PIXELS
YES, SOME THINGS YOU CANNOT CONTROL
but some of them you can mitigate
SOME CHALLENGES
LOCALIZED MESSAGES
Expected identifier, string or number
Identificador esperado
Se esperaba un identificador, una cadena o un número
Bezeichner erwartet
标识
‫ّف‬ ‫د‬ ‫و‬ ‫ا‬
LINE NUMBER
minify js
using gzip and preserving new lines may be a temporary solution
CRYPTIC MESSAGES
cannot find method of undefined
Script error.
cross origin domain policy
Chrome and Firefox
Access-Control-Allow-Origin: *
BE SAFE
deploy environment vars that disable 3rd party code
if possible, without making any deploy to live
that way you can take action quickly
LET'S DO SOME LOGGING
APPROACHES
WINDOW.ONERROR
works across the board
amount of information is limited
window.onerror = function(msg, url, lno){
/*
No impact besides parsing
overhead is only for the request to log the error
when one actually happens
*/
return true; //hides the message in supported browsers
};
TRY/CATCH
works across the board
try {
throw new Error("my error");
} catch (e){
e.stack; //chrome, firefox
e.message; //opera
log(e.stack || e.message || e);
}
TRY/CATCH
more meaningful errors
performance hit, but you should evaluate if it matters
may lead to a lot of nesting if not thought through
var fn = function(){
throw "new error"; //this exception will not be caught
//since it's a string it will not have stack trace
};
try{
setTimeout(fn,0);
} catch(e) { }
TYPES OF EXCEPTIONS
Error
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
LOGGING
GET VS POST
both methods work fine
get has the size of url limitation
you can truncate some data (case by case evaluation)
IMAGE (GET)
//assuming src was already calculated
var img = new Image(1,1);
img.onload = function() {};
img.src = "/log?msg=error&url=http%3A%2F%2Flocalhost&lno=1";
IFRAME (POST)
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var iframeDoc = iframe.contentDocument,
content = '<form method="post" action="/log">
<input type="text" name="msg" value="Script Error">
<input type="text" name="url" value="http%3A%2F%2Flocalhost">
<input type="text" name="lno" value="1">
</form>';
iframeDoc.open();
iframeDoc.write(content);
iframeDoc.close();
iframeDoc.body.firstChild.submit();
XHR (BOTH)
var xhr = new XMLHttpRequest();
//post
xhr.open("POST",'/log');
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send( payload );
//get
xhr.open("GET",'/log?' + qs);
xhr.send();
IF YOU WANT JUST A COUNTER
Google Analytics is also an option
_gaq.push([
'_trackEvent',
'jserror',
url + ':' + lno,
message || ''
]);
STACKTRACE.JS
<script src="path/to/stacktrace.js"></script>
<script>
</script>
//... your code ...
if (errorCondition) {
var trace = printStackTrace();
//Output however you want!
alert(trace.join('nn'));
}
//... more code of yours ...
STACKTRACE.JS
Firefox (and Iceweasel) 0.9+
Google Chrome 1+
Safari 3.0+ (including iOS 1+)
Opera 7+
IE 5.5+
Konqueror 3.5+
Flock 1.0+
SeaMonkey 1.0+
K-Meleon 1.5.3+
Epiphany 2.28.0+
Iceape 1.1+
YOUR DASHBOARD
NODEJS + REDIS
express
node_redis
npm install -g express
express dashboard_js
npm install redis
EXPRESS
//assuming a sample express app
var log = require('./routes/log');
app.get('/log', log.index);
app.post('/log', log.index);
app.get('/log_list', log.list);
app.get('/log_chart', log.chart);
THE ROUTERS
exports.index = function (req, res) {
var msg = req.param('msg', ''),
url = req.param('url', ''),
lno = req.param('lno', 0),
js_error = msg + ':!:' + url + ':!:' + lno;
minute = ((+new Date()/60000|0)*60000),
data = [ 'jserrors', '' + minute, 1 ];
if(!msg) {
res.send('', 400);
}
redis_cli.hincrby( data, function(){} );
redis_cli.lpush( 'jserror_' + minute, js_error);
res.send('', 202);
};
exports.list = function(req, res) {
var to = (+new Date()/60000|0)*60000,
from = to - 20 * 60000;
inc = 60000,
prefix = 'jserror_',
result = {},
cb = function(res, i){.
return function(err, reply){
var ret = [];
reply.forEach(function(val, ind){
ret[ind] = val.split(':!:');
});
result[i] = ret;
if(i === to) {
res.json(result);
}
};
};
for(var i = from; i<=to; i+=inc) {
redis_cli.lrange( [prefix+i,0,100], cb(res, i) );
}
};
exports.chart = function(req, res) {
var to = (+new Date()/60000|0)*60000, inc = 60000,
from = to - 20 * 60000,
redis_param = ['jserrors'],
ret = [];
for(var i = from; i<=to; i+=inc) {
redis_param.push(''+i);
ret.push({d: new Date(i)});
}
redis_cli.hmget( redis_param, function(err, reply){
reply.forEach(function(val, ind){
ret[ind].v = val || 0;
});
res.json(ret);
});
};
MISCELLANEOUS
jquery 2.0
twitter bootstrap
morris
IN ACTION
SERVICES OUT THERE
Smart error grouping
Team collaboration
Easiness of integration
Users statistics
QBAKA
Smart grouping of errors
We don't rewrite your code
Automatic ignoring of errors
Filter errors to your liking
{ERRORCEPTION}
you can point it to your own service
or use appspot
more a service than a SAAS
JSERRLOG
Low overhead
Email digest
Shows the JavaScript code that caused the error
Automatic cleanup
MUSCULA
SINCE WE ALREADY LOGGING
Navigation Timing API
not available - Opera, Safari
PROPERTIES
navigationStart
unloadEventStart
unloadEventEnd
redirectStart
redirectEnd
fetchStart
domainLookupStart
domainLookupEnd
connectStart
connectEnd
PROPERTIES
secureConnectionStart
requestStart
responseStart
responseEnd
domLoading
domInteractive
domContentLoadedEventStart
domContentLoadedEventEnd
domComplete
loadEventStart
loadEventEnd
VISUAL INDICATION
FRONTEND SPOF
any 3rd party widget
custom font downloading
even your own JS can cause it...
LOG EVERYTHING YOU CAN
EVERYWHERE
don't expect your users to report your errors
be aware, be prepared
THANKS!
Diogo Antunes
Booking.com jobs
Q&A
Know your errors

Weitere ähnliche Inhalte

Was ist angesagt?

Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
danwrong
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
crgwbr
 
Unit testing with Easymock
Unit testing with EasymockUnit testing with Easymock
Unit testing with Easymock
Ürgo Ringo
 
Exceptions irst
Exceptions irstExceptions irst
Exceptions irst
jkumaranc
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
PyCon Italia
 

Was ist angesagt? (18)

2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
My java file
My java fileMy java file
My java file
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
 
Practical Ext JS Debugging
Practical Ext JS DebuggingPractical Ext JS Debugging
Practical Ext JS Debugging
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
 
Practical JavaScript Programming - Session 4/8
Practical JavaScript Programming - Session 4/8Practical JavaScript Programming - Session 4/8
Practical JavaScript Programming - Session 4/8
 
Practical
PracticalPractical
Practical
 
Unit testing with Easymock
Unit testing with EasymockUnit testing with Easymock
Unit testing with Easymock
 
Exceptions irst
Exceptions irstExceptions irst
Exceptions irst
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the type
 
Mad Max is back, plus the rest of our new reviews and notable screenings
Mad Max is back, plus the rest of our new reviews and notable screeningsMad Max is back, plus the rest of our new reviews and notable screenings
Mad Max is back, plus the rest of our new reviews and notable screenings
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
 

Ähnlich wie Know your errors

Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
tonvanbart
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
philogb
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
philogb
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
PL dream
 
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsCompatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensions
Kai Cui
 

Ähnlich wie Know your errors (20)

To Err Is Human
To Err Is HumanTo Err Is Human
To Err Is Human
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Surviving javascript.pptx
Surviving javascript.pptxSurviving javascript.pptx
Surviving javascript.pptx
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
Testing in JavaScript - August 2018 - WebElement Bardejov
Testing in JavaScript - August 2018 - WebElement BardejovTesting in JavaScript - August 2018 - WebElement Bardejov
Testing in JavaScript - August 2018 - WebElement Bardejov
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsCompatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensions
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 

Mehr von Diogo Antunes (6)

It works on your computer... but does it render fast enough?
It works on your computer... but does it render fast enough?It works on your computer... but does it render fast enough?
It works on your computer... but does it render fast enough?
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
 
Nodejs
NodejsNodejs
Nodejs
 
Making burgers with JavaScript
Making burgers with JavaScriptMaking burgers with JavaScript
Making burgers with JavaScript
 
Debugging your JavaScript
Debugging your JavaScriptDebugging your JavaScript
Debugging your JavaScript
 
Working With Canvas
Working With CanvasWorking With Canvas
Working With Canvas
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Know your errors