Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wodcz/nette-sentry-bridge
Bridge that adds some framework-specific context to official Sentry PHP SDK client.
https://github.com/wodcz/nette-sentry-bridge
Last synced: 2 days ago
JSON representation
Bridge that adds some framework-specific context to official Sentry PHP SDK client.
- Host: GitHub
- URL: https://github.com/wodcz/nette-sentry-bridge
- Owner: wodCZ
- Created: 2017-10-05T15:54:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T12:46:59.000Z (over 7 years ago)
- Last Synced: 2024-12-02T11:30:12.159Z (2 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nette-sentry-bridge
Bridge that adds some framework-specific context to official Sentry PHP SDK client.
## Installation and usage
### Installation via composer:
```bash
composer require wodcz/nette-sentry-bridge
```### Usage
This is not usual extension that you would register in `extensions:` section of your config.neon.
In my opinion that is too late (something bad can happen before DIC is initialized).
Because of this, setup is a bit different.#### `app/bootstrap.php`:
```php
setDebugMode('23.75.345.200'); // enable for your remote IP
$configurator->enableTracy(__DIR__ . '/../log');
$configurator->setTimeZone('Europe/Prague');
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
->addDirectory(__DIR__)
->register();
$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');####################################### PART 1 #######################################
# Try to load configuration from app/config/sentry.php file
if(is_array($config = (@include __DIR__ . '/config/sentry.php')) && @$config['dsn']){
$logger = new \wodCZ\NetteSentryBridge\SentryLogger($config['dsn'], @$config['options'] ?: []);
}
####################################### PART 1 #######################################$container = $configurator->createContainer();
####################################### PART 2 #######################################
# Add container instance to logger, so it can pull some info from there.
if (isset($logger)) {
$logger->setContainer($container);
}
####################################### PART 2 #######################################return $container;
```Then, create `app/config/sentry.php` with following configuration:
#### `app/config/sentry.php`:
```php
'http://key:[email protected]/123',
'options' => [
'app_path' => __DIR__.'/../',
'environment' => 'production',
'exclude' => [
'Nette\Application\BadRequestException',
'Nette\Application\ForbiddenRequestException',
'Nette\Application\AbortException'
],
# 'revision' => '',
# all options: https://docs.sentry.io/clients/php/config/
]
];
```Alternative configuration if you use docker or other setup that uses environment variables. If you don't specify dsn
variable, extension will silently do nothing.#### `app/config/sentry.php`:
```php
getenv('SENTRY_DSN'),
'options' => [
'app_path' => __DIR__.'/../',
'environment' => getenv('DEBUG') === 'true' ? 'development' : 'production',
'exclude' => [
'Nette\Application\BadRequestException',
'Nette\Application\ForbiddenRequestException',
'Nette\Application\AbortException'
],
# 'revision' => '',
# all options: https://docs.sentry.io/clients/php/config/
]
];
```This is just a sample, all you need to do is to create instance of `\wodCZ\NetteSentryBridge\SentryLogger`
to start logging, and call `$logger->setContainer($container)` to extend logs with Nette Context
**and to log errors caught by Nette\Application**### Important note to prevent confusion
Extension will not log anything if you have tracy enabled.