crypt4 / jantung-php
Jantung for PHP
Requires
- php: ^7.4 || ^8.0 || ^8.1 || ^8.2
- guzzlehttp/guzzle: ^6.3.1|^7.0.1
- hisorange/browser-detect: ^4.5
- illuminate/support: ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
- ramsey/uuid: ^3.0 | ^4.7
Requires (Dev)
- mockery/mockery: ^1.5
- phpunit/phpunit: ^8.0 || ^9.0 || ^10.1
This package is auto-updated.
Last update: 2025-03-18 01:59:57 UTC
README
Jantung PHP Client
Jantung is a simple issue tracker for monitoring your application crashes. This package developed for PHP.
Installation
composer require crypt4/jantung-php
Adding New Metric
You can add a new metric as you see fit to your application / framework.
Do take note, all metrics will be converted to associative array.
In order to create your own metrics, you need to extends the class Crypt4\Jantung\Metric\Base
and implement your metrics details in metrics()
method which always return an array. You may need to define as a dot notation in your metric.
However, Jantung will convert to the associative array.
Following is an example for capture Http request for Laravel framework.
<?php namespace App\Metric; use Crypt4\Jantung\Support\Arr; use Crypt4\Jantung\Metric\Base; use Illuminate\Support\Str; class Http extends Base { public function metrics(): array { $startTime = defined('LARAVEL_START') ? LARAVEL_START : request()->server('REQUEST_TIME_FLOAT'); return [ 'http.client.duration' => $startTime ? floor((microtime(true) - $startTime) * 1000) : null, 'http.scheme' => request()->getScheme(), 'http.route' => request()->getRequestUri(), 'http.method' => request()->getMethod(), 'http.status_code' => http_response_code(), 'http.query' => request()->getQueryString(), 'http.uri' => str_replace(request()->root(), '', request()->fullUrl()) ?: '/', 'http.headers' => Arr::undot(collect(request()->headers->all()) ->map(function ($header) { return $header[0]; }) ->reject(function ($header, $key) { return in_array($key, [ 'authorization', config('jantung.header-key'), 'jantung-key', ]); }) ->toArray()), ]; } }
Once you have declared your metric, you can use in your application:
use App\Metrics\Http; use Crypt4\Jantung\Metric\Metric; $metric = new Metric(); $metric->add(new Http()); $metric->toArray();
If you are adding from Laravel framework, you can simply just add in config/jantung.php
:
'metrics' => [ \App\Metrics\Http::class, ];