Skip to content

Commit

Permalink
Merge pull request #22 from netlogix/feature/flag-framework-code
Browse files Browse the repository at this point in the history
Flag framework code as non in app and rewrite Flow proxy class paths
  • Loading branch information
paxuclus authored Sep 27, 2022
2 parents a5f9418 + f730213 commit 54c037c
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 11 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/functionaltests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_sqlite
ini-values: opcache.fast_shutdown=0

- name: "[1/4] Create composer project - Cache composer dependencies"
- name: "[1/5] Create composer project - Cache composer dependencies"
uses: actions/cache@v1
with:
path: ~/.composer/cache
Expand All @@ -40,14 +40,18 @@ jobs:
php-${{ matrix.php-version }}-flow-${{ matrix.flow-version }}-composer-
php-${{ matrix.php-version }}-flow-
- name: "[2/4] Create composer project - No install"
- name: "[2/5] Create composer project - No install"
run: composer create-project neos/flow-base-distribution ${{ env.FLOW_DIST_FOLDER }} --prefer-dist --no-progress --no-install "^${{ matrix.flow-version }}"

- name: "[3/4] Create composer project - Require behat in compatible version"
- name: "[3/5] Allow neos composer plugin"
run: composer config --no-plugins allow-plugins.neos/composer-plugin true
working-directory: ${{ env.FLOW_DIST_FOLDER }}

- name: "[4/5] Create composer project - Require behat in compatible version"
run: composer require --dev --no-update "neos/behat:@dev"
working-directory: ${{ env.FLOW_DIST_FOLDER }}

- name: "[4/4] Create composer project - Install project"
- name: "[5/5] Create composer project - Install project"
run: composer install
working-directory: ${{ env.FLOW_DIST_FOLDER }}

Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_sqlite
ini-values: opcache.fast_shutdown=0

- name: "[1/4] Create composer project - Cache composer dependencies"
- name: "[1/5] Create composer project - Cache composer dependencies"
uses: actions/cache@v1
with:
path: ~/.composer/cache
Expand All @@ -40,14 +40,18 @@ jobs:
php-${{ matrix.php-version }}-flow-${{ matrix.flow-version }}-composer-
php-${{ matrix.php-version }}-flow-
- name: "[2/4] Create composer project - No install"
- name: "[2/5] Create composer project - No install"
run: composer create-project neos/flow-base-distribution ${{ env.FLOW_DIST_FOLDER }} --prefer-dist --no-progress --no-install "^${{ matrix.flow-version }}"

- name: "[3/4] Create composer project - Require behat in compatible version"
- name: "[3/5] Allow neos composer plugin"
run: composer config --no-plugins allow-plugins.neos/composer-plugin true
working-directory: ${{ env.FLOW_DIST_FOLDER }}

- name: "[4/5] Create composer project - Require behat in compatible version"
run: composer require --dev --no-update "neos/behat:@dev"
working-directory: ${{ env.FLOW_DIST_FOLDER }}

- name: "[4/4] Create composer project - Install project"
- name: "[5/5] Create composer project - Install project"
run: composer install
working-directory: ${{ env.FLOW_DIST_FOLDER }}

Expand Down
80 changes: 80 additions & 0 deletions Classes/Integration/NetlogixIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\ObjectManagement\CompileTimeObjectManager;
use Neos\Utility\Files;
use Netlogix\Sentry\ExceptionHandler\ExceptionRenderingOptionsResolver;
use Netlogix\Sentry\Scope\ScopeProvider;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\Frame;
use Sentry\Integration\IntegrationInterface;
use Sentry\SentrySdk;
use Sentry\Stacktrace;
use Sentry\State\Scope;
use Sentry\UserDataBag;
use Throwable;
Expand All @@ -23,6 +26,16 @@
final class NetlogixIntegration implements IntegrationInterface
{

/**
* @var array
*/
protected static $inAppExclude;

public function __construct(array $inAppExclude)
{
self::$inAppExclude = $inAppExclude;
}

public function setupOnce(): void
{
Scope::addGlobalEventProcessor(static function (Event $event, EventHint $hint): ?Event {
Expand All @@ -49,11 +62,78 @@ public static function handleEvent(Event $event, EventHint $hint): ?Event
}
}

$rewrittenExceptions = array_map(
function ($exception) {
$stacktrace = $exception->getStacktrace();
$exception->setStacktrace(self::rewriteStacktraceAndFlagInApp($stacktrace));
return $exception;
},
$event->getExceptions()
);

$event->setExceptions($rewrittenExceptions);

self::configureScopeForEvent($event, $hint);

return $event;
}

private static function rewriteStacktraceAndFlagInApp(Stacktrace $stacktrace): Stacktrace
{
$frames = array_map(function ($frame) {
$classPathAndFilename = self::getOriginalClassPathAndFilename($frame->getFile());
return new Frame(
self::replaceProxyClassName($frame->getFunctionName()),
$classPathAndFilename,
$frame->getLine(),
self::replaceProxyClassName($frame->getRawFunctionName()),
$frame->getAbsoluteFilePath()
? Files::concatenatePaths([FLOW_PATH_ROOT, trim($classPathAndFilename, '/')])
: null,
$frame->getVars(),
self::isInApp($classPathAndFilename)
);
}, $stacktrace->getFrames());

return new Stacktrace($frames);
}

private static function getOriginalClassPathAndFilename(string $proxyClassPathAndFilename): string
{
if (!preg_match('#Flow_Object_Classes/[A-Za-z0-9_]+.php$#', $proxyClassPathAndFilename)) {
return $proxyClassPathAndFilename;
}

$absolutePathAndFilename = Files::concatenatePaths([FLOW_PATH_ROOT, trim($proxyClassPathAndFilename, '/')]);
if (
!file_exists($absolutePathAndFilename) ||
!($proxyClassFile = file_get_contents($absolutePathAndFilename))
) {
return $proxyClassPathAndFilename;
}

if (!preg_match('@# PathAndFilename: ([/A-Za-z0-9_.]+\.php)@', $proxyClassFile, $matches)) {
return $proxyClassPathAndFilename;
}

return str_replace(FLOW_PATH_ROOT, '/', str_replace('_', '/', $matches[1]));
}

private static function replaceProxyClassName(?string $className): ?string
{
return $className ? str_replace('_Original', '', $className) : null;
}

private static function isInApp(string $path): bool
{
foreach (self::$inAppExclude as $excludePath) {
if (strpos($path, $excludePath) !== false) {
return false;
}
}
return true;
}

private static function configureScopeForEvent(Event $event, EventHint $hint): void
{
try {
Expand Down
13 changes: 10 additions & 3 deletions Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ public function boot(Bootstrap $bootstrap)
ConfigurationManager::class,
'configurationManagerReady',
static function (ConfigurationManager $configurationManager) {
$dsn = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'Netlogix.Sentry.dsn');
$dsn = $configurationManager->getConfiguration(
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'Netlogix.Sentry.dsn'
);

$inAppExclude = $configurationManager->getConfiguration(
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'Netlogix.Sentry.inAppExclude'
);

init([
'dsn' => $dsn,
'integrations' => [
new NetlogixIntegration(),
new NetlogixIntegration($inAppExclude ?? []),
]
]);
}
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions Configuration/Settings.InAppExclude.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Netlogix:
Sentry:
inAppExclude:
- 'Packages/Framework/'
- 'Packages/Libraries/'

0 comments on commit 54c037c

Please sign in to comment.