22
33Symfony bundle for Messenger lifecycle logging, suitable for monitoring.
44
5+ ## Overview
6+
7+ This bundle subscribes to Symfony Messenger lifecycle events and emits
8+ structured logs that are easy to correlate in monitoring and debugging tools.
9+
10+ ### What It Adds
11+
12+ - A UUIDv7 is assigned when a message is queued.
13+ - The same UUID is reused across queueing, receiving, handling, failures, and retries.
14+ - Each log entry includes the message class and a normalized ` stamps ` array.
15+ - Transport metadata such as receiver names, retry counts, and failure-transport
16+ details are included when available.
17+
18+ ### Supported Lifecycle Events
19+
20+ The bundle logs queueing, receiving, success, failure, and retry events. If the
21+ installed Messenger version supports ` WorkerMessageSkipEvent ` , skipped messages
22+ are logged as well.
23+
524## Installation
625
26+ ### Package Installation
27+
728``` bash
829composer require ckrack/messenger-logging-bundle
930```
1031
32+ ### Bundle Registration
33+
1134If you are not using Symfony Flex, register the bundle manually in
1235` config/bundles.php ` .
1336
37+ ### Supported Versions
38+
1439The bundle targets Symfony ` 6.4 ` , ` 7.4 ` , and ` 8.0 ` .
1540
1641## Configuration
1742
43+ ### Basic Configuration
44+
1845``` yaml
19- c10k_messenger_logging :
46+ ckrack_messenger_logging :
2047 enabled : true
2148 log_channel : messenger
2249 log_levels :
@@ -26,49 +53,56 @@ c10k_messenger_logging:
2653 failed : error
2754 retried : warning
2855 skipped : warning
29- stamp_normalizers : { }
56+ stamp_normalizers : {}
3057` ` `
3158
59+ ### Log Levels
60+
3261All PSR-3 log levels are supported. If failure logs are too noisy in a
3362retry-heavy environment, you can set ` failed: info`.
3463
64+ # ## Dedicated Log Channel
65+
3566If `log_channel` is set, only the logs emitted by this bundle are sent to that
3667Monolog channel. Other project logs remain unaffected unless they are
3768explicitly configured to use the same channel. Without `log_channel`, the
3869default logger behavior remains unchanged.
3970
40- The bundle subscribes to Messenger events and ensures that each message
41- receives a UUIDv7 when it is queued. The same UUID then appears in the logs for
42- queueing, receiving, success, failure, and retry, together with the message
43- class and a normalized `stamps` array.
71+ # # Stamp Normalization
72+
73+ # ## Default Behavior
74+
75+ The bundle normalizes a safe subset of Messenger stamp data and includes it in
76+ the `stamps` field of each log entry. Built-in normalizers cover
77+ ` BusNameStamp` , `DelayStamp`, `HandledStamp`, `RedeliveryStamp`,
78+ ` RouterContextStamp` , `SentStamp`, `TransportNamesStamp`, and
79+ ` ValidationStamp` .
4480
45- Stamp normalization is explicit. The bundle ships dedicated normalizers for a
46- safe subset of Messenger stamps such as `BusNameStamp`, `DelayStamp`,
47- ` HandledStamp` , `RedeliveryStamp`, `RouterContextStamp`, `SentStamp`,
48- ` TransportNamesStamp` , and `ValidationStamp`. Unknown stamps are still listed
49- by class name, but their `context` remains empty unless a normalizer is
50- registered for them. This avoids reflecting every public getter on every stamp,
51- which can expose sensitive data or large payloads such as handler results.
81+ Unknown stamps are still listed by class name, but their `context` remains
82+ empty unless a normalizer is registered for them. This avoids reflecting every
83+ public getter on every stamp, which can expose sensitive data or large payloads
84+ such as handler results.
85+
86+ # ## Custom Normalizers
5287
5388Custom normalizers are discovered automatically when they implement
5489` C10k\M essengerLoggingBundle\L ogging\S tampNormalizerInterface` and are
5590registered as autoconfigured services. The bundle tags them with
56- ` c10k_messenger_logging .stamp_normalizer` and maps them by supported stamp
91+ ` ckrack_messenger_logging .stamp_normalizer` and maps them by supported stamp
5792class.
5893
5994You can also wire an explicit `StampClass -> NormalizerClass` mapping via
6095configuration, which is useful for overrides :
6196
6297` ` ` yaml
63- c10k_messenger_logging :
98+ ckrack_messenger_logging :
6499 stamp_normalizers:
65100 App\M essenger\C ustomStamp: App\M essenger\L ogging\C ustomStampNormalizer
66101` ` `
67102
68- If the installed Messenger version supports `WorkerMessageSkipEvent`, skipped
69- messages are logged as well.
103+ # # Logged Lifecycle
70104
71- # # Example Lifecycle
105+ # ## Example Message Flow
72106
73107The example below shows how a single message can appear in the logs when it is
74108queued, fails once, is retried, and is eventually handled successfully. The
@@ -135,16 +169,23 @@ retry_count: 1</pre></td>
135169 </tbody>
136170</table>
137171
138- Each entry also contains the normalized `stamps` array, plus fields such as
172+ # ## Additional Context Fields
173+
174+ Each entry also contains the normalized `stamps` array. Depending on the
175+ envelope state, the bundle may also include fields such as
139176` transport_message_id` , `from_failed_transport`, and
140- ` failed_transport_original_receiver_name` when those details are available .
177+ ` failed_transport_original_receiver_name` .
141178
142179# # Local development
143180
181+ # ## Prerequisites
182+
144183- Docker with Compose V2
145184- pre-commit
146185- GNU Make
147186
187+ # ## Common Commands
188+
148189` ` ` bash
149190make setup
150191make check
0 commit comments