SlideShare a Scribd company logo
1 of 30
Download to read offline
POST-MORTEM DEBUGGING 
AND WEB DEVELOPMENT 
Alessandro Molina 
@__amol__ 
amol@turbogears.org
Who am I 
● CTO @ Axant.it, mostly Python company 
(with some iOS and Android) 
● TurboGears2 devteam member 
● Contributions to web world python libraries 
○ MING MongoDB ODM 
○ ToscaWidgets2 
○ Formencode
Why 
● Debugging is a core part of the 
development process. 
● You can try to prevent issues as much as 
possible, but users will find new ones. 
● Gathering informations to replicate issues 
is required to fix them
Debugging
At least know you have an issue. 
● Debugging is the “process of finding and 
reducing the number of bugs” 
● Users are already doing half of the work. 
● When users find a bug for you, make sure 
to be aware that they found it 
● Log it or it will be forgotten
Log what you really need 
● Log to replicate 
○ Then you are able to write tests that actually verify 
the issue has been solved. 
● You probably want to log: 
○ WSGI Environ 
○ Traceback 
○ Last N stack frames local variables 
○ Request Headers & Body (when size permits)
Log in an useful way 
● Log data in an easy to use way 
○ Log request in a way it’s quick to replay it 
○ Log in a computer friendly format for test units 
○ Request dump is good: netcat to replay it and is 
already understood by computers. 
● Organize your informations 
○ Use a tool to group and avoid duplicates 
○ Know what got solved and what didn’t 
○ Log by email, so you don’t have to check yourself
Log or...
But log in a separate thread or...
Crash Report 
● Many middlewares and frameworks 
provide exception reporting by email: 
○ pyramid_exclog (Pyramid) 
○ WebError (Pylons) 
○ BackLash (TurboGears) 
○ Django & Flask, framework provided 
● Logging module has what you need: 
Logger.exception + handlers.SMTPHandler
Ready-Made Email Reporting 
● Looking for a stand-alone solution? 
○ Backlash can be used by itself, not bound to 
TurboGears. 
○ Only dependency is “WebOb” 
● Supports both Python2 and Python3 
from backlash.trace_errors import EmailReporter 
email_reporter = EmailReporter(smtp_server="localhost", 
error_email="email@host.com", 
from_address="errors@host.com") 
app = backlash.TraceErrorsMiddleware(app, [email_reporter])
Try Sentry 
● Gathers data and detects duplicates 
● Provides “Reply Request” button 
● Mark exceptions as solved to keep track 
● Can log multiple events, not only 
exceptions 
from backlash.trace_errors.sentry import SentryReporter 
sentry_reporter = SentryReporter(sentry_dsn="http://public:secret@example.com/1") 
app = backlash.TraceErrorsMiddleware(app, [sentry_reporter])
Sentry
See what’s happening now 
● On development and test environments 
receiving errors by email is not convenient 
● In case of freezes you don’t get an 
exception that can be reported 
● Some problems need to be 
troubleshooted on the fly
Interactive Debugger 
● Python provides built-in Post Mortem 
debugging through pdb module 
try: 
return app(environ, start_response) 
except: 
import pdb 
pdb.post_mortem() 
● While it’s ready to use and works great it’s 
not the most comfortable tool when 
working on web development
Browser Debugger 
● Many frameworks have browser debugger 
○ Pyramid DebugBar 
○ Werkzeug DebuggedApplication 
○ TurboGears ErrorWare 
● BackLash provides a stand-alone version 
of the Werkzeug debugger. 
import backlash 
app = backlash.DebuggedApplication(app)
Werkzeug/BackLash Debugger
Browser Debugger Console 
● Browser debuggers usually implement a 
special URL with an interactive console 
that runs in the context of the application. 
● Use it to see what’s happening right now 
○ for threadId, stack in sys._current_frames().items() 
● Try /__console__ on Werkzeug or Backlash
Production Debugging 
● In-browser debugger must be disabled on 
production environments 
○ Unless you are PythonAnyware you want to block 
people from running code on your servers. 
● So we are back again at the starting point 
○ How do I debug issues that don’t provide an 
exception traceback on production?
Attaching to running processes 
To inspect running applications you can rely 
on tools like ispyd and pyrasite that are able 
to attach to a running python process 
from ispyd.plugins.wsgi import 
WSGIApplicationWrapper 
app = WSGIApplicationWrapper(app)
ispyd 
(wsgi:18630) requests 
No active transactions. 
(wsgi:18630) requests 
==== 67 ==== 
thread_id = 140735076232384 
start_time = Mon Apr 9 21:49:54 2012 
duration = 0.013629 seconds 
HTTP_HOST = 'localhost:5000' 
QUERY_STRING = '' 
… 
File: "wsgi.py", line 19, in hello 
time.sleep(0.05)
Pyrasite
Not only Debugging 
● Debugging tools can also help in finding 
and solving performance issues 
● When a request is taking a lot of time, just 
attach ipsyd and see what it’s happening 
● There are specific tools that can 
proactively notify you of slow requests
Slow Requests Tracing 
● Backlash provides slow request tracing for 
any WSGI framework. 
● Dogslow: a Django tool created by 
Bitbucket guys to monitor slow requests 
● Both Notify you by email, no need to check 
○ Backlash can also use any backlash reporter, for 
example by reporting slow requests on sentry.
Slow Requests Tracing 
● Setting up slow request reporting is 
incredibly simple both with Backlash and 
Dogslow 
import backlash 
from backlash.trace_errors import EmailReporter 
email_reporter = EmailReporter(smtp_server="localhost", 
error_email="email@host.com", 
from_address="errors@host.com") 
app = backlash.TraceSlowRequestsMiddleware(app, [email_reporter])
New Relic 
● Full stack tracing 
○ Controllers 
○ SQLAlchemy queries 
○ Background Tasks 
○ External Services 
○ Groups informations by controller, not URL 
● On-Demand profiling 
○ Turn On / Off controllers profiling from remote
New Relic
Slow requests stack trace might 
not be enough
Profiling 
● Full profiling has a big cost, so it is usually 
constrained to development environment 
● If you want to profile on production, 
perform sampling, don’t profile every 
request 
● Use a Low Overhead profiler like PLOP, not 
built-in profile module.
Questions?

