Skip to content

Commit

Permalink
🐛 fix compatibility with spatie/async and staticfilecache
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti committed Sep 12, 2023
1 parent 529a15d commit 763634e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Classes/EventListener/BootCompletedEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __invoke(BootCompletedEvent $event): void
{
// we initialize TimingUtility here
// in the install tool, (eg. DB compare)
// at this point, the TimingUtility is found in the container, but at the shutdown state the TimingUtility is not found in the conatiner.
// at this point, the TimingUtility is found in the container, but at the shutdown state the TimingUtility is not found in the container.
// so if we initialize it right here and save it inside a static variable, then everything works as expected. (not the sentry part :/ )
TimingUtility::getInstance();
SqlLoggerCore11::registerSqlLogger();
Expand Down
11 changes: 8 additions & 3 deletions Classes/Utility/GuzzleUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ public static function getHandler(): ?Closure
return null;
}

return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($handler): PromiseInterface {
// initialize early: so the spatie/async with staticfilecache doesn't kill the process
// there is the problem that it has a subprocess where the Container is not initialized fully
$timingUtility = TimingUtility::getInstance();
$sentryService = GeneralUtility::makeInstance(SentryService::class);

Check warning on line 27 in Classes/Utility/GuzzleUtility.php

View check run for this annotation

Codecov / codecov/patch

Classes/Utility/GuzzleUtility.php#L26-L27

Added lines #L26 - L27 were not covered by tests

return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($sentryService, $timingUtility, $handler): PromiseInterface {

Check warning on line 29 in Classes/Utility/GuzzleUtility.php

View check run for this annotation

Codecov / codecov/patch

Classes/Utility/GuzzleUtility.php#L29

Added line #L29 was not covered by tests
$info = $request->getMethod() . ' ' . $request->getUri()->__toString();
$stop = TimingUtility::stopWatch('http.client', $info);
$request = GeneralUtility::makeInstance(SentryService::class)->addSentryTraceHeaders($request, $stop);
$stop = $timingUtility->stopWatchInternal('http.client', $info);
$request = $sentryService->addSentryTraceHeaders($request, $stop);

Check warning on line 32 in Classes/Utility/GuzzleUtility.php

View check run for this annotation

Codecov / codecov/patch

Classes/Utility/GuzzleUtility.php#L31-L32

Added lines #L31 - L32 were not covered by tests

$handlerPromiseCallback = static function ($responseOrException) use ($request, $stop) {
$response = null;
Expand Down
1 change: 1 addition & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- '../Classes/{Dto,SqlLogging}/*'
- '../Classes/*/WrapMiddleware.php'
- '../Classes/*/XClassMiddlewareDispatcher.php'

Kanti\ServerTiming\Service\RegisterShutdownFunction\RegisterShutdownFunctionInterface:
class: Kanti\ServerTiming\Service\RegisterShutdownFunction\RegisterShutdownFunction

Expand Down

0 comments on commit 763634e

Please sign in to comment.