Skip to content

Commit

Permalink
Merge pull request #30 from smartbooster/api_call_monitor_get_process…
Browse files Browse the repository at this point in the history
…_monitor

ApiCallMonitor::getProcessMonitor getter + start and end method adjustments
  • Loading branch information
mathieu-ducrot authored Jun 5, 2024
2 parents 2a0e49c + 92e9823 commit c6d843c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
CHANGELOG for 1.x
===================
## v1.4.2 - (2024-06-05)
### Added
- `ApiCallMonitor::getProcessMonitor` getter to access the ProcessMonitor instance through it

### Changed
- `ApiCallMonitor::start` add **$flush** param to match `ProcessMonitor::start` definition
- `ApiCallMonitor::end` use Symfony Response const instead of hard coded value for the isSuccess check, also expand the range to >= 100 and < 400

## v1.4.1 - (2024-05-29)
### Fixed
- `DateUtils::millisecondsToString` int type cast when calling **secondsToString** to fix the deprecated: Implicit conversion from float
Expand Down
13 changes: 9 additions & 4 deletions src/Monitoring/ApiCallMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Smart\CoreBundle\Monitoring;

use Smart\CoreBundle\Entity\ApiCallInterface;
use Smart\CoreBundle\Entity\ProcessInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* @author Mathieu Ducrot <[email protected]>
Expand All @@ -15,9 +15,9 @@ public function __construct(private readonly ProcessMonitor $processMonitor)
{
}

public function start(ApiCallInterface $apiCall, Request $request): ApiCallInterface
public function start(ApiCallInterface $apiCall, Request $request, bool $flush = false): ApiCallInterface
{
$this->processMonitor->start($apiCall);
$this->processMonitor->start($apiCall, $flush);
$apiCall->setMethod($request->getMethod());
$apiCall->setRouteUrl($request->getUri());
$apiCall->setType($request->attributes->get('_route'));
Expand All @@ -29,6 +29,11 @@ public function start(ApiCallInterface $apiCall, Request $request): ApiCallInter
public function end(ApiCallInterface $apiCall, int $statusCode, bool $flush = true): void
{
$apiCall->setStatusCode($statusCode);
$this->processMonitor->end($apiCall, $statusCode >= 200 && $statusCode < 300, $flush);
$this->processMonitor->end($apiCall, $statusCode >= Response::HTTP_CONTINUE && $statusCode < Response::HTTP_BAD_REQUEST, $flush);
}

public function getProcessMonitor(): ProcessMonitor
{
return $this->processMonitor;
}
}

0 comments on commit c6d843c

Please sign in to comment.