Skip to content

Commit

Permalink
Merge pull request #40 from Kanti/bugfix/spatie-async-guzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Dec 11, 2023
2 parents cd64d30 + e8f7387 commit ccbe1d0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Classes/Utility/GuzzleUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ public static function getHandler(): ?Closure

// 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);

return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($sentryService, $timingUtility, $handler): PromiseInterface {
return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($handler): PromiseInterface {
try {
GeneralUtility::getContainer();
} catch (\LogicException) {
// container not found:
// than we are most likely in a subprocess (spatie/async)
// and we don't want to initialize the container here!
return $handler($request, $options);
}

$info = $request->getMethod() . ' ' . $request->getUri()->__toString();
$stop = $timingUtility->stopWatchInternal('http.client', $info);
$request = $sentryService->addSentryTraceHeaders($request, $stop);
$stop = TimingUtility::getInstance()->stopWatchInternal('http.client', $info);
$request = GeneralUtility::makeInstance(SentryService::class)->addSentryTraceHeaders($request, $stop);

$handlerPromiseCallback = static function ($responseOrException) use ($request, $stop) {
$response = null;
Expand Down

0 comments on commit ccbe1d0

Please sign in to comment.