Download the PHP package sturents/sentry-light without Composer

On this page you can find all versions of the php package sturents/sentry-light. 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 sentry-light

sturents/sentry-light

Lightweight Sentry client with no dependencies. Forked from kodus/sentry as that package is no longer maintained and is causing breaks in newer PHP versions.

PHP Version Build Status

About

This package is an alternative to the official PHP client for Sentry.

The library consists of a client class, an event-model model that matches the shape of the Sentry API, and an interface for extensions.

The API deviates from the Unified API recommendation - our goal is to log detailed exceptions, and capture log-entries leading up to those exceptions, with as little coupling and dependency on the client as possible.

With most members declared as protected, you can further extend and override/enhance various aspects of exception/error/request-processing with simple code that modifies the (fully type-hinted) model.

Features

This client has most of the features of the official client plus some extras.

All features are opt-in, and the package ships with the following extensions:

Non-features:

Usage

Most modern frameworks by now have some sort of DI container and an error-handler.

To avoid getting caught up in the specifics of various frameworks, in this section, we'll demonstrate how to bootstrap and integrate the client independently of any specific framework.

To bootstrap the client itself, you need a Sentry DSN, an EventCapture implementation, and a your choice of extensions - this example uses DirectEventCapture and most of the built-in extensions:

Some extensions support additional options, which will be described in the Configuration section.

To capture PHP errors, we'll need to add an error-handler that maps errors to instances of the built-in ErrorException class.

Note that most frameworks and error-handlers already have something like this built-in - an existing error-handler likely is designed to be the only global error-handler, and will likely offer an abstraction and some sort of API over set_error_handler().

The following simplified error-handler throws for all error-levels except E_NOTICE and E_WARNING, which it silently captures to the $client instance we created above:

Now that we have ErrorException being thrown for PHP errors, we can handle any error/exception consistently with a try/catch-statement surrounding any statements in the top-level script:

We now have basic error-handling and silent capture of warnings and notices.

In a PSR-15 middleware context, we can capture useful additional information about the ServerRequestInterface instance that initiated the error - typically, we'll do this with a middleware at the top of the middleware-stack, which will delegate to the next middleware from a try/catch-block.

Here's a basic example of an anonymous middleware being added to an array of middlewares:

Any error caught by this middleware won't bubble to our first try/catch-statement in the top-level script - instead, the call to captureException() from the middleware includes both the $error and the $request (which doesn't exist yet in the top-level script) from which the client can capture a lot more detail.

In addition, your application may log incidental useful information (such as database queries) during normal operation - on failure, this information can help you diagnose the events leading up to an error.

These log entries can be captured as so-called "breadcrumbs" using the provided BreadcrumbLogger, which is both a PSR-3 LoggerInterface implementation and a SentryClientExtension.

You might want to bootstrap this as your primary logger - maybe you only care about log-entries that lead to an error condition. However, it's more likely you'll want another logger to send log-events to a persisted log, as well as recording them as breadcrumbs. (For example, you may try the monolog/monolog package, which allows you to log to any combination of PSR-3 and monolog-handlers, filter the log-entries, and so on - or mouf/utils.log.psr.multi-logger, if you prefer something simple.)

Note that log-entries will buffer in the logger until you capture an exception - if your application is a CLI script handling many requests, you will need to manually call clear() on the logger instance at the end of a successful request, since otherwise log-entries will accumulate across requests.

Notice: PHP 7.4 introduced a new ini setting (zend.exception_ignore_args) for excluding arguments from stack traces. If you want arguments to be passed on to Sentry you will need to turn this setting off.

Configuration

A few of the extensions support optional constructor arguments to configure some optional features.

ExceptionReporter

The constructor accepts two optional argument:

In addition, the public $error_levels property lets you customize how PHP error-levels map to Sentry severity-levels. The default configuration matches that of the official 2.0 client.

ClientSniffer

If your client base uses rare or exotic clients, you can add your own regular expression patterns to to the public $browser_patterns and $os_patterns properties to enhance the browser classifications. The default configuration will recognize most common browsers and versions, operating systems and bots.

ClientIPDetector

Replace or add to $user_ip_headers to detect client IP addresses in unusual environments. The built-in patterns support most ordinary cache/proxy-servers.

BreadcrumbLogger

The default $log_levels match those of the official (2.0) client - if needed, you can override with custom mappings from PSR-5 log-level to Sentry severity-level.

BufferedEventCapture

A buffered EventCapture implementation is available.

If you're capturing exceptions/errors only, you probably don't need this - but if you're mapping warnings and notices to ErrorException with an error-handler, you may wish to avoid blocking the response while posting to Sentry.

You can accomplish this using the BufferedEventCapture decorator, which allows you to defer the actual HTTP request(s) until after you've sent the response to the user.

In this case, you will need to bootstrap the capture and client instances separately:

Since Events will now get buffered rather than directly posted to Sentry, you will need to manually flush the Events at the of the request.

In a typical PHP FCGI SAPI-environment, you can accomplish this by explicitly closing the HTTP response immediately before flushing the events to Sentry - for example, from an index.php file:

Customization

The client class and extensions were designed with project-specific extensions in mind and contain many protected methods designed for you to extend and override their behavior.

Using protected overrides, you can customize how events get created and captured, how exceptions and requests get processed, client IP detection and filtering, how PHP values are formatted in stack-traces, and many other details.

Please refer to the source-code for available protected methods - and note that we're committed to versioning this package semantically: any breaking changes to protected methods will be versioned as major releases.

Why?

Openly opinionated fluff:

Version 1.x of the official Sentry PHP client is dated, and not a good fit for a modern (PSR-7/15) application stack.

Version 2.0 (currently in development) is an architectural masterpiece - which is not what we need/want from something that's going to essentially collect some data and perform a simple JSON POST request.

Specifically:

We want something simple, fast and transparent.

We also insist on code with good IDE support, which provides better insight for someone reading/modifying the code, and reduces the potential for silent errors - the official client juggles array values, whereas our model formally describes the JSON body-shape with a plain PHP class-hierarchy that implements JsonSerializable.

Note that we only model the portion of the JSON body shape that makes sense in a PHP context - if you find something to be missing or incorrect, pull-requests are more than welcome.


All versions of sentry-light with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-json Version *
psr/http-message Version ^1 | ^2
psr/log Version ^1 | ^2 | ^3
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 sturents/sentry-light contains the following files

Loading the files please wait ....