Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	phpstan-baseline.neon
#	src/EventListener/ConsoleCommandListener.php
#	tests/DependencyInjection/SentryExtensionTest.php
#	tests/EventListener/ConsoleCommandListenerTest.php
  • Loading branch information
ste93cry committed Mar 3, 2021
2 parents 8f7a737 + 32fce0e commit 187d364
Show file tree
Hide file tree
Showing 29 changed files with 326 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .craft.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
minVersion: '0.9.0'
minVersion: 0.9.0
github:
owner: getsentry
repo: sentry-symfony
changelogPolicy: simple
statusProvider:
statusProvider:
name: github
artifactProvider:
name: none
Expand Down
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.md]
max_line_length = 80

[*.{yml, yaml}]
indent_size = 2

[COMMIT_EDITMSG]
max_line_length = 0
29 changes: 29 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Prepare Release

on:
workflow_dispatch:
inputs:
version:
description: Version to release
required: true
force:
description: Force a release even when there are release-blockers (optional)
required: false

jobs:
release:
runs-on: ubuntu-latest
name: Release version
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.GH_RELEASE_PAT }}
fetch-depth: 0

- name: Prepare release
uses: getsentry/action-prepare-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }}
with:
version: ${{ github.event.inputs.version }}
force: ${{ github.event.inputs.force }}
1 change: 1 addition & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
- develop
- 3.5.x

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
- develop
- 3.5.x

