-
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.
- Loading branch information
1 parent
fe58a4c
commit da46b34
Showing
7 changed files
with
166 additions
and
3 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
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
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,12 @@ | ||
<?xml version="1.0" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="Frosh\SentryBundle\Subscriber\StorefrontPageSubscriber"> | ||
<argument key="$container" type="service" id="service_container" /> | ||
<argument key="$sentryOptions" type="service" id="sentry.client.options" /> | ||
<tag name="kernel.event_subscriber" /> | ||
</service> | ||
</services> | ||
</container> |
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,7 @@ | ||
{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %} | ||
|
||
{% block layout_head_javascript_feature %} | ||
{% sw_include '@ShopwareSentryBundle/storefront/sentry.html.twig' %} | ||
|
||
{{ parent() }} | ||
{% endblock %} |
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,37 @@ | ||
{% if sentry %} | ||
{% block sentry %} | ||
<script src="{{ sentry.javascript_src }}"></script> | ||
<script> | ||
Sentry.init({ | ||
dsn: '{{ sentry.dsn }}', | ||
release: '{{ sentry.release }}', | ||
environment: '{{ sentry.environment }}', | ||
integrations: [ | ||
{% if sentry.tracing.enabled -%} | ||
Sentry.browserTracingIntegration({ | ||
enableInp: true, | ||
{% block sentry_additional_configuration_tracing %}{% endblock %} | ||
...{ } | ||
}), | ||
{% endif -%} | ||
{% if sentry.replay_recording.enabled -%} | ||
Sentry.replayIntegration({ | ||
blockAllMedia: false, | ||
maskAllText: false, | ||
{% block sentry_additional_configuration_replay %}{% endblock %} | ||
...{ } | ||
}), | ||
{% endif -%} | ||
], | ||
{% if sentry.tracing.enabled -%} | ||
tracesSampleRate: {{ sentry.tracing.sample_rate }}, | ||
{% endif -%} | ||
{% if sentry.replay_recording.enabled -%} | ||
replaysSessionSampleRate: {{ sentry.replay_recording.sample_rate }}, | ||
{% endif -%} | ||
{% block sentry_additional_configuration %}{% endblock %} | ||
...{ } | ||
}); | ||
</script> | ||
{% endblock %} | ||
{% endif %} |
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
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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\SentryBundle\Subscriber; | ||
|
||
use Sentry\Options; | ||
use Shopware\Storefront\Event\StorefrontRenderEvent; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class StorefrontPageSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private readonly ContainerInterface $container, | ||
private readonly Options $sentryOptions, | ||
) {} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
StorefrontRenderEvent::class => 'onRender', | ||
]; | ||
} | ||
|
||
public function onRender(StorefrontRenderEvent $event): void | ||
{ | ||
if ($this->sentryOptions->getDsn() == null | ||
|| !$this->container->getParameter('frosh_sentry.storefront.enabled') | ||
) { | ||
return; | ||
} | ||
|
||
$jsSdkVersion = $this->container->getParameter('frosh_sentry.storefront.javascript_sdk_version'); | ||
if (!is_string($jsSdkVersion)) { | ||
return; | ||
} | ||
|
||
$isReplayRecordingEnabled = $this->container->getParameter('frosh_sentry.storefront.replay_recording.enabled'); | ||
$isPerformanceTracingEnabled = $this->container->getParameter('frosh_sentry.storefront.tracing.enabled'); | ||
|
||
if ($isReplayRecordingEnabled && $isPerformanceTracingEnabled) { | ||
$jsFile = 'bundle.tracing.replay.min.js'; | ||
} elseif ($isReplayRecordingEnabled && !$isPerformanceTracingEnabled) { | ||
$jsFile = 'bundle.replay.min.js'; | ||
} elseif (!$isReplayRecordingEnabled && $isPerformanceTracingEnabled) { | ||
$jsFile = 'bundle.tracing.min.js'; | ||
} elseif (!$isReplayRecordingEnabled && !$isPerformanceTracingEnabled) { | ||
$jsFile = 'bundle.min.js'; | ||
} else { | ||
// this case should never happen | ||
return; | ||
} | ||
|
||
$replaySample = $this->container->getParameter('frosh_sentry.storefront.replay_recording.sample_rate'); | ||
$tracingSample = $this->container->getParameter('frosh_sentry.storefront.tracing.sample_rate'); | ||
|
||
$event->setParameter('sentry', [ | ||
'dsn' => $this->sentryOptions->getDsn(), | ||
'javascript_src' => sprintf("https://browser.sentry-cdn.com/%s/%s", $jsSdkVersion, $jsFile), | ||
'replay_recording' => [ | ||
'enabled' => $isReplayRecordingEnabled, | ||
'sample_rate' => is_float($replaySample) ? $replaySample : 0.1, | ||
], | ||
'tracing' => [ | ||
'enabled' => $isPerformanceTracingEnabled, | ||
'sample_rate' => is_float($tracingSample) ? $tracingSample : 0.1, | ||
], | ||
'release' => $this->sentryOptions->getRelease(), | ||
'environment' => $this->sentryOptions->getEnvironment(), | ||
]); | ||
} | ||
} |