More Related Content

What's hot

What's hot (16)

Ivan Dryzhyruk “Ducks Don’t Like Bugs”
Ivan Dryzhyruk “Ducks Don’t Like Bugs”Ivan Dryzhyruk “Ducks Don’t Like Bugs”
Ivan Dryzhyruk “Ducks Don’t Like Bugs”
 
Know where the fire is
Know where the fire isKnow where the fire is
Know where the fire is
 
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and MoreA Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
Mad&pwa practical no. 1
Mad&pwa practical no. 1Mad&pwa practical no. 1
Mad&pwa practical no. 1
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
 
Firmware Extraction & Fuzzing - Jatan Raval
Firmware Extraction & Fuzzing - Jatan RavalFirmware Extraction & Fuzzing - Jatan Raval
Firmware Extraction & Fuzzing - Jatan Raval
 
TDD with Python and App Engine
TDD with Python and App EngineTDD with Python and App Engine
TDD with Python and App Engine
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance Workshop
 
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
 
What can possibly go wrong if i dont e2 e test my packages?
What can possibly go wrong if i dont e2 e test my packages?What can possibly go wrong if i dont e2 e test my packages?
What can possibly go wrong if i dont e2 e test my packages?
 
Meetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React TestingMeetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React Testing
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
 
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida  Android run time hooking - Bhargav Gajera & Vitthal ShindeFrida  Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
 
Typescript - a JS superset
Typescript - a JS supersetTypescript - a JS superset
Typescript - a JS superset
 
Successful Joomla migrations that don't hurt Search Engine Rankings
Successful Joomla migrations that don't hurt Search Engine RankingsSuccessful Joomla migrations that don't hurt Search Engine Rankings
Successful Joomla migrations that don't hurt Search Engine Rankings
 

Viewers also liked

Achieving Maximum Results from Your Hostel
Achieving Maximum Results from Your HostelAchieving Maximum Results from Your Hostel
Achieving Maximum Results from Your Hostel
GoMio.com
 
planeamiento estratégico, paradigmas, cambio, entorno
planeamiento estratégico, paradigmas, cambio, entornoplaneamiento estratégico, paradigmas, cambio, entorno
planeamiento estratégico, paradigmas, cambio, entorno
UNIVERSIDAD NACIONAL DE PIURA
 

Viewers also liked (9)

Linked in
Linked inLinked in
Linked in
 
Achieving Maximum Results from Your Hostel
Achieving Maximum Results from Your HostelAchieving Maximum Results from Your Hostel
Achieving Maximum Results from Your Hostel
 
TraDesto Financial Social Network
TraDesto Financial Social NetworkTraDesto Financial Social Network
TraDesto Financial Social Network
 
Principles Of Achieving Wealth
Principles Of Achieving WealthPrinciples Of Achieving Wealth
Principles Of Achieving Wealth
 
PyConUK2013 - Validated documents on MongoDB with Ming
PyConUK2013 - Validated documents on MongoDB with MingPyConUK2013 - Validated documents on MongoDB with Ming
PyConUK2013 - Validated documents on MongoDB with Ming
 
Tell Your Story Capabilities & Cases 2014
Tell Your Story Capabilities & Cases 2014Tell Your Story Capabilities & Cases 2014
Tell Your Story Capabilities & Cases 2014
 