jobs:
Expand Down Expand Up @@ -44,6 +45,8 @@ jobs:
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
Expand Down
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
- Added missing `capture-soft-fails` config schema option (#417)
- Deprecate the `Sentry\SentryBundle\EventListener\ConsoleCommandListener` class in favor of its parent class `Sentry\SentryBundle\EventListener\ConsoleListener` (#429)

## 4.0.3 (2021-03-03)
- Fix regression from #454 for `null` value on DSN not disabling Sentry (#457)

## 4.0.2 (2021-03-03)

- Add `kernel.project_dir` to `prefixes` default value to trim paths to the project root (#434)
- Fix `null`, `false` or empty value not disabling Sentry (#454)

## 4.0.1 (2021-01-26)

- Add missing `capture-soft-fails` option to the XSD schema for the XML config (#417)
- Fix regression that send PII even when the `send_default_pii` option is off (#425)
- Fix capture of console errors when the `register_error_listener` option is disabled (#427)

## 4.0.0 (2021-01-19)

**Breaking Change**: This version uses the [envelope endpoint](https://develop.sentry.dev/sdk/envelopes/). If you are
Expand Down Expand Up @@ -38,7 +52,7 @@ using an on-premise installation it requires Sentry version `>= v20.6.0` to work

- Use `jean85/pretty-package-versions` `^1.5` to leverage the new `getRootPackageVersion` method (c8799ac)
- Fix support for PHP preloading (#354, thanks to @annuh)
- Fix `capture_soft_fails: false` option for the Messenger (#353)
- Fix `capture_soft_fails: false` option for the Messenger (#353)

## 3.5.1 (2020-05-07)

Expand Down
88 changes: 28 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,58 @@ Use `sentry-symfony` for:
- app path
- excluded paths (cache and vendor)

## Installation with Symfony Flex (Symfony 4 or newer):
If you're using the [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) Composer plugin, you can install this bundle in a single, easy step:
## Installation

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/).

```bash
composer require sentry/sentry-symfony
```
This could show a message similar to this:

If you're using the [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) Composer plugin, it could show 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
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?
Do you want to execute this recipe?
```
Press `y` and return to allow the installation.

## Installation without Symfony Flex:
### Step 1: Download the Bundle
You can install this bundle using Composer:
Just type `y`, press return, and the procedure will continue.

```bash
composer require sentry/sentry-symfony
**Warning:** due to a bug in all versions lower than `6.0` of the [`SensioFrameworkExtra`](https://github.com/sensiolabs/SensioFrameworkExtraBundle) bundle,
if you have it installed you will likely get an error during the execution of the commands above in regards to the missing `Nyholm\Psr7\Factory\Psr17Factory`
class. To workaround the issue, if you are not using the PSR-7 bridge, please change the configuration of that 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.

### Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles
in the `app/AppKernel.php` file of your project:
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
<?php
// app/AppKernel.php

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

// ...
}

// ...
}
```

Note that, unlike before in version 3, the bundle will be enabled in all environments; event reporting, instead, is enabled
only when providing a DSN (see the next step).

Expand All @@ -92,43 +97,6 @@ The parameter `options` allows to fine-tune exceptions. To discover more options
[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 monolog handler provided by `sentry/sentry` (available since 3.2.0)
*Note: this step is optional*

If you're using `monolog` for logging e.g. in-app errors, you
can use this handler in order for them to show up in Sentry.

First, enable & configure the `Sentry\Monolog\Handler`; you'll also need
to disable the `Sentry\SentryBundle\EventListener\ErrorListener` to
avoid having duplicate events in Sentry:

```yaml
sentry:
register_error_listener: false # Disables the ErrorListener
monolog:
error_handler:
enabled: true
level: error
```

Then enable it in `monolog` config:

```yaml
monolog:
handlers:
sentry:
type: service
id: Sentry\Monolog\Handler
```

Additionally, you can register the `PsrLogMessageProcessor` to resolve PSR-3 placeholders in reported messages:

```yaml
services:
Monolog\Processor\PsrLogMessageProcessor:
tags: { name: monolog.processor, handler: sentry }
```

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

Since SDK 2.0 uses HTTPlug to remain transport-agnostic, you need to have installed two packages that provides
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ using an on-premise installation it requires Sentry version `>= v20.6.0` to work
```yaml
sentry:
options:
before_send: 'app.sentry.before_breadcrumb'
before_breadcrumb: 'app.sentry.before_breadcrumb'
```

- Changed the type of the `sentry.options.class_serializers` configuration option from an array of `scalar` values to an array of `string` values. The value must always be the name of the container service to call without the `@` prefix.
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ parameters:

-
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 6
count: 8
path: tests/EventListener/RequestListenerTest.php

-
Expand Down
14 changes: 2 additions & 12 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.3.0@6f916553a8de3c5c2483162b6cc01b21b24e4d1d">
<files psalm-version="4.6.1@e93e532e4eaad6d68c4d7b606853800eaceccc72">
<file src="src/EventListener/ConsoleCommandListener.php">
<InvalidExtendClass occurrences="1">
<code>ConsoleListener</code>
</InvalidExtendClass>
<MethodSignatureMismatch occurrences="1">
<code>public function __construct(HubInterface $hub)</code>
</MethodSignatureMismatch>
</file>
<file src="src/Tracing/Doctrine/DBAL/TracingDriver.php">
<TooManyArguments occurrences="1">
<code>getSchemaManager</code>
</TooManyArguments>
<UndefinedClass occurrences="1">
<code>ExceptionConverter</code>
</UndefinedClass>
<MethodSignatureMismatch occurrences="1"/>
</file>
</files>
8 changes: 2 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode
->children()
->scalarNode('dsn')
->beforeNormalization()
->ifTrue(static function ($value): bool {
return empty($value) || (\is_string($value) && '' === trim($value));
})
->thenUnset()
->end()
->info('If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.')
->end()
->booleanNode('register_error_listener')->defaultTrue()->end()
->arrayNode('options')
Expand All @@ -51,6 +46,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('default_integrations')->end()
->integerNode('send_attempts')->min(0)->end()
->arrayNode('prefixes')
->defaultValue(array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))))
->scalarPrototype()->end()
->end()
->floatNode('sample_rate')
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sentry\Integration\RequestFetcherInterface;
use Sentry\Integration\RequestIntegration;
use Sentry\Options;
use Sentry\SentryBundle\EventListener\ConsoleListener;
use Sentry\SentryBundle\EventListener\ErrorListener;
use Sentry\SentryBundle\EventListener\MessengerListener;
use Sentry\SentryBundle\SentryBundle;
Expand Down Expand Up @@ -73,7 +74,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
{
$options = $config['options'];

if (isset($config['dsn'])) {
if (\array_key_exists('dsn', $config)) {
$options['dsn'] = $config['dsn'];
}

Expand Down Expand Up @@ -140,6 +141,8 @@ private function registerErrorListenerConfiguration(ContainerBuilder $container,
if (!$config['register_error_listener']) {
$container->removeDefinition(ErrorListener::class);
}

$container->getDefinition(ConsoleListener::class)->setArgument(1, $config['register_error_listener']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/ConsoleCommandListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
final class ConsoleCommandListener extends ConsoleListener
{
public function __construct(HubInterface $hub)
public function __construct(HubInterface $hub, bool $captureErrors = true)
{
parent::__construct($hub);
parent::__construct($hub, $captureErrors);

@trigger_error(sprintf('The "%s" class is deprecated since version 4.1 and will be removed in 5.0. Use "%s" instead.', self::class, ConsoleListener::class), \E_USER_DEPRECATED);
}
Expand Down
15 changes: 12 additions & 3 deletions src/EventListener/ConsoleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ class ConsoleListener
*/
private $hub;

/**
* @var bool Whether to capture console errors
*/
private $captureErrors;

/**
* Constructor.
*
* @param HubInterface $hub The current hub
* @param HubInterface $hub The current hub
* @param bool $captureErrors Whether to capture console errors
*/
public function __construct(HubInterface $hub)
public function __construct(HubInterface $hub, bool $captureErrors = true)
{
$this->hub = $hub;
$this->captureErrors = $captureErrors;
}

/**
Expand Down Expand Up @@ -68,7 +75,9 @@ public function handleConsoleErrorEvent(ConsoleErrorEvent $event): void
$this->hub->configureScope(function (Scope $scope) use ($event): void {
$scope->setTag('console.command.exit_code', (string) $event->getExitCode());

$this->hub->captureException($event->getError());
if ($this->captureErrors) {
$this->hub->captureException($event->getError());
}
});
}
}
6 changes: 6 additions & 0 deletions src/EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
return;
}

$client = $this->hub->getClient();

if (null === $client || !$client->getOptions()->shouldSendDefaultPii()) {
return;
}

$token = null;
$userData = UserDataBag::createFromUserIpAddress($event->getRequest()->getClientIp());

Expand Down
Loading

0 comments on commit 187d364

Please sign in to comment.