Skip to content

Commit

Permalink
Merge pull request #13 from OxCom/develop
Browse files Browse the repository at this point in the history
update configuration
  • Loading branch information
OxCom authored Aug 15, 2018
2 parents df3755c + 1d7fc22 commit 2fc9c6f
Show file tree
Hide file tree
Showing 20 changed files with 387 additions and 113 deletions.
18 changes: 13 additions & 5 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ public function getConfigTreeBuilder()
->scalarNode('endpoint')->defaultValue(static::API_ENDPOINT)->end()
->scalarNode('base_api_url')->defaultValue(static::API_ENDPOINT)->end()
->scalarNode('branch')->defaultValue(static::BRANCH)->end()
->booleanNode('capture_email')->defaultFalse()->end()
->booleanNode('capture_ip')->defaultTrue()->end()
->booleanNode('capture_username')->defaultFalse()->end()
->booleanNode('capture_error_stacktraces')->defaultTrue()->end()
->scalarNode('checkIgnore')->defaultNull()->end()
->scalarNode('check_ignore')->defaultNull()->end()
->scalarNode('code_version')->defaultValue('')->end()
->booleanNode('enable_utf8_sanitization')->defaultTrue()->end()
->scalarNode('environment')->defaultValue(static::ENVIRONMENT)->end()
Expand All @@ -100,7 +103,10 @@ public function getConfigTreeBuilder()
->end()
->end()
->defaultValue([])
->end()
->end()
->scalarNode('custom_data_method')->defaultNull()->end()
->scalarNode('custom_truncation')->defaultNull()->end()
->scalarNode('ca_cert_path')->defaultNull()->end()
->arrayNode('error_sample_rates')
->treatNullLike([])
->useAttributeAsKey('key')
Expand All @@ -111,7 +117,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->defaultValue([])
->end()
->end()
->arrayNode('exception_sample_rates')
->treatNullLike([])
->useAttributeAsKey('key')
Expand All @@ -122,7 +128,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->defaultValue([])
->end()
->end()
->scalarNode('fluent_host')->defaultValue(static::FLUENT_HOST)->end()
->scalarNode('fluent_port')->defaultValue(static::FLUENT_PORT)->end()
->scalarNode('fluent_tag')->defaultValue(static::FLUENT_TAG)->end()
Expand All @@ -145,14 +151,16 @@ public function getConfigTreeBuilder()
->defaultValue(static::$scrubFieldsDefault)
->end()
->scalarNode('scrub_whitelist')->defaultNull()->end()
->scalarNode('transformer')->defaultNull()->end()
->scalarNode('verbosity')->defaultValue(\Psr\Log\LogLevel::ERROR)->end()
->booleanNode('shift_function')->defaultTrue()->end()
->scalarNode('timeout')->defaultValue(static::TIMEOUT)->end()
->booleanNode('report_suppressed')->defaultFalse()->end()
->booleanNode('use_error_reporting')->defaultFalse()->end()
->scalarNode('proxy')->defaultNull()->end()
->booleanNode('send_message_trace')->defaultFalse()->end()
->booleanNode('include_raw_request_body')->defaultFalse()->end()
->booleanNode('local_vars_dump')->defaultFalse()->end()
->booleanNode('local_vars_dump')->defaultTrue()->end()
->end()
->end()
->arrayNode('rollbar_js')->children()
Expand Down
19 changes: 19 additions & 0 deletions Provider/InterfaceCustomData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace SymfonyRollbarBundle\Provider;

/**
* Interface InterfaceCustomData
*
* @package SymfonyRollbarBundle\Provider
*/
interface InterfaceCustomData
{
/**
* @param \Exception|\Throwable|string $toLog
* @param mixed $context
*
* @return array
*/
public function __invoke($toLog, $context);
}
19 changes: 19 additions & 0 deletions Provider/InterfaceLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace SymfonyRollbarBundle\Provider;

