Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions Block/SentryScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ public function __construct(
*/
public function canUseScriptTag($blockName)
{
if (!$this->dataHelper->isActive()) {
if (!$this->dataHelper->isActive() || !$this->dataHelper->showScriptTagInThisBlock($blockName)) {
return false;
}

if ($this->dataHelper->useScriptTag() && $this->dataHelper->showScriptTagInThisBlock($blockName)) {
if ($this->useScriptTag()) {
return true;
}

if ($this->dataHelper->useSessionReplay()) {
if ($this->useSessionReplay()) {
return true;
}

if ($this->isSpotlightEnabled()) {
return true;
}

Expand All @@ -61,7 +65,7 @@ public function canUseScriptTag($blockName)
*/
public function getDSN()
{
return $this->dataHelper->getDSN();
return (string) $this->dataHelper->getDSN();
}

/**
Expand Down Expand Up @@ -94,6 +98,14 @@ public function getEnvironment()
return $this->dataHelper->getEnvironment();
}

/**
* Whether to enable sentry js tracking.
*/
public function useScriptTag(): bool
{
return $this->dataHelper->useScriptTag();
}

/**
* Whether to enable session replay.
*/
Expand Down Expand Up @@ -202,6 +214,14 @@ public function isTracingEnabled(): bool
return $this->dataHelper->isTracingEnabled();
}

/**
* Whether spotlight is enabled.
*/
public function isSpotlightEnabled(): bool
{
return $this->dataHelper->isSpotlightEnabled();
}

/**
* Get sample rate for tracing.
*/
Expand Down
17 changes: 15 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Data extends AbstractHelper
'http_proxy' => ['type' => 'string'],
'http_connect_timeout' => ['type' => 'int'],
'http_timeout' => ['type' => 'int'],
// https://spotlightjs.com/
'spotlight' => ['type' => 'bool'],
'spotlight_url' => ['type' => 'string'],
];

/**
Expand Down Expand Up @@ -144,6 +147,16 @@ public function isTracingEnabled(): bool
return $this->collectModuleConfig()['tracing_enabled'] ?? false;
}

/**
* Whether spotlight is enabled.
*
* Enabling spotlight will implicitly enable override production mode.
*/
public function isSpotlightEnabled(): bool
{
return ($this->collectModuleConfig()['spotlight'] ?? false) && !$this->isProductionMode();
}

/**
* Get sample rate for tracing.
*/
Expand Down Expand Up @@ -320,7 +333,7 @@ public function isActiveWithReason(): array
if (!$configEnabled) {
$reasons[] = __('Module is not enabled in config.');
}
if (!$dsnNotEmpty) {
if (!$dsnNotEmpty && !$this->isSpotlightEnabled()) {
$reasons[] = __('DSN is empty.');
}
if (!$productionMode) {
Expand Down Expand Up @@ -359,7 +372,7 @@ public function isOverwriteProductionMode(): bool
{
$config = $this->collectModuleConfig();

return isset($config['mage_mode_development']) && $config['mage_mode_development'];
return (isset($config['mage_mode_development']) && $config['mage_mode_development']) || $this->isSpotlightEnabled();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions Model/Collector/SentryRelatedCspCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function collect(array $defaultPolicies = []): array
);
}

if ($this->dataHelper->isSpotlightEnabled()) {
$policies[] = new FetchPolicy(
'script-src',
false,
['https://unpkg.com/@spotlightjs/']
);
}

if ($this->dataHelper->useLogrocket()) {
$policies[] = new FetchPolicy(
'script-src',
Expand Down
1 change: 1 addition & 0 deletions Plugin/GlobalExceptionCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function prepareConfig(): DataObject
$config = $this->dataObjectFactory->create();
$config->setData(array_intersect_key($this->sentryHelper->collectModuleConfig(), SentryHelper::NATIVE_SENTRY_CONFIG_KEYS));

$config->setSpotlight($this->sentryHelper->isSpotlightEnabled());
$config->setDsn($this->sentryHelper->getDSN());
if ($release = $this->releaseIdentifier->getReleaseId()) {
$config->setRelease((string) $release);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Next to that there are some configuration options under Stores > Configuration >
| `disable_default_integrations` | `[]` | Provide a list of FQCN of default integrations you do not want to use. [List of default integrations](https://github.com/getsentry/sentry-php/tree/master/src/Integration).|
| `cron_monitoring_enabled` | `false` | Wether to enable [cron check ins](https://docs.sentry.io/platforms/php/crons/#upserting-cron-monitors) |
| `track_crons` | `[]` | Cron handles of crons to track with cron monitoring, [Sentry only supports 6 check-ins per minute](https://docs.sentry.io/platforms/php/crons/#rate-limits) Magento does many more. |
| `spotlight` | `false` | Enable [Spotlight](https://spotlightjs.com/) on the page |
| `spotlight_url` | - | Override the [Sidecar url](https://spotlightjs.com/sidecar/) |

### Configuration for Adobe Cloud
Since Adobe Cloud doesn't allow you to add manually add content to the `env.php` file, the configuration can be done
Expand Down
46 changes: 26 additions & 20 deletions view/frontend/templates/script/sentry.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
if (!$block->canUseScriptTag($block->getNameInLayout())) {
return;
}
?>

$bundleFile = 'bundle';

if ($block->isTracingEnabled()) {
$bundleFile .= '.tracing';
}

if ($block->useSessionReplay()) {
$bundleFile .= '.replay';
}
<?php if ($this->useScriptTag()): ?>
<?php
$bundleFile = 'bundle';

$bundleFile .= '.min.js';
if ($block->isTracingEnabled()) {
$bundleFile .= '.tracing';
}

$remoteFile = sprintf(
'https://browser.sentry-cdn.com/%s/%s',
$escaper->escapeHtmlAttr($block->getJsSdkVersion()),
$bundleFile
);
?>
if ($block->useSessionReplay()) {
$bundleFile .= '.replay';
}

<?= /* @noEscape */ $secureRenderer->renderTag('script', ['src' => $remoteFile, 'crossorigin' => 'anonymous']) ?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $block->getLayout()->createBlock(\JustBetter\Sentry\Block\SentryScript::class)
->setTemplate('JustBetter_Sentry::script/sentry_init.phtml')
->toHtml(), false); ?>
$bundleFile .= '.min.js';

$remoteFile = sprintf(
'https://browser.sentry-cdn.com/%s/%s',
$escaper->escapeHtmlAttr($block->getJsSdkVersion()),
$bundleFile
);
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['src' => $remoteFile, 'crossorigin' => 'anonymous']) ?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $block->getLayout()->createBlock(\JustBetter\Sentry\Block\SentryScript::class)
->setTemplate('JustBetter_Sentry::script/sentry_init.phtml')
->toHtml(), false); ?>
<?php endif; ?>
<?php if ($block->useLogRocket()): ?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['src' => 'https://cdn.lr-ingest.io/LogRocket.min.js', 'crossorigin' => 'anonymous']) ?>
<?= /* @noEscape */ $secureRenderer->renderTag(
Expand All @@ -52,3 +54,7 @@ $remoteFile = sprintf(
->setTemplate('JustBetter_Sentry::script/logrocket_init.phtml')
->toHtml(), false); ?>
<?php endif; ?>

<?php if ($block->isSpotlightEnabled()): ?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['src' => 'https://unpkg.com/@spotlightjs/overlay@latest/dist/sentry-spotlight.iife.js', 'crossorigin' => 'anonymous']) ?>
<?php endif; ?>