Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony SDK 5.0.0 #821

Merged
merged 24 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
composer-options: --prefer-dist

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

phpstan:
name: PHPStan
Expand All @@ -50,7 +50,7 @@ jobs:
composer-options: --prefer-dist

- name: Run script
run: composer phpstan
run: vendor/bin/phpstan analyse

psalm:
name: Psalm
Expand All @@ -70,4 +70,4 @@ jobs:
composer-options: --prefer-dist

- name: Run script
run: composer psalm -- --php-version=8.0
run: vendor/bin/psalm --php-version=8.0
463 changes: 3 additions & 460 deletions CHANGELOG.md

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions Makefile

This file was deleted.

143 changes: 14 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,153 +20,38 @@ This is the official Symfony SDK for [Sentry](https://getsentry.com/).

## Getting Started

Using this `sentry-symfony` SDK provides you with the following benefits:

* Quickly integrate and configure Sentry for your Symfony app
* Out of the box, each event will contain the following data by default
- The currently authenticated user
- The Symfony environment

### Install

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

```bash
composer require sentry/sentry-symfony
```

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:

```
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/sentry/sentry-symfony/3.0

Do you want to execute this recipe?
```

Just type `y`, press return, and the procedure will continue.

**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.
If you are not using the PSR-7 bridge, you can work around this issue by changing the configuration of the bundle as follows:

```yaml
sensio_framework_extra:
psr_message:
enabled: false
```

For more details about the issue see https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710.

### Enable the Bundle

If you installed the package using the Flex recipe, the bundle will be automatically enabled. Otherwise, enable it by adding it to the list
of registered bundles in the `Kernel.php` file of your project:

```php
class AppKernel extends \Symfony\Component\HttpKernel\Kernel
{
public function registerBundles(): array
{
return [
// ...
new \Sentry\SentryBundle\SentryBundle(),
];
}

// ...
}
```

The bundle will be enabled in all environments by default.
To enable event reporting, you'll need to add a DSN (see the next step).

### Configure

Add the [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) of your project.
If you're using Symfony 3.4, add the DSN to your `app/config/config_prod.yml` file.
For Symfony 4 or newer, add the DSN to your `config/packages/sentry.yaml` file.

Keep in mind that by leaving the `dsn` value empty (or undeclared), you will disable Sentry's event reporting.

```yaml
sentry:
dsn: "https://public:secret@sentry.example.com/1"
messenger:
enabled: true # flushes Sentry messages at the end of each message handling
capture_soft_fails: true # captures exceptions marked for retry too
options:
environment: '%kernel.environment%'
release: '%env(VERSION)%' #your app version
```

The parameter `options` allows to fine-tune exceptions. To discover more options, please refer to
[the Unified APIs](https://docs.sentry.io/development/sdk-dev/unified-api/#options) options and
the [PHP specific](https://docs.sentry.io/platforms/php/#php-specific-options) ones.

#### Optional: use custom HTTP factory/transport

Since the SDK 2.0 uses HTTPlug to remain transport-agnostic, you need to install two packages that provide
[`php-http/async-client-implementation`](https://packagist.org/providers/php-http/async-client-implementation)
and [`psr/http-message-implementation`](https://packagist.org/providers/psr/http-message-implementation).

This bundle depends on `sentry/sdk`, which is a metapackage that already solves this need, requiring our suggested HTTP
packages: the Symfony HTTP client (`symfony/http-client`) and Guzzle's message factories (`http-interop/http-factory-guzzle`).
Add the [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) to your `.env` file.

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:

```json
"replace": {
"sentry/sdk": "*"
}
```

For example when you want to use Guzzle's components:

```bash
composer require php-http/guzzle6-adapter guzzlehttp/psr7
###> sentry/sentry-symfony ###
SENTRY_DSN="https://public@sentry.example.com/1"
###< sentry/sentry-symfony ###
```

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.

## Maintained versions
### Usgae

* 4.x is actively maintained and developed on the master branch, and uses Sentry SDK 3.0;
* 3.x is supported only for fixes and uses Sentry SDK 2.0;
* 2.x is no longer maintained; from this version onwards it requires Symfony 3+ and PHP 7.1+;
* 1.x is no longer maintained; you can use it for Symfony < 2.8 and PHP 5.6/7.0;
* 0.8.x is no longer maintained.

### Upgrading to 4.0

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.

#### Custom serializers

The option class_serializers can be used to send customized objects serialization.
```yml
sentry:
options:
class_serializers:
YourValueObject: 'ValueObjectSerializer'
```

Several serializers can be added and the serializable check is done by using the **instanceof** type operator.
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.

Serializer example:
```php
final class ValueObjectSerializer
{
public function __invoke(YourValueObject $vo): array
{
return [
'value' => $vo->value()
];
}
use function Sentry\captureException;

try {
$this->functionThatMayFail();
} catch (\Throwable $exception) {
captureException($exception);
}
```

## Symfony Version Compatibility

## Contributing to the SDK

Please refer to [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
54 changes: 20 additions & 34 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,15 @@
"license": "MIT",
"authors": [
{
"name": "David Cramer",
"email": "dcramer@gmail.com"
},
{
"name": "Alessandro Lai",
"email": "alessandro.lai85@gmail.com"
"name": "Sentry",
"email": "accounts@sentry.io"
}
],
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true,
"php-http/discovery": false
}
},
"require": {
"php": "^7.2||^8.0",
"guzzlehttp/psr7": "^1.7 || ^2.0",
"jean85/pretty-package-versions": "^1.5 || ^2.0",
"sentry/sdk": "^3.6",
"sentry/sentry": "^3.22.1",
"guzzlehttp/psr7": "^2.1.1",
"jean85/pretty-package-versions": "^1.5||^2.0",
"sentry/sentry": "^4.6.1",
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
"symfony/config": "^4.4.20||^5.0.11||^6.0||^7.0",
"symfony/console": "^4.4.20||^5.0.11||^6.0||^7.0",
Expand Down Expand Up @@ -83,24 +70,23 @@
}
},
"scripts": {
"tests": [
"vendor/bin/phpunit --verbose"
"check": [
"@cs-check",
"@phpstan",
"@psalm",
"@tests"
],
"phpcs": [
"vendor/bin/php-cs-fixer fix --verbose --diff --dry-run"
],
"phpstan": [
"vendor/bin/phpstan analyse"
],
"psalm": [
"vendor/bin/psalm"
]
"tests": "vendor/bin/phpunit --verbose",
"cs-check": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"cs-fix": "vendor/bin/php-cs-fixer fix --verbose --diff",
"phpstan": "vendor/bin/phpstan analyse",
"psalm": "vendor/bin/psalm"
},
"extra": {
"branch-alias": {
"releases/3.2.x": "3.2.x-dev",
"releases/2.x": "2.x-dev",
"releases/1.x": "1.x-dev"
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true
}
}
}
39 changes: 17 additions & 22 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ parameters:
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'before_send_check_in' on mixed\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'before_send_metrics' on mixed\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'before_send…' on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -45,6 +55,11 @@ parameters:
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'http_client' on mixed\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'in_app_exclude' on mixed\\.$#"
count: 2
Expand All @@ -61,7 +76,7 @@ parameters:
path: src/DependencyInjection/SentryExtension.php

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

Expand All @@ -77,7 +92,7 @@ parameters:

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

-
Expand Down Expand Up @@ -130,11 +145,6 @@ parameters:
count: 4
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Parameter \\#2 \\$registerErrorListener of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureErrorListenerIntegration\\(\\) expects bool, mixed given\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Parameter \\#2 \\$useDefaultIntegrations of method Sentry\\\\SentryBundle\\\\DependencyInjection\\\\SentryExtension\\:\\:configureRequestIntegration\\(\\) expects bool, mixed given\\.$#"
count: 1
Expand All @@ -150,11 +160,6 @@ parameters:
count: 1
path: src/EventListener/AbstractTracingRequestListener.php

-
message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\ConsoleCommandListener extends @final class Sentry\\\\SentryBundle\\\\EventListener\\\\ConsoleListener\\.$#"
count: 1
path: src/EventListener/ConsoleCommandListener.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -255,11 +260,6 @@ parameters:
count: 1
path: tests/DependencyInjection/Fixtures/php/release_option_fallback_to_env_var.php

-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: tests/DependencyInjection/SentryExtensionTest.php

-
message: "#^Cannot access offset 'dsn' on mixed\\.$#"
count: 1
Expand All @@ -275,11 +275,6 @@ parameters:
count: 1
path: tests/DependencyInjection/SentryExtensionTest.php

-
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
count: 1
path: tests/DependencyInjection/SentryExtensionTest.php

-
message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#"
count: 1
Expand Down