Skip to content

Commit

Permalink
Merge pull request #18 from FranMoraton/add-retry-count
Browse files Browse the repository at this point in the history
add retry count to logger
  • Loading branch information
FranMoraton authored Nov 25, 2021
2 parents 19f71c7 + 7accbca commit 501b6b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/MessageLogger/MessageLoggerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;

final class MessageLoggerMiddleware implements MiddlewareInterface
{
Expand All @@ -26,6 +27,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
$context = [
'message' => $message,
'name' => $message::messageName(),
'retry_count' => $this->extractEnvelopeRetryCount($envelope),
];

try {
Expand All @@ -51,4 +53,11 @@ private function messageFromEnvelope(Envelope $envelope): Message
{
return $envelope->getMessage();
}

private function extractEnvelopeRetryCount(Envelope $envelope): int
{
$retryCountStamp = $envelope->last(RedeliveryStamp::class);

return null !== $retryCountStamp ? $retryCountStamp->getRetryCount() : 0;
}
}
3 changes: 3 additions & 0 deletions src/Util/Filebeat/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"message": {
"type": "text"
},
"retry_count": {
"type": "integer"
},
"name": {
"type": "text",
"fields": {
Expand Down

0 comments on commit 501b6b4

Please sign in to comment.