planeamiento estratégico, paradigmas, cambio, entorno
planeamiento estratégico, paradigmas, cambio, entornoplaneamiento estratégico, paradigmas, cambio, entorno
planeamiento estratégico, paradigmas, cambio, entorno
 
Tell Your Story: Select Social PR Case Studies 2015
Tell Your Story: Select Social PR Case Studies 2015Tell Your Story: Select Social PR Case Studies 2015
Tell Your Story: Select Social PR Case Studies 2015
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 

Similar to PyConUK 2014 - PostMortem Debugging and Web Development Updated

Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
egypt
 
Android Frameworks: Highlighting the Need for a Solid Development Framework 
Android Frameworks: Highlighting the Need for a Solid Development Framework Android Frameworks: Highlighting the Need for a Solid Development Framework 
Android Frameworks: Highlighting the Need for a Solid Development Framework 
Mutual Mobile
 
Aws uk ug #8 not everything that happens in vegas stay in vegas
Aws uk ug #8   not everything that happens in vegas stay in vegasAws uk ug #8   not everything that happens in vegas stay in vegas
Aws uk ug #8 not everything that happens in vegas stay in vegas
Peter Mounce
 

Similar to PyConUK 2014 - PostMortem Debugging and Web Development Updated (20)

PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
 
Pentester++
Pentester++Pentester++
Pentester++
 
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
 
Fuzzing - Part 2
Fuzzing - Part 2Fuzzing - Part 2
Fuzzing - Part 2
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Pen Testing Development
Pen Testing DevelopmentPen Testing Development
Pen Testing Development
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
Django best practices for logging and signals
Django best practices for logging and signals Django best practices for logging and signals
Django best practices for logging and signals
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Frameworks: Highlighting the Need for a Solid Development Framework 
Android Frameworks: Highlighting the Need for a Solid Development Framework Android Frameworks: Highlighting the Need for a Solid Development Framework 
Android Frameworks: Highlighting the Need for a Solid Development Framework 
 
Cost-Effective Two-Factor Authentication
Cost-Effective Two-Factor AuthenticationCost-Effective Two-Factor Authentication
Cost-Effective Two-Factor Authentication
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Aws uk ug #8 not everything that happens in vegas stay in vegas
Aws uk ug #8   not everything that happens in vegas stay in vegasAws uk ug #8   not everything that happens in vegas stay in vegas
Aws uk ug #8 not everything that happens in vegas stay in vegas
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Infrastructure talk
Infrastructure talkInfrastructure talk
Infrastructure talk
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"
 
Services, tools & practices for a software house
Services, tools & practices for a software houseServices, tools & practices for a software house
Services, tools & practices for a software house
 
Making Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF UsableMaking Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF Usable
 

More from Alessandro Molina

PyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profitPyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profit
Alessandro Molina
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
Alessandro Molina
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2
Alessandro Molina
 

More from Alessandro Molina (12)

PyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdfPyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdf
 
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
 
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
EP2016 - Moving Away From Nodejs To A Pure Python Solution For AssetsEP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
 
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
EuroPython 2015 - Storing files for the web is not as straightforward as you ...EuroPython 2015 - Storing files for the web is not as straightforward as you ...
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
 
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESPyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
 
PyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profitPyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profit
 
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
PyConFR 2014 - DEPOT, Story of a file.write() gone wrongPyConFR 2014 - DEPOT, Story of a file.write() gone wrong
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
 
MongoTorino 2013 - BSON Mad Science for fun and profit
MongoTorino 2013 - BSON Mad Science for fun and profitMongoTorino 2013 - BSON Mad Science for fun and profit
MongoTorino 2013 - BSON Mad Science for fun and profit
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2
 

Recently uploaded

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 

