Introducing Breadcrumbs for Laravel
source link: https://www.honeybadger.io/blog/laravel-breadcrumbs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Some time ago, we introduced breadcrumbs for Ruby and JavaScript. We're pleased to announce that breadcrumbs are now officially supported in our PHP libraries. Here's a quick walkthrough.
How do breadcrumbs help?
A big part of debugging errors is wondering, "How did this happen? Why is this value null?" To help with this, you've probably added extra logs to your app, so you can reference them when something happens.
Log::debug("Processed payment request for $userId");
Log::debug("Sending notification to user $userId on channel $channel");
But logs can be noisy and unstructured. Breadcrumbs let you replace those debug logs with structured event records. No more scouring log files to find out what was going on at 11:20 PM yesterday. Record these events with Honeybadger and you'll see the breadcrumbs right in the error detail on your dashboard.
Recording a breadcrumb is easy. Use the addBreadcrumb()
method on the Honeybadger client:
$honeybadger->addBreadcrumb('Sending notification', ['user' => $user->id, 'channel' => $channel]);
// In Laravel
Honeybadger::addBreadcrumb('Sending notification', ['user' => $user->id, 'channel' => $channel]);
If an error occurs later, the breadcrumb will show up in your dashboard:
In our example, the channel
is empty — that might be the cause of our error.
Automatic Breadcrumbs in Laravel
Even better, if you're using Laravel, we'll automatically capture breadcrumbs for interesting events. We listen for the following events:
- Log messages
- View renders
- Email dispatches
- Job dispatches
- Notification dispatches
- Database queries
- Redis commands
- Incoming requests
All of this can be configured in the config/honeybadger.php
config file.
How can you use them?
Breadcrumbs are currently available in our PHP client as of version 2.8.0, and in our Laravel client as of version 3.8.0. You can update your Honeybadger client by running:
composer update honeybadger-io/honeybadger-laravel
composer update honeybadger-io/honeybadger-php
(depending on which you're using.)
Be sure to check out our documentation for more details on using breadcrumbs in PHP.
Let us know how it goes!
We hope that breadcrumbs will be a helpful addition to your debugging toolbox. Try it out, and give us a shout if there is anything you would like to see added.
Shalvah Adebayo
Hi, I'm Shalvah. I'm passionate about making better dev tools, APIs, and documentation.
@theshalvah Author TwitterLevel up your software development career
Join our community of kick-ass developers as we learn engineering, DevOps, cloud architecture, and bootstrapping remote software companies. Tell me more →
We're Honeybadger. We'll never send you spam; we will send you cool stuff like exclusive content, memes, and special swag.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK