-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add shopware exception ignoring
- Loading branch information
Showing
5 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Shopware Sentry Bundle | ||
|
||
This plugin integrates the [Sentry](https://sentry.io) error tracking service into Shopware 6. | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require frosh/sentry-bundle | ||
``` | ||
|
||
## Configuration | ||
|
||
After installation, create a `config/packages/sentry.yaml` file in your Shopware installation and add the following configuration: | ||
|
||
```yaml | ||
parameters: | ||
env(SENTRY_DSN): '' | ||
env(SENTRY_RELEASE): '' | ||
|
||
# Tells Shopware to forward traces to Sentry | ||
shopware: | ||
profiler: | ||
integrations: | ||
- Sentry | ||
|
||
sentry: | ||
dsn: "%env(SENTRY_DSN)%" | ||
tracing: | ||
enabled: true | ||
dbal: | ||
enabled: false | ||
cache: | ||
enabled: false | ||
twig: | ||
enabled: false | ||
http_client: | ||
enabled: true | ||
messenger: | ||
enabled: true | ||
options: | ||
integrations: | ||
# Use default exception ignore list of Shopware | ||
- 'Frosh\SentryBundle\Integration\UseShopwareExceptionIgnores' | ||
environment: '%kernel.environment%' | ||
release: '%env(SENTRY_RELEASE)%' | ||
# Trace 10% of requests | ||
traces_sample_rate: 0.1 | ||
sample_rate: 0.1 | ||
``` | ||
### Pictures | ||
![img](https://i.imgur.com/KUwUkxA.png) | ||
![img](https://i.imgur.com/Jm7tjqB.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Frosh\SentryBundle\CompilerPass; | ||
|
||
use Shopware\Core\Framework\DependencyInjection\CompilerPass\CompilerPassConfigTrait; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class ExceptionConfigCompilerPass implements CompilerPassInterface | ||
{ | ||
use CompilerPassConfigTrait; | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
$config = $this->getConfig($container, 'framework'); | ||
|
||
$container->setParameter('frosh_sentry.exclude_exceptions', $config['exceptions']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Frosh\SentryBundle\Integration; | ||
|
||
use Sentry\Event; | ||
use Sentry\Integration\IntegrationInterface; | ||
use Sentry\State\Scope; | ||
|
||
class UseShopwareExceptionIgnores implements IntegrationInterface | ||
{ | ||
public function __construct(private readonly array $exceptions) | ||
{ | ||
} | ||
|
||
public function setupOnce(): void | ||
{ | ||
$exceptions = $this->exceptions; | ||
|
||
Scope::addGlobalEventProcessor(function (Event $event) use($exceptions): ?Event { | ||
$eventExceptions = $event->getExceptions()[0]; | ||
|
||
if ($eventExceptions === null) { | ||
return $event; | ||
} | ||
|
||
$config = $exceptions[$eventExceptions->getType()] ?? []; | ||
|
||
if (!isset($config['log_level'])) { | ||
return $event; | ||
} | ||
|
||
if ($config['log_level'] === 'notice') { | ||
return null; | ||
} | ||
|
||
return $event; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Frosh\SentryBundle\Listener; | ||
|
||
use Sentry\State\HubInterface; | ||
use Shopware\Storefront\Framework\Routing\RequestTransformer; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
|
||
/** | ||
* This listener overwrites the URL determined by Sentry to the original URL of the request. | ||
*/ | ||
class FixRequestUrlListener | ||
{ | ||
public function __construct(private readonly HubInterface $hub) | ||
{ | ||
|
||
} | ||
|
||
public function __invoke(RequestEvent $event): void | ||
{ | ||
$span = $this->hub->getSpan(); | ||
|
||
if ($span === null) { | ||
return; | ||
} | ||
|
||
if ($span->getOp() !== 'http.server') { | ||
return; | ||
} | ||
|
||
$request = $event->getRequest(); | ||
|
||
$url = $request->attributes->get(RequestTransformer::ORIGINAL_REQUEST_URI); | ||
|
||
if ($url === null) { | ||
return; | ||
} | ||
|
||
$span->setData(['http.url' => $request->getSchemeAndHttpHost() . $url]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters