Skip to content

Commit 6f7d6cd

Browse files
authored
Merge pull request #184 from getsentry/3.0
First steps toward 3.0 and 2.0 SDK
2 parents afeec4f + 1712f84 commit 6f7d6cd

27 files changed

+1191
-1838
lines changed

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dist: trusty
55
php:
66
- 7.1
77
- 7.2
8+
- 7.3
89

910
cache:
1011
directories:
@@ -16,7 +17,7 @@ before_install:
1617
- composer global require hirak/prestissimo
1718

1819
install:
19-
- travis_retry travis_wait composer update --no-interaction --prefer-dist --prefer-stable $COMPOSER_OPTIONS
20+
- travis_retry travis_wait composer update --no-interaction --prefer-dist --prefer-stable
2021

2122
script:
2223
- vendor/bin/phpunit -v
@@ -25,7 +26,11 @@ jobs:
2526
include:
2627
- stage: Test
2728
php: 7.1
28-
env: COMPOSER_OPTIONS="--prefer-lowest"
29+
env:
30+
- DEPS=--prefer-lowest
31+
install:
32+
- travis_retry travis_wait composer install --no-interaction --prefer-dist
33+
- travis_retry travis_wait composer update --no-interaction --prefer-dist --prefer-stable --prefer-lowest
2934
- stage: Code style and static analysis
3035
script:
3136
- composer phpstan

README.md

