Download the PHP package songhieu/monitor-track-laravel without Composer

On this page you can find all versions of the php package songhieu/monitor-track-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package monitor-track-laravel

monitor-track for Laravel

tests Packagist

songhieu/monitor-track-laravel sends structured events to monitor-track App Logs. Plain log lines can't carry this data: exceptions with real stack frames, exact queue job runs, scheduled task runs that register themselves, queue worker heartbeats, and slow or N+1 database queries with the line of your code that ran them. The wire format is described in docs/sdk-spec.md.

Requires PHP 8.0+ and Laravel 9, 10, 11, 12 or 13 (Monolog 2 or 3). Every combination is tested in CI on PHP 8.0–8.5, including the lowest supported versions. Laravel 9, 10 and 11 no longer receive security fixes; Composer 2.10+ refuses to install them while they have open advisories — upgrading is the real fix.

Install

On Kubernetes, run the test inside a pod with --pod-log:

kubectl exec gives the command its own stderr, which is not the container log the collector reads; --pod-log writes to the container's stderr (/proc/1/fd/2) instead. It must run as the same user as the container's main process, which is what kubectl exec does by default.

Package discovery registers the service provider and the MonitorTrack facade. The default transport writes one JSON line per event to stderr. The monitor-track collector already reads pod logs, so on Kubernetes you usually don't need to configure anything else — no key, and no network call from the app.

Outside Kubernetes (a VM, shared hosting), create an HTTP push log source in monitor-track to get a key (mt_src_…, shown once) and send the events straight to the ingest service:

To publish the config file (optional):

Configuration

These MT_* variables are the same in the Go and Python SDKs.

env default meaning
MT_ENABLED true false makes every call a no-op and registers no listeners
MT_TRANSPORT stream stream | file | http
MT_STREAM stderr stderr | stdout
MT_FILE storage/logs/monitor-track.jsonl file transport path
MT_ENDPOINT — http transport base URL, e.g. https://monitor.example.com
MT_TOKEN — source push token (http)
MT_APP config('app.name') app field
MT_ENV app()->environment() env field
MT_RELEASE — release field (e.g. image tag)
MT_SAMPLE_RATE 1 0..1, applies to type=log only
MT_QUEUE_SIZE 1000 http transport: max events buffered per PHP process
MT_HEARTBEAT_SECONDS 15 queue worker heartbeat interval
MT_LOG_LEVEL debug minimum level of the monitor-track log channel
MT_SLOW_QUERY_MS 500 report queries at least this slow; 0 turns it off
MT_N_PLUS_ONE 10 report a statement run this many times in one request / job / command (minimum 2); 0 turns it off
MT_QUERY_THROTTLE_SECONDS 60 at most one query event per statement and call site per window per server; 0 sends every one
MT_LONG_RUNNING_COMMANDS — your own daemon commands, comma-separated names or patterns (distribution:*): not a query scope themselves, like queue:work

With MT_TRANSPORT=http and no MT_ENDPOINT, the SDK falls back to stream. config/monitor-track.php also has capture.exceptions|queue|schedule|queries switches and the http timeouts.

What is captured automatically

source events
ExceptionHandler::reportable() exception with frames (innermost first, relative to base_path(), in_app = not vendor/), route POST /api/v1/payments/{payment}, user id (only when the guard already loaded the user, so no extra query), trace id from traceparent or X-Request-Id. Exceptions in $dontReport (404, validation, …) are skipped as usual.
Queue worker (JobProcessing, JobProcessed, JobFailed, JobExceptionOccurred, JobReleasedAfterException, JobTimedOut) job start, then exactly one of done / failed / retry per attempt, with queue, connection, class, uuid, attempts, runtime_ms, timeout_ms
Queue worker Looping heartbeat every MT_HEARTBEAT_SECONDS: queues, busy/idle, current job, memory, processed count. Only queue workers (queue:work, horizon:work) send heartbeats; a dispatch_sync() job in a web request or an Octane worker is a job run, not a worker.
Scheduler (ScheduledTaskStarting, Finished, Failed, Skipped, ScheduledBackgroundTaskFinished) cron start / success / fail / skip with name, expression, timezone, exit code, duration and the output tail on failure. The first event registers the task in monitor-track with its schedule.
Database (QueryExecuted) query n_plus_one / slow per request, job, command or scheduled task, with the normalized SQL, count, total and max time, and the call site. See Slow queries and N+1.

