How to ditch the debugger and use logging instead - devwinter 2015
-
Upload
skelton-thatcher-consulting-ltd -
Category
Software
-
view
768 -
download
0
Transcript of How to ditch the debugger and use logging instead - devwinter 2015
![Page 1: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/1.jpg)
How to ditch the debugger and use logging instead
Matthew Skelton & Rob Thatcher, Skelton Thatcher Consulting
/dev/winter 2015,
Saturday 24th January, Cambridge, UK
#devwinter
![Page 2: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/2.jpg)
Event tracingVagrant + ELK
Demo: no debugging
![Page 3: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/3.jpg)
Skelton ThatcherIntroduction and Services Overview
![Page 4: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/4.jpg)
‘Cloud’ changes the way we mustdesign, deliver, and operate
our software systems
![Page 5: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/5.jpg)
Changes for ‘cloud’
![Page 6: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/6.jpg)
Event tracing
![Page 7: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/7.jpg)
Event type IDsTransaction tracing
Adjusting logging levels
![Page 8: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/8.jpg)
Event type IDs
How many event types in your application?
![Page 9: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/9.jpg)
Event type IDs
![Page 10: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/10.jpg)
Event type IDs
enum
Human-readable sets: unique values, sparse, immutable
C#, Java, Python, node(Ruby, PHP, …)
![Page 11: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/11.jpg)
public enum EventID
{
// Badly-initialised logging data
NotSet = 0,
// An unrecognised event has occurred
UnexpectedError = 10000,
ApplicationStarted = 20000,
ApplicationShutdownNoticeReceived = 20001,
PageGenerationStarted = 30000,
PageGenerationCompleted = 30001,
MessageQueued = 40000,
MessagePeeked = 40001,
ItemAddedToBasket = 60001,
ItemRemovedFromBasket = 60002,
CreditCardDetailsSubmitted = 70001,
// ...
}
![Page 12: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/12.jpg)
Technical
Domain
public enum EventID
{
// Badly-initialised logging data
NotSet = 0,
// An unrecognised event has occurred
UnexpectedError = 10000,
ApplicationStarted = 20000,
ApplicationShutdownNoticeReceived = 20001,
PageGenerationStarted = 30000,
PageGenerationCompleted = 30001,
MessageQueued = 40000,
MessagePeeked = 40001,
ItemAddedToBasket = 60001,
ItemRemovedFromBasket = 60002,
CreditCardDetailsSubmitted = 70001,
// ...
}
![Page 13: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/13.jpg)
ItemAddedToBasket = 60001
![Page 14: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/14.jpg)
ItemAddedToBasket = 60001
![Page 15: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/15.jpg)
ItemAddedToBasket = 60001
![Page 16: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/16.jpg)
Transaction tracing
![Page 17: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/17.jpg)
Monolith to microservices:debugger does not have the full view
Distributed systems
![Page 18: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/18.jpg)
Even with remote debugger, it’s boring to attach and detach
Remote debugging?
![Page 19: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/19.jpg)
![Page 20: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/20.jpg)
Transaction tracing
Unique-ish identifier assigned to web request
Passed through downstream layers
![Page 21: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/21.jpg)
What about APM?
APM gives us application insightBUT
How much do we learn? Is APM available on the Dev box?
It’s not just ‘an Ops problem’!
![Page 22: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/22.jpg)
Minimal viable tracing?
Helps us to understand how the software really works
Small overhead is worth it
![Page 23: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/23.jpg)
Which log level is right?
DEBUG, INFO, WARNING, ERROR, CRITICAL
![Page 24: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/24.jpg)
Which log level is right?
Log level should *not* be fixed at compile or build time!
![Page 25: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/25.jpg)
<?xml version="1.0" encoding="utf-8" ?>
<Application.EventMappings>
<Events>
<Event Type="CacheServiceStarted">
<Severity Type="Information"/>
</Event>
<Event Type="PageCachePurged">
<Severity Type="Debug"/>
<Enabled="false"/>
</Event>
<Event Type="DatabaseConnectionTimeOut">
<Severity Type="Error"/>
</Event>
</Events>
</Application.EventMappings>
![Page 26: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/26.jpg)
Tune log levels
![Page 27: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/27.jpg)
Tune log levels
![Page 28: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/28.jpg)
Tune log levels
![Page 29: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/29.jpg)
Tune log levels
http://bit.ly/TuneLoggingLevels
![Page 30: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/30.jpg)
Dev and Ops collaboration*
* and testers too!
![Page 31: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/31.jpg)
![Page 32: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/32.jpg)
Event tracing
Use enumerations (or closest thing)
Technical and Domain event types
Distributed systems: debuggers less useful
Trace calls with ‘unique-enough’ handles
Tune log levels via config
![Page 33: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/33.jpg)
Vagrant + ELK
![Page 34: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/34.jpg)
Log AggregationElasticsearch, Logstash & Kibana
Vagrant
![Page 35: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/35.jpg)
Log Aggregation
![Page 36: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/36.jpg)
Multiple log sourcesMany logs in one place
SearchableTime Sequenced
![Page 37: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/37.jpg)
![Page 38: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/38.jpg)
![Page 39: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/39.jpg)
![Page 40: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/40.jpg)
![Page 41: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/41.jpg)
What is ELK?
http://www.exploringnature.org/db/detail.php?dbID=43&detID=956
![Page 42: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/42.jpg)
![Page 43: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/43.jpg)
Vagrant
![Page 44: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/44.jpg)
Ruby CLI to deploy Virtual environments
Deploy locally to AWS or Azure etc.
![Page 45: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/45.jpg)
Four Simple Steps
$ vagrant box add ubuntu/trusty64$ vagrant init trusty64$ vagrant up$ vagrant ssh
![Page 46: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/46.jpg)
RapidRepeatable
Provisioning via scripts ++
![Page 47: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/47.jpg)
• Listening to: • Local nginx logs• Local Syslog• (Application logs)
http://bit.ly/velk-demo
Vagrant + ELK Demo VM
![Page 48: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/48.jpg)
Elasticsearch, Logstash, Kibana
![Page 49: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/49.jpg)
![Page 50: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/50.jpg)
![Page 51: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/51.jpg)
![Page 52: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/52.jpg)
![Page 53: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/53.jpg)
![Page 54: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/54.jpg)
Recap
![Page 55: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/55.jpg)
Aggregated Logging:Vagrant + ELK
Centralised logs, time sequenced, searchableVagrant :quickly spin up & manage machines
ELK : collect, store, display & search logsDeveloper-friendly!
![Page 56: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/56.jpg)
Demo: ditching the debugger
![Page 57: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/57.jpg)
Vagrant on developer laptopELK for log aggregationWeb app: PHP (Slim)
Event type IDs
Demo: background
![Page 58: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/58.jpg)
Use VirtualBoxshared folders
Browse to Kibana UI via NAT-ed interface
![Page 59: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/59.jpg)
Event type IDsLog aggregation with ELK
Demo
![Page 60: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/60.jpg)
![Page 61: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/61.jpg)
![Page 62: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/62.jpg)
![Page 63: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/63.jpg)
![Page 64: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/64.jpg)
![Page 65: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/65.jpg)
![Page 66: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/66.jpg)
![Page 67: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/67.jpg)
![Page 68: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/68.jpg)
![Page 69: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/69.jpg)
![Page 70: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/70.jpg)
![Page 71: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/71.jpg)
![Page 72: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/72.jpg)
![Page 73: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/73.jpg)
![Page 74: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/74.jpg)
![Page 75: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/75.jpg)
![Page 76: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/76.jpg)
![Page 77: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/77.jpg)
![Page 78: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/78.jpg)
![Page 79: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/79.jpg)
Demo: summary
Super-easy to hook application logs into ELK
Sequences of events emerge
Compare timings of events: past and present
![Page 80: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/80.jpg)
Recapitulation
![Page 81: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/81.jpg)
How to ditch the debuggerUse Vagrant + ELK on development VM
Use a set of event type IDs (enums)Log distinct states of execution
Both technical and domain eventsConsistent event naming helps with searchCompare previous and current executions New logging-fu: make friends with Ops!
![Page 82: How to ditch the debugger and use logging instead - devwinter 2015](https://reader034.fdocuments.us/reader034/viewer/2022051400/55a78cab1a28ab1a6e8b47c6/html5/thumbnails/82.jpg)
LinksTune logging levels in Production without recompiling code: http://bit.ly/TuneLoggingLevels
VELK (Vagrant + ELK) demo VM: http://bit.ly/velk-demo
GOOS book (section on logging: p.233-5):http://www.growing-object-oriented-software.com/