Skip to content

Commit 18a35be

Browse files
authored
Symfony SDK 5.0.0 (#821)
1 parent 34997bc commit 18a35be

34 files changed

+401
-1163
lines changed

.github/workflows/static-analysis.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
composer-options: --prefer-dist
3131

3232
- name: Run script
33-
run: composer phpcs
33+
run: vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
3434

3535
phpstan:
3636
name: PHPStan
@@ -50,7 +50,7 @@ jobs:
5050
composer-options: --prefer-dist
5151

5252
- name: Run script
53-
run: composer phpstan
53+
run: vendor/bin/phpstan analyse
5454

5555
psalm:
5656
name: Psalm
@@ -70,4 +70,4 @@ jobs:
7070
composer-options: --prefer-dist
7171

7272
- name: Run script
73-
run: composer psalm -- --php-version=8.0
73+
run: vendor/bin/psalm --php-version=8.0

CHANGELOG.md

+3-460
Large diffs are not rendered by default.

Makefile

-21
This file was deleted.

README.md

+14-129
Original file line numberDiff line numberDiff line change
@@ -20,153 +20,38 @@ This is the official Symfony SDK for [Sentry](https://getsentry.com/).
2020

2121
## Getting Started
2222

23-
Using this `sentry-symfony` SDK provides you with the following benefits:
24-
25-
* Quickly integrate and configure Sentry for your Symfony app
26-
* Out of the box, each event will contain the following data by default
27-
- The currently authenticated user
28-
- The Symfony environment
29-
3023
### Install
3124

32-
To install the SDK you will need to be using [Composer]([https://getcomposer.org/)
33-
in your project. To install it please see the [docs](https://getcomposer.org/download/).
25+
Install the SDK using [Composer](https://getcomposer.org/).
3426

3527
```bash
3628
composer require sentry/sentry-symfony
3729
```
3830

39-
If you're using the [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) Composer plugin, you might encounter a message similar to this:
40-
41-
```
42-
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
43-
Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/sentry/sentry-symfony/3.0
44-
45-
Do you want to execute this recipe?
46-
```
47-
48-
Just type `y`, press return, and the procedure will continue.
49-
50-
**Caution:** Due to a bug in the [`SensioFrameworkExtra`](https://github.com/sensiolabs/SensioFrameworkExtraBundle) bundle, affecting version 6.0 and below, you might run into a missing `Nyholm\Psr7\Factory\Psr17Factory::class` error while executing the commands mentioned above.
51-
If you are not using the PSR-7 bridge, you can work around this issue by changing the configuration of the bundle as follows:
52-
53-
```yaml
54-
sensio_framework_extra:
55-
psr_message:
56-
enabled: false
57-
```
58-
59-
For more details about the issue see https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710.
60-
61-
### Enable the Bundle
62-
63-
If you installed the package using the Flex recipe, the bundle will be automatically enabled. Otherwise, enable it by adding it to the list
64-
of registered bundles in the `Kernel.php` file of your project:
65-
66-
```php
67-
class AppKernel extends \Symfony\Component\HttpKernel\Kernel
68-
{
69-
public function registerBundles(): array
70-
{
71-
return [
72-
// ...
73-
new \Sentry\SentryBundle\SentryBundle(),
74-
];
75-
}
76-
77-
// ...
78-
}
79-
```
80-
81-
The bundle will be enabled in all environments by default.
82-
To enable event reporting, you'll need to add a DSN (see the next step).
83-
8431
### Configure
8532

86-
Add the [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) of your project.
87-
If you're using Symfony 3.4, add the DSN to your `app/config/config_prod.yml` file.
88-
For Symfony 4 or newer, add the DSN to your `config/packages/sentry.yaml` file.
89-
90-
Keep in mind that by leaving the `dsn` value empty (or undeclared), you will disable Sentry's event reporting.
91-
92-
```yaml
93-
sentry:
94-
dsn: "https://public:[email protected]/1"
95-
messenger:
96-
enabled: true # flushes Sentry messages at the end of each message handling
97-
capture_soft_fails: true # captures exceptions marked for retry too
98-
options:
99-
environment: '%kernel.environment%'
100-
release: '%env(VERSION)%' #your app version
101-
```
102-
103-
The parameter `options` allows to fine-tune exceptions. To discover more options, please refer to
104-
[the Unified APIs](https://docs.sentry.io/development/sdk-dev/unified-api/#options) options and
105-
the [PHP specific](https://docs.sentry.io/platforms/php/#php-specific-options) ones.
106-
107-
#### Optional: use custom HTTP factory/transport
108-
109-
Since the SDK 2.0 uses HTTPlug to remain transport-agnostic, you need to install two packages that provide
110-
[`php-http/async-client-implementation`](https://packagist.org/providers/php-http/async-client-implementation)
111-
and [`psr/http-message-implementation`](https://packagist.org/providers/psr/http-message-implementation).
112-
113-
This bundle depends on `sentry/sdk`, which is a metapackage that already solves this need, requiring our suggested HTTP
114-
packages: the Symfony HTTP client (`symfony/http-client`) and Guzzle's message factories (`http-interop/http-factory-guzzle`).
33+
Add the [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) to your `.env` file.
11534

116-
If you want to use a different HTTP client or message factory, you can override the `sentry/sdk` package by adding the following to your `composer.json` after the `require` section:
117-
118-
```json
119-
"replace": {
120-
"sentry/sdk": "*"
121-
}
12235
```
123-
124-
For example when you want to use Guzzle's components:
125-
126-
```bash
127-
composer require php-http/guzzle6-adapter guzzlehttp/psr7
36+
###> sentry/sentry-symfony ###
37+
SENTRY_DSN="https://[email protected]/1"
38+
###< sentry/sentry-symfony ###
12839
```
12940

130-
If you don't have a compatible HTTP client and/or message factory implementation installed `php-http/discovery` will try to install it for you using a Composer plugin.
131-
132-
## Maintained versions
41+
### Usgae
13342

134-
* 4.x is actively maintained and developed on the master branch, and uses Sentry SDK 3.0;
135-
* 3.x is supported only for fixes and uses Sentry SDK 2.0;
136-
* 2.x is no longer maintained; from this version onwards it requires Symfony 3+ and PHP 7.1+;
137-
* 1.x is no longer maintained; you can use it for Symfony < 2.8 and PHP 5.6/7.0;
138-
* 0.8.x is no longer maintained.
139-
140-
### Upgrading to 4.0
141-
142-
The 4.0 version of the bundle uses the newest version (3.x) of the underlying Sentry SDK. If you need to migrate from previous versions, please check the `UPGRADE-4.0.md` document.
143-
144-
#### Custom serializers
145-
146-
The option class_serializers can be used to send customized objects serialization.
147-
```yml
148-
sentry:
149-
options:
150-
class_serializers:
151-
YourValueObject: 'ValueObjectSerializer'
152-
```
153-
154-
Several serializers can be added and the serializable check is done by using the **instanceof** type operator.
155-
The serializer must implement the `__invoke` method, which needs to return an **array**, containing the information that should be send to Sentry. The class name is always sent by default.
156-
157-
Serializer example:
15843
```php
159-
final class ValueObjectSerializer
160-
{
161-
public function __invoke(YourValueObject $vo): array
162-
{
163-
return [
164-
'value' => $vo->value()
165-
];
166-
}
44+
use function Sentry\captureException;
45+
46+
try {
47+
$this->functionThatMayFail();
48+
} catch (\Throwable $exception) {
49+
captureException($exception);
16750
}
16851
```
16952

53+
## Symfony Version Compatibility
54+
17055
## Contributing to the SDK
17156

17257
Please refer to [CONTRIBUTING.md](CONTRIBUTING.md).

composer.json

+20-34
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,15 @@
77
"license": "MIT",
88
"authors": [
99
{
10-
"name": "David Cramer",
11-
"email": "[email protected]"
12-
},
13-
{
14-
"name": "Alessandro Lai",
15-
"email": "[email protected]"
10+
"name": "Sentry",
11+
"email": "[email protected]"
1612
}
1713
],
18-
"config": {
19-
"sort-packages": true,
20-
"allow-plugins": {
21-
"composer/package-versions-deprecated": true,
22-
"phpstan/extension-installer": true,
23-
"php-http/discovery": false
24-
}
25-
},
2614
"require": {
2715
"php": "^7.2||^8.0",
28-
"guzzlehttp/psr7": "^1.7 || ^2.0",
29-
"jean85/pretty-package-versions": "^1.5 || ^2.0",
30-
"sentry/sdk": "^3.6",
31-
"sentry/sentry": "^3.22.1",
16+
"guzzlehttp/psr7": "^2.1.1",
17+
"jean85/pretty-package-versions": "^1.5||^2.0",
18+
"sentry/sentry": "^4.6.1",
3219
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
3320
"symfony/config": "^4.4.20||^5.0.11||^6.0||^7.0",
3421
"symfony/console": "^4.4.20||^5.0.11||^6.0||^7.0",
@@ -83,24 +70,23 @@
8370
}
8471
},
8572
"scripts": {
86-
"tests": [
87-
"vendor/bin/phpunit --verbose"
73+
"check": [
74+
"@cs-check",
75+
"@phpstan",
76+
"@psalm",
77+
"@tests"
8878
],
89-
"phpcs": [
90-
"vendor/bin/php-cs-fixer fix --verbose --diff --dry-run"
91-
],
92-
"phpstan": [
93-
"vendor/bin/phpstan analyse"
94-
],
95-
"psalm": [
96-
"vendor/bin/psalm"
97-
]
79+
"tests": "vendor/bin/phpunit --verbose",
80+
"cs-check": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
81+
"cs-fix": "vendor/bin/php-cs-fixer fix --verbose --diff",
82+
"phpstan": "vendor/bin/phpstan analyse",
83+
"psalm": "vendor/bin/psalm"
9884
},
99-
"extra": {
100-
"branch-alias": {
101-
"releases/3.2.x": "3.2.x-dev",
102-
"releases/2.x": "2.x-dev",
103-
"releases/1.x": "1.x-dev"
85+
"config": {
86+
"sort-packages": true,
87+
"allow-plugins": {
88+
"composer/package-versions-deprecated": true,
89+
"phpstan/extension-installer": true
10490
}
10591
}
10692
}

phpstan-baseline.neon

+17-22
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ parameters:
1515
count: 1
1616
path: src/DependencyInjection/SentryExtension.php
1717

18+
-
19+
message: "#^Cannot access offset 'before_send_check_in' on mixed\\.$#"
20+
count: 1
21+
path: src/DependencyInjection/SentryExtension.php
22+
23+
-
24+
message: "#^Cannot access offset 'before_send_metrics' on mixed\\.$#"
25+
count: 1
26+
path: src/DependencyInjection/SentryExtension.php
27+
1828
-
1929
message: "#^Cannot access offset 'before_send…' on mixed\\.$#"
2030
count: 1
@@ -45,6 +55,11 @@ parameters:
4555
count: 1
4656
path: src/DependencyInjection/SentryExtension.php
4757

58+
-
59+
message: "#^Cannot access offset 'http_client' on mixed\\.$#"
60+
count: 1
61+
path: src/DependencyInjection/SentryExtension.php
62+
4863
-
4964
message: "#^Cannot access offset 'in_app_exclude' on mixed\\.$#"
5065
count: 2
@@ -61,7 +76,7 @@ parameters:
6176
path: src/DependencyInjection/SentryExtension.php
6277

6378
-
64-
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
79+
message: "#^Cannot access offset 'transport' on mixed\\.$#"
6580
count: 1
6681
path: src/DependencyInjection/SentryExtension.php
6782

@@ -77,7 +92,7 @@ parameters:
7792

7893
-
7994
message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#"
80-
count: 6
95+
count: 9
8196
path: src/DependencyInjection/SentryExtension.php
8297

8398
-
@@ -130,11 +145,6 @@ parameters:
130145
count: 4
131146
path: src/DependencyInjection/SentryExtension.php
132147

133-
-
134-
message: "#^Parameter \\#2 \\$registerErrorListener of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureErrorListenerIntegration\\(\\) expects bool, mixed given\\.$#"
135-
count: 1
136-
path: src/DependencyInjection/SentryExtension.php
137-
138148
-
139149
message: "#^Parameter \\#2 \\$useDefaultIntegrations of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureRequestIntegration\\(\\) expects bool, mixed given\\.$#"
140150
count: 1
@@ -150,11 +160,6 @@ parameters:
150160
count: 1
151161
path: src/EventListener/AbstractTracingRequestListener.php
152162

153-
-
154-
message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\ConsoleCommandListener extends @final class Sentry\\\\SentryBundle\\\\EventListener\\\\ConsoleListener\\.$#"
155-
count: 1
156-
path: src/EventListener/ConsoleCommandListener.php
157-
158163
-
159164
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
160165
count: 1
@@ -255,11 +260,6 @@ parameters:
255260
count: 1
256261
path: tests/DependencyInjection/Fixtures/php/release_option_fallback_to_env_var.php
257262

258-
-
259-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
260-
count: 1
261-
path: tests/DependencyInjection/SentryExtensionTest.php
262-
263263
-
264264
message: "#^Cannot access offset 'dsn' on mixed\\.$#"
265265
count: 1
@@ -275,11 +275,6 @@ parameters:
275275
count: 1
276276
path: tests/DependencyInjection/SentryExtensionTest.php
277277

278-
-
279-
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
280-
count: 1
281-
path: tests/DependencyInjection/SentryExtensionTest.php
282-
283278
-
284279
message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#"
285280
count: 1

0 commit comments

Comments
 (0)