feat: log request ids to map xml dumps of bpn api communication
This commit is contained in:
@@ -104,4 +104,4 @@ when@prod:
|
|||||||
type: stream
|
type: stream
|
||||||
channels: [deprecation]
|
channels: [deprecation]
|
||||||
path: php://stderr
|
path: php://stderr
|
||||||
formatter: monolog.formatter.json
|
formatter: monolog.formatter.json
|
||||||
@@ -132,3 +132,8 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
$httpClient: '@typo3.client'
|
$httpClient: '@typo3.client'
|
||||||
$apiKey: 'AbcAbc123'# dummy key, not yet implemented
|
$apiKey: 'AbcAbc123'# dummy key, not yet implemented
|
||||||
|
|
||||||
|
App\Logger\RequestIdProcessor:
|
||||||
|
tags:
|
||||||
|
- { name: monolog.processor }
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use App\Form\Model\RegistrationDto;
|
|||||||
use League\Flysystem\FilesystemException;
|
use League\Flysystem\FilesystemException;
|
||||||
use League\Flysystem\FilesystemOperator;
|
use League\Flysystem\FilesystemOperator;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
@@ -55,6 +56,7 @@ class ApiClient
|
|||||||
private readonly FilesystemOperator $xmlDump,
|
private readonly FilesystemOperator $xmlDump,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private readonly BookingDataProcessor $bookingDataProcessor,
|
private readonly BookingDataProcessor $bookingDataProcessor,
|
||||||
|
private readonly RequestStack $requestStack,
|
||||||
array $options,
|
array $options,
|
||||||
) {
|
) {
|
||||||
$this->config = $this->resolveOptions($options);
|
$this->config = $this->resolveOptions($options);
|
||||||
@@ -516,7 +518,7 @@ class ApiClient
|
|||||||
*/
|
*/
|
||||||
private function doSendRawXml(string $xml, bool $debug = false): string
|
private function doSendRawXml(string $xml, bool $debug = false): string
|
||||||
{
|
{
|
||||||
$requestId = date(DATE_ATOM).uniqid();
|
$requestId = $this->getRequestId();
|
||||||
|
|
||||||
$doc = new \DOMDocument();
|
$doc = new \DOMDocument();
|
||||||
if (false === @$doc->loadXML($xml)) {
|
if (false === @$doc->loadXML($xml)) {
|
||||||
@@ -631,7 +633,7 @@ class ApiClient
|
|||||||
*/
|
*/
|
||||||
private function doSendRequest(string $type, array $data, array $additionalArgs = [], bool $debug = false): mixed
|
private function doSendRequest(string $type, array $data, array $additionalArgs = [], bool $debug = false): mixed
|
||||||
{
|
{
|
||||||
$requestId = date(DATE_ATOM).uniqid();
|
$requestId = $this->getRequestId();
|
||||||
|
|
||||||
$body = $this
|
$body = $this
|
||||||
->serializer
|
->serializer
|
||||||
@@ -685,6 +687,12 @@ class ApiClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getRequestId(): string
|
||||||
|
{
|
||||||
|
return $this->requestStack->getMainRequest()?->attributes->get('request_id')
|
||||||
|
?? date(DATE_ATOM).uniqid();
|
||||||
|
}
|
||||||
|
|
||||||
private function createKey(string $username, string $password, string $type): string
|
private function createKey(string $username, string $password, string $type): string
|
||||||
{
|
{
|
||||||
$date = (new \DateTimeImmutable())->format('Ymd');
|
$date = (new \DateTimeImmutable())->format('Ymd');
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\EventListener;
|
||||||
|
|
||||||
|
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
|
||||||
|
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||||
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
|
||||||
|
#[AsEventListener(event: KernelEvents::REQUEST, priority: 255)]
|
||||||
|
class RequestIdListener
|
||||||
|
{
|
||||||
|
public function __invoke(RequestEvent $event): void
|
||||||
|
{
|
||||||
|
if (false === $event->isMainRequest()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestId = date(DATE_ATOM).uniqid();
|
||||||
|
$event->getRequest()->attributes->set('request_id', $requestId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Logger;
|
||||||
|
|
||||||
|
use Monolog\LogRecord;
|
||||||
|
use Monolog\Processor\ProcessorInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
||||||
|
class RequestIdProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RequestStack $requestStack,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(LogRecord $record): LogRecord
|
||||||
|
{
|
||||||
|
$requestId = $this->requestStack->getMainRequest()?->attributes->get('request_id');
|
||||||
|
|
||||||
|
if (null !== $requestId) {
|
||||||
|
$record->extra['request_id'] = $requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user