SlideShare a Scribd company logo
1 of 29
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 dev team 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 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
Dogslow
● Dogslow is a Django tool created by
Bitbucket guys to monitor slow requests
● Notifies you by email, no need to check
● Really small codebase, it’s easy to port it to
other environments
○ Upcoming BackLash version will provide a port of
dogslow for frameworks apart Django
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

Viewers also liked

How better sales rep onboarding can boost your topline
How better sales rep onboarding can boost your toplineHow better sales rep onboarding can boost your topline
How better sales rep onboarding can boost your toplineMindTickle
 
Why sales readiness? And Why Now?
Why sales readiness? And Why Now?Why sales readiness? And Why Now?
Why sales readiness? And Why Now?MindTickle
 
Sirius sales readiness 22 tips
Sirius sales readiness 22 tipsSirius sales readiness 22 tips
Sirius sales readiness 22 tipsRob Wright
 
Putting the Ready in Business Readiness
Putting the Ready in Business ReadinessPutting the Ready in Business Readiness
Putting the Ready in Business ReadinessDarren Nerland
 
Business Readiness Assessment & Ocm Platform
Business Readiness Assessment & Ocm PlatformBusiness Readiness Assessment & Ocm Platform
Business Readiness Assessment & Ocm PlatformEduardo Muniz
 
Business Readiness Planning Checklist
Business Readiness Planning ChecklistBusiness Readiness Planning Checklist
Business Readiness Planning ChecklistDarren Nerland
 
Tips for aligning business process and systems to support accurate quota and ...
Tips for aligning business process and systems to support accurate quota and ...Tips for aligning business process and systems to support accurate quota and ...
Tips for aligning business process and systems to support accurate quota and ...Anaplan
 
Sales budget, quotas and sales territories
Sales budget, quotas and sales territoriesSales budget, quotas and sales territories
Sales budget, quotas and sales territoriesIndransh Gupta
 
The Planning Cycle
The Planning CycleThe Planning Cycle
The Planning CycleBusiness901
 
Sales territory and management of sales quota
Sales territory and management of sales quotaSales territory and management of sales quota
Sales territory and management of sales quotasanjay_sarkar
 
Sales readiness - future of predictive sales
Sales readiness - future of predictive salesSales readiness - future of predictive sales
Sales readiness - future of predictive salesMindTickle
 

Viewers also liked (13)

How better sales rep onboarding can boost your topline
How better sales rep onboarding can boost your toplineHow better sales rep onboarding can boost your topline
How better sales rep onboarding can boost your topline
 
Why sales readiness? And Why Now?
Why sales readiness? And Why Now?Why sales readiness? And Why Now?
Why sales readiness? And Why Now?
 
Sirius sales readiness 22 tips
Sirius sales readiness 22 tipsSirius sales readiness 22 tips
Sirius sales readiness 22 tips
 
Putting the Ready in Business Readiness
Putting the Ready in Business ReadinessPutting the Ready in Business Readiness
Putting the Ready in Business Readiness
 
Business Readiness Assessment & Ocm Platform
Business Readiness Assessment & Ocm PlatformBusiness Readiness Assessment & Ocm Platform
Business Readiness Assessment & Ocm Platform
 
Business Readiness Planning Checklist
Business Readiness Planning ChecklistBusiness Readiness Planning Checklist
Business Readiness Planning Checklist
 
Tips for aligning business process and systems to support accurate quota and ...
Tips for aligning business process and systems to support accurate quota and ...Tips for aligning business process and systems to support accurate quota and ...
Tips for aligning business process and systems to support accurate quota and ...
 
Sales budget, quotas and sales territories
Sales budget, quotas and sales territoriesSales budget, quotas and sales territories
Sales budget, quotas and sales territories
 
Sales quota
Sales quotaSales quota
Sales quota
 
The Planning Cycle
The Planning CycleThe Planning Cycle
The Planning Cycle
 
Sales territory and management of sales quota
Sales territory and management of sales quotaSales territory and management of sales quota
Sales territory and management of sales quota
 
Brainstorming
Brainstorming Brainstorming
Brainstorming
 
Sales readiness - future of predictive sales
Sales readiness - future of predictive salesSales readiness - future of predictive sales
Sales readiness - future of predictive sales
 

Similar to Post-Mortem Debugging and Web Development

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...Alessandro Molina
 
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 ApplicationsGraham Dumpleton
 
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
 
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 TurboGearsAlessandro Molina
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
Масштабируемый и эффективный фаззинг Google Chrome
Масштабируемый и эффективный фаззинг Google ChromeМасштабируемый и эффективный фаззинг Google Chrome
Масштабируемый и эффективный фаззинг Google ChromePositive Hack Days
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGPablo Garbossa
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database AuditingJuan Berner
 
Pentester++
Pentester++Pentester++
Pentester++CTruncer
 
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 flywindy
 
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"Demi Ben-Ari
 
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ..."Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...PROIDEA
 
Pen Testing Development
Pen Testing DevelopmentPen Testing Development
Pen Testing DevelopmentCTruncer
 
Velocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing SystemsVelocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing SystemsSOASTA
 
Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)SOASTA
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyBrian Lyttle
 
Graylog for open stack 3 steps to know why
Graylog for open stack    3 steps to know whyGraylog for open stack    3 steps to know why
Graylog for open stack 3 steps to know whyMạnh Đinh
 
Cost-Effective Two-Factor Authentication
Cost-Effective Two-Factor AuthenticationCost-Effective Two-Factor Authentication
Cost-Effective Two-Factor AuthenticationWaihon Yew
 

Similar to Post-Mortem Debugging and Web Development (20)

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
 
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...
 
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
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Масштабируемый и эффективный фаззинг Google Chrome
Масштабируемый и эффективный фаззинг Google ChromeМасштабируемый и эффективный фаззинг Google Chrome
Масштабируемый и эффективный фаззинг Google Chrome
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
 
Pentester++
Pentester++Pentester++
Pentester++
 
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
 
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"
 
Graylog for open stack 3 steps to know why
Graylog for open stack    3 steps to know whyGraylog for open stack    3 steps to know why
Graylog for open stack 3 steps to know why
 
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ..."Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
 
Pen Testing Development
Pen Testing DevelopmentPen Testing Development
Pen Testing Development
 
Velocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing SystemsVelocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing Systems
 
Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
Graylog for open stack 3 steps to know why
Graylog for open stack    3 steps to know whyGraylog for open stack    3 steps to know why
Graylog for open stack 3 steps to know why
 
Cost-Effective Two-Factor Authentication
Cost-Effective Two-Factor AuthenticationCost-Effective Two-Factor Authentication
Cost-Effective Two-Factor Authentication
 

More from Alessandro Molina

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.pdfAlessandro Molina
 
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...Alessandro Molina
 
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 AssetsAlessandro Molina
 
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 ...Alessandro Molina
 
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESPyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESAlessandro 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 profitAlessandro Molina
 
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 wrongAlessandro Molina
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Alessandro Molina
 
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 profitAlessandro Molina
 
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 MingAlessandro Molina
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Alessandro Molina
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2Alessandro Molina
 

More from Alessandro Molina (13)

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
 
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
 
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

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Post-Mortem Debugging and Web Development

  • 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 dev team 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. Dogslow ● Dogslow is a Django tool created by Bitbucket guys to monitor slow requests ● Notifies you by email, no need to check ● Really small codebase, it’s easy to port it to other environments ○ Upcoming BackLash version will provide a port of dogslow for frameworks apart Django
  • 25. 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
  • 27. Slow requests stack trace might not be enough
  • 28. 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.