ability to monitor or measure performance, diagnose errors, collect and write trace information
<?php $logger->logf('saving user %s failed: %s', $username, $err); // saving user john.doe failed: cannot connect to database
everything is very goooood everything is very goooood everything is very goooood everything is very goooood everything is very goooood everything is very goooood cannot connect to database everything is very goooood everything is very goooood everything is very goooood everything is very goooood
everything is very goooood everything is very goooood everything is very goooood everything is very goooood everything is very goooood everything is very goooood cannot connect to database everything is very goooood everything is very goooood everything is very goooood everything is very goooood
<?php $logger->errorf('saving user %s failed: %s', $username, $err); // [ERROR] saving user john.doe failed: cannot connect to database
<?php $logger->error( 'saving user failed', [ 'user' => $username, 'reason' => $err, ] ); // [ERROR] saving user failed // user: john.doe // reason: cannot connect to database
<?php // 👎 DON'T!!! $logger->error('saving user failed', [ 'ip' => $ip, 'credit_card' => $creditCard, ] ); // 👍 DO! $logger->error('saving user failed', ['user_id' => $userId]);
<?php // 👎 DON'T!!! for ($i=0; $i < 100; $i++) { $logger->info('processing details', ['id' => $i]); } // 👍 DO! $logger->info('starting batch processing', ['items' => 100]); for ($i=0; $i < 100; $i++) { // if error $logger->error('failed to process item', ['id' => $i]); } $logger->info('finished batch processing', ['errors' => 1]);
(PHP: shared-nothing architecture 💩)
Correlation ID on steroids
https://github.com/census-instrumentation/opencensus-php
<?php // Creates a detached span $span = Tracer::startSpan(['name' => 'expensive-operation']); // Opens a scope that attaches the span to the current context $scope = Tracer::withSpan($span); try { $pi = calculatePi(1000); } finally { // Closes the scope (ends the span) $scope->close(); }
PHP: shared-nothing architecture 🚀
http://www.brendangregg.com/usemethod.html
https://twitter.com/LindsayofSF/status/692191001692237825
https://peter.bourgon.org/blog/2016/02/07/logging-v-instrumentation.html