/**
* Interface InterfaceLogger
*
* @package SymfonyRollbarBundle\Provider
*/
interface InterfaceLogger
{
/**
* @param mixed $level
* @param string $message
*
* @return void
*/
public function log($level, $message);
}
51 changes: 44 additions & 7 deletions Provider/RollbarHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,31 @@ class RollbarHandler extends AbstractProcessingHandler
* @var array
*/
protected $injectServices = [
// config option, method
'person_fn' => 'getPerson',
'checkIgnore' => 'checkIgnore',
/**
* 'person_fn' can be:
* - service::__invoke()
* - service::getPerson() - see: \SymfonyRollbarBundle\Provider\InterfacePersonProvider
* - function() { ... }
*/
'person_fn' => 'getPerson',
/**
* 'check_ignore' can be:
* - service::__invoke()
* - service::checkIgnore() - see: \SymfonyRollbarBundle\Provider\InterfaceCheckIgnore
* - function() { ... }
*/
'check_ignore' => 'checkIgnore',
/**
* 'custom_data_method' can be:
* - service::__invoke() - see: \SymfonyRollbarBundle\Provider\InterfaceCustomData
* - function() { ... }
*/
'custom_data_method' => null,
/**
* 'logger' can be:
* - service::log() - see: \SymfonyRollbarBundle\Provider\InterfaceLogger
*/
'logger' => 'log',
];

/**
Expand Down Expand Up @@ -156,18 +178,33 @@ protected function mapConfigValues($rConfig)
protected function injectService($name, $method)
{
$container = $this->getContainer();
$service = null;

if ($container->has($name)) {
$service = $container->get($name);
} elseif (class_exists($name)) {
$service = new $name($container);
}

if (!empty($service) && method_exists($service, $method)) {
return [$service, $method];
} else {
return is_callable($name) ? $name : null;
$toCall = null;
switch (true) {
case (empty($service)):
// inline function
$toCall = is_callable($name) ? $name : null;
break;

case (!empty($service) && empty($method)):
// service with __invoke()
$toCall = is_callable($service) ? $service : null;
break;

case !empty($service) && !empty($method) && method_exists($service, $method):
// service with provided method
$toCall = [$service, $method];
break;
}

return $toCall;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Bundle for Symfony Framework (v2.8.x, 3.x, 4.x) that integrates Rollbar tracker

Find all documentation here [here](https://github.com/OxCom/symfony-rollbar-bundle/tree/master/Resources/doc)
More documentation here [here](https://github.com/OxCom/symfony-rollbar-bundle/tree/master/Resources/doc)

# Install
1. Add bundle as dependency
Expand All @@ -23,7 +23,10 @@ Find all documentation here [here](https://github.com/OxCom/symfony-rollbar-bund
- \AppBundle\Exceptions\MyAwesomeException
rollbar:
access_token: 'some-secret-token-here'
rollbar_js:
access_token: 'some-public-token-here'
```

# Bugs and Issues
Please, if You found a bug or something, that is not working properly, contact me and tell what's wrong. It's nice to have an example how to reproduce a bug, or any idea how to fix it in Your request. I'll take care about it ASAP.
Please, if You found a bug or something, that is not working properly, contact me and tell what's wrong.
It's nice to have an example how to reproduce a bug, or any idea how to fix it in Your request. I'll take care about it ASAP.
37 changes: 37 additions & 0 deletions Resources/doc/check_ignore.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Configuration: Check Ignore
=============

The function called before sending payload to Rollbar, return true to stop the error from being sent to Rollbar.

Examples
------------------
Use globally defined function:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
check_ignore: 'function_name_here'
Use custom ``CheckIgnoreProvider`` class that should implements ``InterfaceCheckIgnore``:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
check_ignore: '\SymfonyRollbarBundle\Tests\Fixtures\CheckIgnoreProvider'
Use custom ``CheckIgnoreProvider`` service that class should implements ``InterfaceCheckIgnore``:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
check_ignore: 'awesome_app.rollbar_check_ignore_provider'
112 changes: 26 additions & 86 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Simple configuration of bundle:
base_api_url: 'https://api.rollbar.com/api/1/'
branch: 'master'
capture_error_stacktraces: true
checkIgnore: null
check_ignore: null
code_version: ''
enable_utf8_sanitization': true
environment: 'production'
Expand Down Expand Up @@ -55,27 +55,35 @@ Simple configuration of bundle:
proxy: null
send_message_trace: false
include_raw_request_body: false
local_vars_dump: false
local_vars_dump: true
capture_email: false
capture_ip: true
capture_username: false
custom_data_method: null
custom_truncation: null
ca_cert_path: null
transformer: null
verbosity: 'error'
rollbar_js:
enabled: true
accessToken: 'some-public-token'
captureUncaught: true
uncaughtErrorLevel: 'error'
captureUnhandledRejections: true
access_token: 'some-public-token'
capture_uncaught: true
uncaught_error_level: 'error'
capture_unhandled_rejections: true
payload:
environment: environment: '%kernel.environment%'
ignoredMessages: []
environment: '%kernel.environment%'
ignored_messages: []
verbose: false
async: true
autoInstrument:
auto_instrument:
network: true
log: true
dom: true
navigation: true
connectivity: true
itemsPerMinute: 60
maxItems: 0
scrubFields: ['passwd', 'password', 'secret', 'confirm_password', 'password_confirmation', 'auth_token', 'csrf_token']
items_per_minute: 60
max_items: 0
scrub_fields: ['passwd', 'password', 'secret', 'confirm_password', 'password_confirmation', 'auth_token', 'csrf_token']
Bundle configuration
--------------------
Expand All @@ -102,87 +110,19 @@ Here you can description of some important configuration options for RollBar.

``root``: Path to your project's root dir. Default ``%kernel.root_dir%``

``checkIgnore``: Function called before sending payload to Rollbar, return true to stop the error from being sent to Rollbar.

Use globally defined function:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
checkIgnore: 'function_name_here'
Use custom ``CheckIgnoreProvider`` class that should implements ``InterfaceCheckIgnore``:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
checkIgnore: '\SymfonyRollbarBundle\Tests\Fixtures\CheckIgnoreProvider'
Use custom ``CheckIgnoreProvider`` service that class should implements ``InterfaceCheckIgnore``:

.. code-block:: yaml
``check_ignore``: Function called before sending payload to Rollbar, `Example of check ignore`_

symfony_rollbar:
# ...
rollbar:
# ...
checkIgnore: 'awesome_app.rollbar_check_ignore_provider'
``custom_data_method``: Function creating dynamic custom data on runtime during error reporting, `Example of custom data method`_

.. _`Example of check ignore`: check_ignore.rst
.. _`Example of custom data method`: custom_data_method.rst

RollBar - Person Tracking
-------------------------
Rollbar `can track`_ which of your People (users) are affected by each error. There is one of the options:

``person_fn``: A function reference (string, etc. - anything that `call_user_func()`_ can handle) returning an array like the one for 'person'.

Use globally defined function:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
person_fn: 'function_name_here'
Use custom ``PersonProvider`` class that should implements ``InterfacePersonProvider``:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
person_fn: '\SymfonyRollbarBundle\Tests\Fixtures\PersonProvider'
Use custom ``PersonProvider`` service that class should implements ``InterfacePersonProvider``:

.. code-block:: yaml
symfony_rollbar:
# ...
rollbar:
# ...
person_fn: 'awesome_app.rollbar_person_provider'
Than in your ``PersonProvider`` class/service or function you have to return user data as array:

.. code-block:: php
// ..
return [
'id' => 'user_id',
'username' => 'username',
'email' => 'email',
];
Rollbar `can track`_ which of your People (users) are affected by each error. `Example of tracking`_

.. _`can track`: https://rollbar.com/docs/person-tracking/
.. _`call_user_func()`: http://php.net/call_user_func
.. _`Example of tracking`: person_tracking.rst

RollBarJS - Integration
-----------------------
Expand Down
Loading

0 comments on commit 2fc9c6f

Please sign in to comment.