Monitoring aplikasi Laravel yang dibuat sangat penting untuk mengetahui apa yang terjadi di aplikasi anda, seperti error, timeout dan lain sebagainya. Salah satu yang banyak digunakan adalah Sentry, dengan adanya fasilitas free member untuk aplikasi kecil sudah mencukupi untuk log data errornya.

Install Laravel

Bila anda memulai dari awal, install Laravel terlebih dahulu

composer create-project --prefer-dist laravel/laravel aplikasi-monitoring

kalo Laravelnya sudah ada anda bisa langsung lompat ke tahap selanjutnya.

Buat Project Baru

Dari halaman dashboard sentry.io buat project baru
create new project sentry
Akhiri dengan mengklik Create Project

tunggu beberapa saat akan muncul cara konfigurasi Sentry. Bagian yang penting disini adalah

php artisan sentry:publish --dsn=https://7d3104fac49061111ccf85cf111853@o3111774.ingest.sentry.io/56112376

bagian ini nanti akan kita jalankan

Install Sentry

Dengan bantuan composer, cara install sentry menjadi jauh lebih mudah. Pindah ke folder project anda, lalu jalankan

composer require sentry/sentry-laravel

jika proses tersebut tidak berhasil dan muncul error

Using version ^2.3 for sentry/sentry-laravel
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in /usr/share/php/Composer/DependencyResolver/RuleWatchGraph.php on line 52
 
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in /usr/share/php/Composer/DependencyResolver/RuleWatchGraph.php on line 52

ubah perintah install composer tersebut menjadi

COMPOSER_MEMORY_LIMIT=-1 composer require sentry/sentry-laravel

Konfigurasi Sentry

Disini kita akan perlu merubah konfigurasi Exception untuk Laravel, bisa Exception muncul akan langsung ditangkap dan dikirim ke Sentry.io. Walaupun dikirim ke Sentry, di aplikasi Laravel error tersebut tetap bisa dilihat di folder logs (storage/logs)
Buka file app/Exceptions/Handler.php, pada bagian

public function register()
{
    $this->reportable(function (Throwable $e) {
        //
    });
}

ubah menjadi

public function register()
{
    $this->reportable(function (Throwable $e) {
        if (app()->bound('sentry') && $this->shouldReport($e)) {
            app('sentry')->captureException($e);
        }
 
        parent::report($e);
    });
}

Sekarang daftarkan aplikasi Laravel ke project Sentry yang baru dibuat tadi

php artisan sentry:publish --dsn=https://7d3104fac49061111ccf85cf111853@o3111774.ingest.sentry.io/56112376

pada pilihan

Enable Performance Monitoring? (yes/no) [yes]: # isi no
Want to send a test Event? (yes/no) [yes]: # isi yes

Tunggu sekitar 1 menit, buka kembali halaman sentry, dibagian Issue
sentry project issue

Join the Conversation

3 Comments

Your email address will not be published. Required fields are marked *

  1. Min kalo error kaya gini pas daftarin laravel ke projek sentry gimana yak?

    There was an error sending the event.
    SDK: Failed to send the event to Sentry. Reason: “SSL certificate problem: certificate has expired for “https://o1091853.ingest.sentry.io/api/6111068/store/”.”.
    The problem might be related to the Let’s Encrypt root certificate that expired and your machine not having an up-to-date enough OpenSSL version or still having the expired root in your certificate authority store.
    For more information you can check out this forum post from Let’s Encrypt that contains helpful links on how to resolve this for your environment: https://community.letsencrypt.org/t/production-chain-changes/150739/4

    Makasih bantuannya min

  2. Terimakasih atas ilmunya min, sangat bermanfaat tapi saya coba install terdapat error sebagai berikut

    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    – sentry/sentry-laravel 2.x-dev is an alias of sentry/sentry-laravel dev-master and thus requires it to be installed too.
    – sentry/sentry-laravel[dev-master, 2.7.0] require sentry/sdk ^3.1 -> satisfiable by sentry/sdk[3.1.0].
    – sentry/sdk 3.1.0 requires http-interop/http-factory-guzzle ^1.0 -> satisfiable by http-interop/http-factory-guzzle[1.0.0].
    – http-interop/http-factory-guzzle 1.0.0 requires guzzlehttp/psr7 ^1.4.2 -> found guzzlehttp/psr7[1.4.2, …, 1.x-dev] but the package is fixed to 2.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    – Root composer.json requires sentry/sentry-laravel ^2.7 -> satisfiable by sentry/sentry-laravel[2.7.0, 2.x-dev (alias of dev-master)].

    Use the option –with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

    Installation failed, reverting ./composer.json and ./composer.lock to their original content.

    bagaimana solusinya yah min? mohon bantuanya terimakasih.

    1. Salah satunya update manual package.json sesuai versi minimal yang dibutuhkan, atau lewat composer

      composer update  --with-all-dependencies