Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ frosh_sentry:
storefront:
# optional: if you want track errors occurs within the browser (javascript/cors/csp)
enabled: true
# optional: if you want track errors only on specific urls/hosts
allowUrls:
- '"https://example.com"'
- /https?:\/\/((cdn|www)\.)?example\.com/
# optional: if you want to ignore errors for specific urls/hosts
denyUrls:
- '"https://example.com"'
- /https?:\/\/((cdn|www)\.)?example\.com/
# optional: if you want record the user sessions. Please aware the GDPR.
replay_recording:
enabled: true
Expand Down
8 changes: 7 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

class Configuration implements ConfigurationInterface
{
Expand All @@ -16,13 +15,20 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode = $treeBuilder->getRootNode();

// @formatter:off
/** @phpstan-ignore class.notFound */

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you fine with this, or is there a better way to fix it? i got the following error and it seems like phpstan doesnt quite get the symfony config builder structure?!

  19     Call to method booleanNode() on an unknown class Symfony\Component\Config\Definition\Builder\NodeBuilder<Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition>.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols

$rootNode
->children()
->booleanNode('report_scheduled_tasks')->defaultFalse()->end()
->arrayNode('storefront')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->arrayNode('allowUrls')
->scalarPrototype()->end()
->end()
->arrayNode('denyUrls')
->scalarPrototype()->end()
->end()
->arrayNode('replay_recording')
->addDefaultsIfNotSet()
->children()
Expand Down
6 changes: 4 additions & 2 deletions src/DependencyInjection/FroshSentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FroshSentryExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container): void
{
/** @var array{report_scheduled_tasks: bool, storefront?: array{enabled: bool, javascript_sdk_version: string, replay_recording?: array{enabled: bool, sample_rate: float}, tracing?: array{enabled: bool, sample_rate: float}}} $config */
/** @var array{report_scheduled_tasks: bool, storefront?: array{enabled: bool, javascript_sdk_version: string, allowUrls?: array{string}, denyUrls?: array{string}, replay_recording?: array{enabled: bool, sample_rate: float}, tracing?: array{enabled: bool, sample_rate: float}}} $config */
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);

$container->setParameter('frosh_sentry.report_scheduled_tasks', $config['report_scheduled_tasks']);
Expand All @@ -35,7 +35,7 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co
}

/**
* @param array{enabled?: bool, javascript_sdk_version?: string, replay_recording?: array{enabled?: bool, sample_rate?: float}, tracing?: array{enabled?: bool, sample_rate?: float}} $config
* @param array{enabled?: bool, javascript_sdk_version?: string, allowUrls?: array{string}, denyUrls?: array{string}, replay_recording?: array{enabled?: bool, sample_rate?: float}, tracing?: array{enabled?: bool, sample_rate?: float}} $config
*/
private function registerStorefrontConfiguration(array $config, ContainerBuilder $container): void
{
Expand All @@ -52,6 +52,8 @@ private function registerStorefrontConfiguration(array $config, ContainerBuilder
$config['replay_recording']['sample_rate'] ?? 0.1,
$config['tracing']['enabled'] ?? false,
$config['tracing']['sample_rate'] ?? 0.1,
$config['allowUrls'] ?? [],
$config['denyUrls'] ?? [],
])
->addTag('kernel.event_subscriber');
}
Expand Down
14 changes: 14 additions & 0 deletions src/Resources/views/storefront/sentry.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
dsn: '{{ sentry.dsn }}',
release: '{{ sentry.release }}',
environment: '{{ sentry.environment }}',
{% if sentry.allowUrls -%}
allowUrls: [
{% for url in sentry.allowUrls -%}
{{ url|raw }},
{% endfor -%}
],
{% endif -%}
{% if sentry.denyUrls -%}
denyUrls: [
{% for url in sentry.denyUrls -%}
{{ url|raw }},
{% endfor -%}
],
{% endif -%}
integrations: [
{% if sentry.tracing.enabled -%}
Sentry.browserTracingIntegration({
Expand Down
6 changes: 6 additions & 0 deletions src/Subscriber/StorefrontPageSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function __construct(
private readonly float $replayRecordingSampleRate,
private readonly bool $tracingEnabled,
private readonly float $tracingSampleRate,
/** @var array{string} */
private readonly array $allowUrls,
/** @var array{string} */
private readonly array $denyUrls,
) {}

public static function getSubscribedEvents(): array
Expand Down Expand Up @@ -53,6 +57,8 @@ public function onRender(StorefrontRenderEvent $event): void
'enabled' => $this->tracingEnabled,
'sample_rate' => $this->tracingSampleRate,
],
'allowUrls' => $this->allowUrls,
'denyUrls' => $this->denyUrls,
'release' => $this->sentryOptions->getRelease(),
'environment' => $this->sentryOptions->getEnvironment(),
]);
Expand Down