With API 1.10.0 and the Raven_Client, we have the ability to create a breadcrumb with an associative array providing the parameters, which makes reading the code very clear as to what’s happening.
It also gives us other options in terms of how the parameter array is built up. It could be assembled over the course of some logic making some decisions, or, given all at once in the call.
eg:
$sentry_client->breadcrumbs->record([
'level' => 'debug',
'category' => 'my category',
'message' => 'my message',
]);
or
// logic that builds $breadcrumb[]
$breadcrumb = [];
...
// default
$breadcrumb['type'] = 'debug';
// is it really an error?
if({decide whether severity needs upgrading}) {
$breadcrumb['type'] = 'error';
}
...
$sentry_client->breadcrumbs->record($breadcrumb);
The benefits and flexibility of this approach include it not mattering which order the parameter name/value pairs are presented, and, flexibility in how the parameters are built.
For those that prefer readability over flexibility, if the array with values are all given in the call, then you have great readability.
By contrast: Currently, with API 2.0’s Sdk, we have available, the following:
use Sentry\Breadcrumb;
Sentry\addBreadcrumb(new Sentry\Breadcrumb(
Breadcrumb::LEVEL_DEBUG,
Breadcrumb::TYPE_ERROR,
'my category',
'my message'
));
There’s also the fluent way to arrive at the Breadcrumb object, but, leaving that aside:
Reading the above code sample, you’d have to ‘just know’ what order the parameters are required to be in. I understand that there’s some overhead and memory cost in constructing an associative array, but, the readability improvement is considered as outweighing the cost.
So: How about allowing an alternative approach to creating a breadcrumb being supported that allows us to continue the benefits of the old way?
eg:
Sentry\addBreadcrumbFromArray([
'level' => 'debug',
'type' => 'error',
'category' => 'sample category',
'message' => 'test message',
]);
or:
Sentry\addBreadcrumbFromArray([
'level' => Sentry\Breadcrumb:LEVEL_DEBUG,
'type' => Sentry\Breadcrumb:TYPE_ERROR,
'category' => 'my category',
'message' => 'test message',
]);
An even friendlier alternative would be to make the Sdk::addBreadcrumb function deal with variable arguments, so that both variants would be doable via the one function name:
so:
Sentry\addBreadcrumb([
'level' => 'debug',
'type' => 'error',
'category' => 'my category',
'message' => 'my message'
]);
and the existing way would be supported too:
Sentry\addBreadcrumb(new Breadcrumb('debug','error','my category', 'my message'));
I’d be willing to make some code submissions in the github repo to achieve being able to use the array to build the Breadcrumb either with or without variable arguments, if that helps.
how about it?
regards,
peter