sentry-laravel icon indicating copy to clipboard operation
sentry-laravel copied to clipboard

Improve the display of sql.binding in breadcrumbs

Open oleksiikhr opened this issue 3 years ago • 0 comments

I often use Value Objects as values in Eloquent queries, these classes look something like this:

<?php

declare(strict_types=1);

namespace App\ValueObjects;

use InvalidArgumentException;

final class UserName
{
    public function __construct(private string $value)
    {
        if (empty($value)) {
            throw new InvalidArgumentException('Name cannot be empty.');
        }
    }

    public function getValue(): string
    {
        return $this->value;
    }

    public function __toString(): string
    {
        return $this->value;
    }
}

The logic of the execution itself looks like this:

Route::get('/debug-sentry', function () {
    \Illuminate\Support\Facades\DB::transaction(static function () {
        \App\Models\User::query()
            ->create([
                'name' => new \App\ValueObjects\UserName('My Name'),
                'email' => new \App\ValueObjects\UserEmail('[email protected]'),
                'password' => new \App\ValueObjects\UserPassword('password'),
            ]);

        throw new Exception('Just error');
    });
});

And when any error occurs, in BREADCRUMBS, in the sql.query category I see the following:

image

All passed objects turn into {}, it would be cool if I could see the actual values that eloquent performs.

oleksiikhr avatar Feb 18 '22 19:02 oleksiikhr