The task name is the task's description if it has one. Otherwise it is the artisan command without the PHP binary (for example invoices:send-reminders). Closures with no ->name() are named closure:<file>:<line>.

Slow queries and N+1

The SDK listens to Laravel's QueryExecuted event and reports two problems as query events:

Statements are compared by shape: in (?, ?, ?) lists become in (?), and string and number literals become ?. The SDK never reads the bindings, so no values leave the app, and the SQL sent is at most 2000 bytes. A statement repeated only inside framework or vendor code, with none of your code on the stack (the migrator, the queue and cache drivers), is not reported as N+1.

Findings are sent when the unit of work ends: after the response for a request, and when the job, command or scheduled task finishes. A queue worker (queue:work, Horizon) and the other long-running commands (schedule:work, octane:*, reverb:start, pulse:*) are not a unit themselves. Each job they run is one, and the worker's own polling queries are ignored. Add your own daemon commands to that list with MT_LONG_RUNNING_COMMANDS=distribution:*,reports:daemon (names or * patterns); otherwise a command that loops for hours is one unit, and a statement it repeats over its lifetime is reported as N+1 when it exits. Counters start empty for every job and request, so nothing builds up in a long-running worker or an Octane process.

Events are samples. The SDK sends at most one event per statement and call site per MT_QUERY_THROTTLE_SECONDS (60) per server. An N+1 endpoint serving 100 requests a second sends one event a minute, not 100 a second. The count in an event is for that one request or job. The window is kept in marker files in the system temp dir (mt-q-*), so it works across PHP-FPM requests and between FPM and the queue workers. If the temp dir is not writable, 1% of the events are sent instead.

To tune it or turn it off:

With both set to 0, or 'capture' => ['queries' => false] in config/monitor-track.php, the SDK registers no query listener at all.

Overhead. Each query costs about 0.5 µs in the SDK: one normalization, remembered for repeated SQL, and one counter update. Laravel's own event dispatch adds about 1 µs. The SDK only takes a backtrace (under 0.1 ms) when a statement reaches the N+1 threshold, once per request or job, and for each slow query. Memory per request or job is bounded to 1000 distinct statements and 100 findings of each kind. Events are built and throttled when the request or job ends, which is after the response under FPM.

Logging channel

The provider adds a monitor-track channel. Its records become log events, or exception events when the context has an exception:

Pick the setup that matches your transport:

Each exception is sent once, even when both the exception handler and a log call see it.

You can also attach the handler yourself: new MonitorTrack\Monolog\Handler(app(MonitorTrack\Client::class), 'warning').

Manual API

trackJob and trackCron record the exception and rethrow it unchanged.

In your application's tests, MonitorTrack::fake() routes events to memory:

Transports

Laravel Octane

The SDK works under Octane (Swoole, RoadRunner) without configuration:

Octane (1.x and 2.x) stops Swoole with SIGKILL (octane:stop, or SIGTERM to octane:start, which is what supervisord and Kubernetes send), so no PHP code runs at that point: up to the last ~2 s of events of each worker can be lost when the server is stopped. The same goes for a worker killed for exceeding Octane's max_execution_time. With RoadRunner there is no timer: what a request leaves in the buffer goes with a later request or when the worker stops.

With the stream transport, worker output passes through octane:start, which re-encodes JSON lines before printing them. Prefer the http or file transport under Octane.

Why this never slows your app

Known limits


All versions of monitor-track-laravel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/contracts Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/queue Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
monolog/monolog Version ^2.0|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package songhieu/monitor-track-laravel contains the following files

Loading the files please wait ...