shiftonelabs/php-rollbar-extensions

Adds extra strategies for PHP Rollbar customization.

1.0.0 2019-12-13 06:39 UTC

This package is auto-updated.

Last update: 2024-12-13 18:18:10 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This package provides extra strategies to be used with the Rollbar SDK for PHP. The base Rollbar SDK comes with some default strategies for truncation, but they don't always do everything that is needed. The configuration allows for specifying custom strategies for transforming, truncating, etc, and this package aims to provide some of these custom strategies.

Install

Via Composer

$ composer require shiftonelabs/php-rollbar-extensions

Configuration

Rollbar configuration is dependent on the framework/application being used.

Rollbar documentation for installing rollbar for PHP: https://docs.rollbar.com/docs/php

Rollbar configuration options: https://docs.rollbar.com/docs/php-configuration-reference

Usage

This package provides a set of classes that can be provided to the Rollbar configuration. For the most part, usage of this queue driver is the same as the built in queue drivers. There are, however, a few extra things to consider when working with Amazon's SQS FIFO queues.

Custom Data Method

Allows creating dynamic custom data on runtime during error reporting. The callable taking two parameters $toLog (the context of what's being logged) and $context (additional context data provided in the config). You provide $context by adding custom_data_method_context key to the $extra or $context parameters Rollbar::log or RollbarLogger::log.

-- Rollbar config reference

To specify a custom data method to use, set the custom_data_method key of the Rollbar config to a new instance of an invocable Custom Data Method class. These classes should implement the \ShiftOneLabs\PhpRollbarExtensions\CustomDataInterface interface.

No custom data methods available yet.

Custom Truncation

A fully qualified name of your custom truncation strategy class. It has to inherit from \Rollbar\Truncation\AbstractStrategy. This custom strategy will be applied before the built-in strategies.

-- Rollbar config reference

To specify a custom truncation to use, set the custom_truncation key of the Rollbar config to the fully qualified name of the class to use.

No custom truncation methods available yet.

Transformers

From Rollbar:

The class to be used to transform the payload before it gets prepared for sending to Rollbar API. It has to implement \Rollbar\TransformerInterface.

-- Rollbar config reference

To specify a transformer to use, set the transformer key of the Rollbar config to the fully qualified name of the class to use.

Available transformers:

AddExceptionPropertiesTransformer

When an exception is logged to Rollbar, only the basic exception information is sent to Rollbar (exception name, message, code, line number, file, previous exception, and stack trace). However, if you have created a custom exception with additional properties, the values of those properties are not sent to Rollbar by default. Sometimes this information is very valuable in attempting to debug the issue.

The AddExceptionPropertiesTransformer transformer will add all data stored on the exception to the "custom" element of the Rollbar payload, under a new "properties" key. This includes all defined public, protected, and private properties, as well as any properties dynamically assigned at runtime. This transformer also traverses the exception chain, so all the properties for the set "previous" exceptions will be reported, as well. This custom data will be displayed in Rollbar for each occurrence.

Example configuration: 'transformer' => \ShiftOneLabs\PhpRollbarExtensions\Transformers\AddExceptionPropertiesTransformer::class

Contributing

Contributions are welcome. Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email patrick@shiftonelabs.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.