PyConUK 2014 - PostMortem Debugging and Web Development Updated

  • 1. POST-MORTEM DEBUGGING AND WEB DEVELOPMENT Alessandro Molina @__amol__ amol@turbogears.org
  • 2. Who am I ● CTO @ Axant.it, mostly Python company (with some iOS and Android) ● TurboGears2 devteam member ● Contributions to web world python libraries ○ MING MongoDB ODM ○ ToscaWidgets2 ○ Formencode
  • 3. Why ● Debugging is a core part of the development process. ● You can try to prevent issues as much as possible, but users will find new ones. ● Gathering informations to replicate issues is required to fix them
  • 5. At least know you have an issue. ● Debugging is the “process of finding and reducing the number of bugs” ● Users are already doing half of the work. ● When users find a bug for you, make sure to be aware that they found it ● Log it or it will be forgotten
  • 6. Log what you really need ● Log to replicate ○ Then you are able to write tests that actually verify the issue has been solved. ● You probably want to log: ○ WSGI Environ ○ Traceback ○ Last N stack frames local variables ○ Request Headers & Body (when size permits)
  • 7. Log in an useful way ● Log data in an easy to use way ○ Log request in a way it’s quick to replay it ○ Log in a computer friendly format for test units ○ Request dump is good: netcat to replay it and is already understood by computers. ● Organize your informations ○ Use a tool to group and avoid duplicates ○ Know what got solved and what didn’t ○ Log by email, so you don’t have to check yourself
  • 9. But log in a separate thread or...
  • 10. Crash Report ● Many middlewares and frameworks provide exception reporting by email: ○ pyramid_exclog (Pyramid) ○ WebError (Pylons) ○ BackLash (TurboGears) ○ Django & Flask, framework provided ● Logging module has what you need: Logger.exception + handlers.SMTPHandler
  • 11. Ready-Made Email Reporting ● Looking for a stand-alone solution? ○ Backlash can be used by itself, not bound to TurboGears. ○ Only dependency is “WebOb” ● Supports both Python2 and Python3 from backlash.trace_errors import EmailReporter email_reporter = EmailReporter(smtp_server="localhost", error_email="email@host.com", from_address="errors@host.com") app = backlash.TraceErrorsMiddleware(app, [email_reporter])
  • 12. Try Sentry ● Gathers data and detects duplicates ● Provides “Reply Request” button ● Mark exceptions as solved to keep track ● Can log multiple events, not only exceptions from backlash.trace_errors.sentry import SentryReporter sentry_reporter = SentryReporter(sentry_dsn="http://public:secret@example.com/1") app = backlash.TraceErrorsMiddleware(app, [sentry_reporter])
  • 14. See what’s happening now ● On development and test environments receiving errors by email is not convenient ● In case of freezes you don’t get an exception that can be reported ● Some problems need to be troubleshooted on the fly
  • 15. Interactive Debugger ● Python provides built-in Post Mortem debugging through pdb module try: return app(environ, start_response) except: import pdb pdb.post_mortem() ● While it’s ready to use and works great it’s not the most comfortable tool when working on web development
  • 16. Browser Debugger ● Many frameworks have browser debugger ○ Pyramid DebugBar ○ Werkzeug DebuggedApplication ○ TurboGears ErrorWare ● BackLash provides a stand-alone version of the Werkzeug debugger. import backlash app = backlash.DebuggedApplication(app)
  • 18. Browser Debugger Console ● Browser debuggers usually implement a special URL with an interactive console that runs in the context of the application. ● Use it to see what’s happening right now ○ for threadId, stack in sys._current_frames().items() ● Try /__console__ on Werkzeug or Backlash
  • 19. Production Debugging ● In-browser debugger must be disabled on production environments ○ Unless you are PythonAnyware you want to block people from running code on your servers. ● So we are back again at the starting point ○ How do I debug issues that don’t provide an exception traceback on production?
  • 20. Attaching to running processes To inspect running applications you can rely on tools like ispyd and pyrasite that are able to attach to a running python process from ispyd.plugins.wsgi import WSGIApplicationWrapper app = WSGIApplicationWrapper(app)
  • 21. ispyd (wsgi:18630) requests No active transactions. (wsgi:18630) requests ==== 67 ==== thread_id = 140735076232384 start_time = Mon Apr 9 21:49:54 2012 duration = 0.013629 seconds HTTP_HOST = 'localhost:5000' QUERY_STRING = '' … File: "wsgi.py", line 19, in hello time.sleep(0.05)
  • 23. Not only Debugging ● Debugging tools can also help in finding and solving performance issues ● When a request is taking a lot of time, just attach ipsyd and see what it’s happening ● There are specific tools that can proactively notify you of slow requests
  • 24. Slow Requests Tracing ● Backlash provides slow request tracing for any WSGI framework. ● Dogslow: a Django tool created by Bitbucket guys to monitor slow requests ● Both Notify you by email, no need to check ○ Backlash can also use any backlash reporter, for example by reporting slow requests on sentry.
  • 25. Slow Requests Tracing ● Setting up slow request reporting is incredibly simple both with Backlash and Dogslow import backlash from backlash.trace_errors import EmailReporter email_reporter = EmailReporter(smtp_server="localhost", error_email="email@host.com", from_address="errors@host.com") app = backlash.TraceSlowRequestsMiddleware(app, [email_reporter])
  • 26. New Relic ● Full stack tracing ○ Controllers ○ SQLAlchemy queries ○ Background Tasks ○ External Services ○ Groups informations by controller, not URL ● On-Demand profiling ○ Turn On / Off controllers profiling from remote
  • 28. Slow requests stack trace might not be enough
  • 29. Profiling ● Full profiling has a big cost, so it is usually constrained to development environment ● If you want to profile on production, perform sampling, don’t profile every request ● Use a Low Overhead profiler like PLOP, not built-in profile module.