Lines changed: 35 additions & 249 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ Symfony integration for [Sentry](https://getsentry.com/).
99
[![Scrutinizer][Master scrutinizer image]][Master scrutinizer link]
1010
[![Coverage Status][Master coverage image]][Master scrutinizer link]
1111

12+
## Notice 3.0
13+
> The current master branch contains the 3.0 version of this bundle, which is currently under development. This version
14+
> will support the newest 2.0 version of the underlying Sentry SDK version.
15+
>
16+
> A beta version will be tagged as soon as possible, in the meantime you can continue to use the previous versions.
17+
>
18+
> To know more about the progress of this version see [the relative
19+
milestone](https://github.com/getsentry/sentry-symfony/milestone/3)
20+
1221
## Benefits
1322

1423
Use sentry-symfony for:
@@ -26,17 +35,22 @@ Use sentry-symfony for:
2635
## Installation
2736

2837
### Step 1: Download the Bundle
38+
You can install this bundle using Composer. Since the Sentry SDK uses HTTPlug to remain transport-agnostic, you need to
39+
manually require two additional packages that provides [`php-http/async-client-implementation`](https://packagist.org/providers/php-http/async-client-implementation)
40+
and [`http-message-implementation`](https://packagist.org/providers/psr/http-message-implementation).
41+
42+
For example, if you want to install/upgrade using Curl as transport and the PSR-7 implementation by Guzzle, you can use:
2943

30-
Open a command console, enter your project directory and execute the
31-
following command to download the latest stable version of this bundle:
44+
```bash
45+
composer require sentry/sentry-symfony:^3.0 php-http/curl-client guzzlehttp/psr7
46+
```
3247

48+
Or, if you want to use only Guzzle 6, you can use:
3349
```bash
34-
$ composer require sentry/sentry-symfony
50+
composer require sentry/sentry-symfony:^3.0 php-http/guzzle6-adapter guzzlehttp/psr7
3551
```
3652

37-
This command requires you to have Composer installed globally, as explained
38-
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
39-
of the Composer documentation.
53+
> TODO: Flex recipe
4054
4155
### Step 2: Enable the Bundle
4256

@@ -52,20 +66,18 @@ class AppKernel extends Kernel
5266
{
5367
public function registerBundles()
5468
{
55-
$bundles = array(
69+
$bundles = [
5670
// ...
57-
);
71+
new Sentry\SentryBundle\SentryBundle(),
72+
];
5873

59-
if (in_array($this->getEnvironment(), ['staging', 'prod'], true)) {
60-
$bundles[] = new Sentry\SentryBundle\SentryBundle();
61-
}
6274
// ...
6375
}
6476

6577
// ...
6678
}
6779
```
68-
Note that, with this snippet of code, the bundle will be enabled only for the `staging` and `prod` environment; adjust it to your needs. It's discouraged to enable this bundle in the `test` environment, because the Sentry client will change the error handler, which is already used by other packages like Symfony's deprecation handler (see [#46](https://github.com/getsentry/sentry-symfony/issues/46) and [#95](https://github.com/getsentry/sentry-symfony/issues/95)).
80+
Note that, unlike before version 3, the bundle will be enabled in all environments.
6981

7082
### Step 3: Configure the SDK
7183

@@ -78,250 +90,24 @@ sentry:
7890
```
7991
8092
## Maintained versions
81-
* 2.x is actively maintained on the master branch, but it requires Symfony 3+ and PHP 7.1+;
82-
* 1.x is still supported to allow Symfony 2 and PHP 5.6/7.0; it may receive backports of features from the master branch, but it's not guaranteed
83-
* 0.8.x is no longer maintained, with the 0.8.8 release containing the latest new features; it may only receive security fixes in the future.
93+
* 3.x is actively maintained and developed on the master branch, and uses Sentry SDK 2.0;
94+
* 2.x is supported only for fixes; from this version onwards it requires Symfony 3+ and PHP 7.1+;
95+
* 1.x is no longer maintained; you can use it for Symfony < 2.8 and PHP 5.6/7.0;
96+
* 0.8.x is no longer maintained.
8497
8598
## Configuration
8699
87-
The following options can be configured via ``app/config/config.yml``.
88-
89-
### Skip some exceptions
90-
91-
```yaml
92-
sentry:
93-
skip_capture:
94-
- 'Symfony\Component\HttpKernel\Exception\HttpExceptionInterface'
95-
```
96-
97-
### Listeners' priority
98-
99-
You can change the priority of the 3 default listeners of this bundle with the `listener_priorities` key of your config.
100-
The default value is `0`, and here are the 3 possible sub-keys:
101-
102-
```yaml
103-
listener_priorities:
104-
request: 0
105-
kernel_exception: 0
106-
console_exception: 0
107-
```
108-
109-
... respectively for the `onKernelRequest`, `onKernelException` and `onConsoleException` events.
110-
111-
### Options
112-
113-
In the following section you will find some of the available options you can configure, listed alphabetically. All available options and a more detailed description of each can be found [here](https://docs.sentry.io/clients/php/config/), in the Sentry documentation.
114-
115-
#### app_path
116-
117-
The base path to your application. Used to trim prefixes and mark frames of the stack trace as part of your application.
118-
119-
```yaml
120-
sentry:
121-
options:
122-
app_path: "/path/to/myapp"
123-
```
124-
125-
#### environment
126-
127-
The environment your code is running in (e.g. production).
128-
129-
```yaml
130-
sentry:
131-
options:
132-
environment: "%kernel.environment%"
133-
```
134-
135-
#### error types
136-
137-
Define which error types should be reported.
138-
139-
```yaml
140-
sentry:
141-
options:
142-
error_types: E_ALL & ~E_DEPRECATED & ~E_NOTICE
143-
```
144-
145-
#### exception_listener
146-
147-
This is used to replace the default exception listener that this bundle uses. The value must be a FQCN of a class implementing the SentryExceptionListenerInterface interface. See [Create a Custom ExceptionListener](#create-a-custom-exceptionlistener) for more details.
148-
149-
```yaml
150-
sentry:
151-
exception_listener: AppBundle\EventListener\MySentryExceptionListener
152-
```
153-
154-
#### prefixes
155-
156-
A list of prefixes to strip from filenames. Often these would be vendor/include paths.
157-
158-
```yaml
159-
sentry:
160-
options:
161-
prefixes:
162-
- /usr/lib/include
163-
```
164-
165-
#### release
166-
167-
The version of your application. Often this is the Git SHA hash of the commit.
168-
169-
```yaml
170-
sentry:
171-
options:
172-
release: "beeee2a06521a60e646bbb8fe38702e61e4929bf"
173-
```
174-
175-
#### tags
176-
177-
Define tags for the logged errors.
178-
179-
```yaml
180-
sentry:
181-
options:
182-
tags:
183-
tag1: tagvalue
184-
tag2: tagvalue
185-
```
186-
187-
### Deprecated configuration options
188-
189-
In previous releases of this bundle, up to 0.8.2, some of the previous options where set outside of the options level of the configuration file. Those still work but are deprecated, and they will be dropped in the stable 1.x release, so **you are advised to abandon them**; to provide forward compatibility, they can still be used alongside the standard syntax, but values must match. This is a list of those options:
190-
191-
```yaml
192-
sentry:
193-
app_path: ~
194-
environment: ~
195-
error_types: ~
196-
excluded_app_paths: ~
197-
prefixes: ~
198-
release: ~
199-
```
100+
TODO
200101
201102
## Customization
202103
203-
It is possible to customize the configuration of the user context, as well as modify the client immediately before an exception is captured by wiring up an event subscriber to the events that are emitted by the default configured `ExceptionListener` (alternatively, you can also just define your own custom exception listener).
204-
205-
### Create a custom ExceptionListener
206-
207-
You can always replace the default `ExceptionListener` with your own custom listener. To do this, assign a different class to the `exception_listener` property in your Sentry configuration, e.g.:
208-
209-
```yaml
210-
sentry:
211-
exception_listener: AppBundle\EventListener\MySentryExceptionListener
212-
```
213-
214-
... and then define the custom `ExceptionListener` that implements the `SentryExceptionListenerInterface`, e.g.:
215-
216-
```php
217-
// src/AppBundle/EventSubscriber/MySentryEventListener.php
218-
namespace AppBundle\EventSubscriber;
219-
220-
use Sentry\SentryBundle\EventListener\SentryExceptionListenerInterface;
221-
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
222-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
223-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
224-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
225-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
226-
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
227-
228-
class MySentryExceptionListener implements SentryExceptionListenerInterface
229-
{
230-
// ...
231-
232-
public function __construct(TokenStorageInterface $tokenStorage = null, AuthorizationCheckerInterface $authorizationChecker = null, \Raven_Client $client = null, array $skipCapture, EventDispatcherInterface $dispatcher = null)
233-
{
234-
// ...
235-
}
236-
237-
public function onKernelRequest(GetResponseEvent $event)
238-
{
239-
// ...
240-
}
241-
242-
public function onKernelException(GetResponseForExceptionEvent $event)
243-
{
244-
// ...
245-
}
246-
247-
public function onConsoleException(ConsoleExceptionEvent $event)
248-
{
249-
// ...
250-
}
251-
}
252-
```
253-
254-
As a side note, while the above demonstrates a custom exception listener that
255-
does not extend anything you could choose to extend the default
256-
`ExceptionListener` and only override the functionality that you want to.
257-
258-
### Add an EventSubscriber for Sentry Events
259-
260-
Create a new class, e.g. `MySentryEventSubscriber`:
261-
262-
```php
263-
// src/AppBundle/EventSubscriber/MySentryEventListener.php
264-
namespace AppBundle\EventSubscriber;
265-
266-
use Sentry\SentryBundle\Event\SentryUserContextEvent;
267-
use Sentry\SentryBundle\SentrySymfonyEvents;
268-
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
269-
270-
class MySentryEventSubscriber implements EventSubscriberInterface
271-
{
272-
/** @var \Raven_Client */
273-
protected $client;
274-
275-
public function __construct(\Raven_Client $client)
276-
{
277-
$this->client = $client;
278-
}
279-
280-
public static function getSubscribedEvents()
281-
{
282-
// return the subscribed events, their methods and priorities
283-
return array(
284-
SentrySymfonyEvents::PRE_CAPTURE => 'onPreCapture',
285-
SentrySymfonyEvents::SET_USER_CONTEXT => 'onSetUserContext'
286-
);
287-
}
104+
The Sentry 2.0 SDK uses the Unified API, hence it uses the concept of `Scope`s to hold information about the current
105+
state of the app, and attach it to any event that is reported. This bundle has two listeners (`RequestListener` and
106+
`ConsoleListener`) that adds some easy default information. Those listeners normally are executed with a priority of `1`
107+
to allow easier customization with custom listener, that by default run with a lower priority of `0`.
288108

289-
public function onSetUserContext(SentryUserContextEvent $event)
290-
{
291-
// ...
292-
}
293-
294-
public function onPreCapture(Event $event)
295-
{
296-
if ($event instanceof GetResponseForExceptionEvent) {
297-
// ...
298-
}
299-
elseif ($event instanceof ConsoleExceptionEvent) {
300-
// ...
301-
}
302-
}
303-
}
304-
```
305-
306-
In the example above, if you subscribe to the `PRE_CAPTURE` event you may
307-
get an event object that caters more toward a response to a web request (e.g.
308-
`GetResponseForExceptionEvent`) or one for actions taken at the command line
309-
(e.g. `ConsoleExceptionEvent`). Depending on what and how the code was
310-
invoked, and whether or not you need to distinguish between these events
311-
during pre-capture, it might be best to test for the type of the event (as is
312-
demonstrated above) before you do any relevant processing of the object.
313-
314-
To configure the above add the following configuration to your services
315-
definitions:
316-
317-
```yaml
318-
app.my_sentry_event_subscriber:
319-
class: AppBundle\EventSubscriber\MySentryEventSubscriber
320-
arguments:
321-
- '@sentry.client'
322-
tags:
323-
- { name: kernel.event_subscriber }
324-
```
109+
Those listeners are `final` so not extendable, but you can look at those to know how to add more information to the
110+
current `Scope` and enrich you Sentry events.
325111

326112
[Last stable image]: https://poser.pugx.org/sentry/sentry-symfony/version.svg
327113
[Last unstable image]: https://poser.pugx.org/sentry/sentry-symfony/v/unstable.svg

0 commit comments

Comments
 (0)