Download the PHP package zemkogabor/xinfra-php without Composer
On this page you can find all versions of the php package zemkogabor/xinfra-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zemkogabor/xinfra-php
More information about zemkogabor/xinfra-php
Files in zemkogabor/xinfra-php
Package xinfra-php
Short Description PHP client for sending logs and errors to xInfra.
License MIT
Informations about the package xinfra-php
xinfra-php
PHP client for xInfra, a log collection and monitoring app. It sends log events and errors to the xInfra ingest API.
- No dependencies besides the
curlandjsonextensions - Events are buffered and sent in batches, at the latest when the PHP process ends
- Sending never breaks your app: the timeout is short and every error is swallowed
- Optional global error handlers for apps without a framework
- Optional Monolog handler
Using Laravel? Use xinfra-laravel, it is built on this package.
Requirements
- PHP 8.3 or newer
ext-curl,ext-jsonmonolog/monolog3.x, only for the Monolog handler
Installation
Configuration
Client::fromEnvironment() reads these environment variables:
| Variable | Required | Description |
|---|---|---|
XINFRA_INGEST_URL |
yes | The ingest endpoint, e.g. https://xinfra.example.com/api/ingest/events |
XINFRA_INGEST_KEY |
yes | The key of the log client |
XINFRA_ENVIRONMENT |
yes | Environment name, e.g. prod. It must exist on the project in xInfra. |
XINFRA_LOG_LEVEL |
no | Minimum level to send. Default: warning |
XINFRA_RELEASE |
no | Version of your app, e.g. a git tag |
If the URL or the key is empty, sending is turned off and the client does nothing. This is handy in development and tests. If they are set, the environment is required too.
You can also create the config in code:
Usage
Plain PHP
ErrorHandler keeps the normal PHP behaviour: handlers registered before it are still called,
and without them PHP prints and logs errors as usual. Errors silenced with @ are not sent.
If your app already has its own error handler, call the client from it instead:
Monolog
- A
Throwablein theexceptioncontext key is sent as the exception of the event. - Tags come from
$record->extra['tags'], so you can add them with a processor:
Long running processes
Buffered events are sent when a batch is full or when the process ends. A queue worker or a
daemon may run for days, so call flush() after each job, otherwise rare errors wait in memory:
Processors
Processors can add data to every event, or drop an event by returning null:
GlobalRequestProcessor adds the URL, method, client IP and user agent of the current HTTP
request from $_SERVER. It reads X-Forwarded-For and X-Forwarded-Proto by default. If your
app is not behind a proxy, turn this off with new GlobalRequestProcessor(trustForwardedHeaders: false).
Event fields
| Field | Description |
|---|---|
level, message |
PSR-3 level and the message |
environment, release, server |
From the config |
timestamp |
Time of the event |
logger |
Name of the component. Events without an exception are grouped by logger and message. |
fingerprint |
Custom grouping key |
context |
Any extra data |
tags |
Short key-value pairs for filtering |
exception |
Type, message, file, line and stack trace |
request, ip, userAgent, user |
The HTTP request and the user |
Sensitive data (passwords, tokens) is masked and long fields are cut on the server side.
Development
License
MIT
All versions of xinfra-php with dependencies
ext-curl Version *
ext-json Version *