Skip to content

Conversation

@kjamrog
Copy link
Collaborator

@kjamrog kjamrog commented Dec 18, 2025

Context:
The reason for the change is that we want to avoid logging full message payload in debug logs as it can potentially contain private data. The aim is to log only some metadata that is generally useful for debugging and gathering metrics about the processing + give client an option to provide custom formatter if more logs are needed

Summary of the changes:

  • not logging full message anymore
  • removed redundant logs - each message processing goes through handleMessageProcessed method and we have single log there:
  • in the log we include:
    • parsed message properties (id, type, metadata, timestamps etc.) - this is always logged
    • the output of messageLogFormatter - only if provided explicitly (default one printing whole message was removed)

Summary by CodeRabbit

  • New Features

    • Added configurable message metadata field to enable enhanced message tracking across queue operations.
  • Bug Fixes

    • Consolidated message logging into a unified processing path for improved consistency and structure.
  • Refactor

    • Made log formatters optional for greater implementation flexibility.
    • Updated logging architecture to use processed message metadata instead of separate message parameters.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Walkthrough

The PR refactors message logging across queue implementations (AMQP, GCP PubSub, SNS, SQS). It removes inline logging from publisher/consumer methods, centralizes logging through ProcessedMessageMetadata, updates resolveMessageLog signature to accept metadata objects, and makes messageLogFormatter optional in handler configuration.

Changes

Cohort / File(s) Summary
AMQP Consumer & Publisher
packages/amqp/lib/AbstractAmqpConsumer.ts, packages/amqp/lib/AbstractAmqpPublisher.ts
Removed inline logging blocks during message processing/publishing; updated resolveMessageLog to accept ProcessedMessageMetadata instead of separate message and messageType parameters; added type import for ProcessedMessageMetadata.
GCP PubSub Consumer & Publisher
packages/gcp-pubsub/lib/pubsub/AbstractPubSubConsumer.ts, packages/gcp-pubsub/lib/pubsub/AbstractPubSubPublisher.ts
Updated resolveMessageLog signature in consumer to accept ProcessedMessageMetadata; removed inline logging and resolveMessageLog method from publisher.
SNS & SQS Publishers
packages/sns/lib/sns/AbstractSnsPublisher.ts, packages/sqs/lib/sqs/AbstractSqsPublisher.ts
Removed conditional logging blocks that previously logged during publish operations while preserving core publishing logic.
SQS Consumer
packages/sqs/lib/sqs/AbstractSqsConsumer.ts
Removed inline logging during message processing; updated resolveMessageLog signature to accept ProcessedMessageMetadata and return unknown | null.
Core Queue Service
packages/core/lib/queues/AbstractQueueService.ts
Added messageMetadataField configuration property; introduced logMessageProcessed method for centralized logging; updated resolveMessageLog signature; enhanced resolveProcessedMessageMetadata to include messageMetadata field; updated offload payload handling to preserve messageMetadata.
Handler Configuration
packages/core/lib/queues/HandlerContainer.ts
Made messageLogFormatter optional in MessageHandlerConfig; removed default formatter export and fallback initialization.
Type Definitions
packages/core/lib/types/queueOptionsTypes.ts
Added optional messageMetadata field to ProcessedMessageMetadata; added optional messageMetadataField to CommonQueueOptions.
Test Suites
packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts, packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts, packages/core/test/queues/HandlerContainer.spec.ts, packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts
Updated test expectations to reflect new logging structure with processedMessageMetadata; adjusted logged message counts; removed test for default formatter behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Metadata handling consistency: Verify that messageMetadata extraction and preservation is consistent across all queue implementations and offloading scenarios
  • Logging signature alignment: Confirm all implementations correctly override resolveMessageLog with the new ProcessedMessageMetadata parameter
  • Test coverage: Review test expectations for new metadata structure, particularly around processedMessageMetadata nesting and field presence
  • Optional formatter implications: Ensure consumers that depend on messageLogFormatter have been updated to handle undefined formatters safely
  • Backward compatibility: Validate that the removal of inline logging doesn't break existing logging expectations in dependent code

Possibly related PRs

Suggested labels

patch

Suggested reviewers

  • kibertoad
  • CarlosGamero

Poem

🐰 Hops through logs with glee,
Metadata now flows so free,
Centralized and clean,
Finest logging I've seen,
The queues sing in harmony!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title 'Improved message logging' is vague and generic, using non-descriptive language that doesn't convey the specific purpose of removing full message payloads from logs. Consider a more specific title such as 'Remove full message payloads from debug logs' or 'Log only message metadata instead of full payloads' to better reflect the primary change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch remove_payload_from_logs

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03b7220 and f45eaee.

📒 Files selected for processing (1)
  • packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: general (24.x, @message-queue-toolkit/s3-payload-store) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/gcp-pubsub) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/outbox-core) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/schemas) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/metrics) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/gcs-payload-store) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/outbox-core) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/amqp) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/s3-payload-store) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/redis-message-deduplication-store) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/gcp-pubsub) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/gcp-pubsub) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: kafka (22.x) / build
  • GitHub Check: kafka (24.x) / build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kjamrog kjamrog added the minor label Dec 18, 2025
@kjamrog kjamrog marked this pull request as ready for review December 18, 2025 14:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/lib/queues/AbstractQueueService.ts (1)

345-349: Fix the property name - critical bug!

Line 348 accesses message[this.messageDeduplicationId] but the property is named this.messageDeduplicationIdField (defined at line 112). The "Field" suffix is missing, causing this to always return undefined and breaking deduplication ID tracking.

🔎 Apply this diff to fix the property name:
   const messageDeduplicationId =
     message && this.messageDeduplicationIdField in message
       ? // @ts-ignore
-        message[this.messageDeduplicationId]
+        message[this.messageDeduplicationIdField]
       : undefined
🧹 Nitpick comments (1)
packages/core/lib/events/DomainEventEmitter.spec.ts (1)

207-207: Consider removing the non-null assertion for consistency.

The combination of optional chaining (?.) and non-null assertion (!) is contradictory: optional chaining handles undefined gracefully, while ! asserts the value is definitely not undefined. Line 407 uses the cleaner pattern metadata?.correlationId without the trailing !.

🔎 Apply this diff for consistency:
-          correlationId: createdEventPayload.metadata?.correlationId!,
+          correlationId: createdEventPayload.metadata?.correlationId,
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a78d2a7 and 03b7220.

📒 Files selected for processing (16)
  • packages/amqp/lib/AbstractAmqpConsumer.ts (2 hunks)
  • packages/amqp/lib/AbstractAmqpPublisher.ts (0 hunks)
  • packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts (3 hunks)
  • packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts (1 hunks)
  • packages/core/lib/events/DomainEventEmitter.spec.ts (1 hunks)
  • packages/core/lib/queues/AbstractQueueService.ts (7 hunks)
  • packages/core/lib/queues/HandlerContainer.ts (2 hunks)
  • packages/core/lib/types/queueOptionsTypes.ts (2 hunks)
  • packages/core/test/queues/HandlerContainer.spec.ts (0 hunks)
  • packages/gcp-pubsub/lib/pubsub/AbstractPubSubConsumer.ts (2 hunks)
  • packages/gcp-pubsub/lib/pubsub/AbstractPubSubPublisher.ts (0 hunks)
  • packages/sns/lib/sns/AbstractSnsPublisher.ts (0 hunks)
  • packages/sns/lib/utils/snsInitter.ts (1 hunks)
  • packages/sqs/lib/sqs/AbstractSqsConsumer.ts (3 hunks)
  • packages/sqs/lib/sqs/AbstractSqsPublisher.ts (0 hunks)
  • packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts (2 hunks)
💤 Files with no reviewable changes (5)
  • packages/core/test/queues/HandlerContainer.spec.ts
  • packages/gcp-pubsub/lib/pubsub/AbstractPubSubPublisher.ts
  • packages/sns/lib/sns/AbstractSnsPublisher.ts
  • packages/sqs/lib/sqs/AbstractSqsPublisher.ts
  • packages/amqp/lib/AbstractAmqpPublisher.ts
🧰 Additional context used
🧬 Code graph analysis (7)
packages/gcp-pubsub/lib/pubsub/AbstractPubSubConsumer.ts (1)
packages/core/lib/types/queueOptionsTypes.ts (1)
  • ProcessedMessageMetadata (19-70)
packages/core/lib/queues/AbstractQueueService.ts (1)
packages/core/lib/types/queueOptionsTypes.ts (1)
  • ProcessedMessageMetadata (19-70)
packages/amqp/lib/AbstractAmqpConsumer.ts (1)
packages/core/lib/types/queueOptionsTypes.ts (1)
  • ProcessedMessageMetadata (19-70)
packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts (1)
examples/sns-sqs/lib/common/Dependencies.ts (1)
  • logger (22-22)
packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts (1)
examples/sns-sqs/lib/common/Dependencies.ts (1)
  • logger (22-22)
packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts (1)
examples/sns-sqs/lib/common/Dependencies.ts (1)
  • logger (22-22)
packages/sqs/lib/sqs/AbstractSqsConsumer.ts (1)
packages/core/lib/types/queueOptionsTypes.ts (1)
  • ProcessedMessageMetadata (19-70)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: general (20.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/gcp-pubsub) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/core) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/s3-payload-store) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/s3-payload-store) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/gcp-pubsub) / build
  • GitHub Check: kafka (24.x) / build
  • GitHub Check: kafka (22.x) / build
🔇 Additional comments (18)
packages/core/lib/types/queueOptionsTypes.ts (1)

65-69: LGTM!

The new optional fields messageMetadata and messageMetadataField are well-documented and properly typed to support the metadata-driven logging refactor described in the PR objectives.

Also applies to: 121-121

packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts (2)

446-458: LGTM!

Test expectations correctly updated to reflect the new consolidated logging structure using processedMessageMetadata. The reduction from 2 log entries to 1 aligns with the PR's goal of centralizing message logging.


515-517: LGTM!

Metrics test correctly validates that messageMetadata is captured and includes the schemaVersions field from the published message's metadata.

packages/amqp/test/publishers/AmqpPermissionPublisher.spec.ts (1)

50-64: LGTM!

Test expectations correctly updated to validate the new metadata-based logging structure for publishers, including the processedMessageMetadata object with processingResult: { status: 'published' }.

packages/sqs/lib/sqs/AbstractSqsConsumer.ts (1)

835-846: LGTM!

The resolveMessageLog method has been correctly refactored to accept ProcessedMessageMetadata and includes appropriate null guards. The implementation properly returns null when the message log formatter is not configured, which aligns with the change to make messageLogFormatter optional in HandlerContainer.

packages/amqp/test/consumers/AmqpPermissionConsumer.spec.ts (3)

98-115: LGTM!

Test expectations correctly updated to reflect the consolidated logging structure with processedMessageMetadata objects. The reduction from 6 to 4 log entries aligns with the centralized logging approach.


166-166: LGTM!

Correctly validates that messageMetadata is undefined when no metadata is provided in the message.


408-408: LGTM!

Good defensive programming with optional chaining to safely access potentially undefined nested properties.

packages/core/lib/queues/HandlerContainer.ts (1)

99-99: LGTM - Important behavioral change!

The messageLogFormatter is now optional and no longer has a default value. This ensures that message payloads are not logged by default, which aligns with the PR's objective to avoid exposing potentially private data. Clients must now explicitly provide a messageLogFormatter if they want message logging.

This is a semantic change that improves privacy by default.

Also applies to: 127-127

packages/gcp-pubsub/lib/pubsub/AbstractPubSubConsumer.ts (1)

865-876: LGTM!

The resolveMessageLog method has been correctly refactored to use the metadata-based approach, consistent with similar changes in other consumer implementations (SQS, AMQP). The implementation includes proper guards and correctly handles the optional messageLogFormatter.

packages/amqp/lib/AbstractAmqpConsumer.ts (2)

9-9: LGTM!

The import is necessary for the updated resolveMessageLog signature and is correctly placed.


266-277: LGTM!

The refactored resolveMessageLog method correctly:

  • Accepts the new ProcessedMessageMetadata parameter
  • Guards against missing message or messageType
  • Returns null when no formatter is configured
  • Invokes the formatter only when appropriate

This aligns well with the PR's centralized logging approach.

packages/core/lib/queues/AbstractQueueService.ts (6)

117-120: LGTM!

The new messageMetadataField property is well-documented and its purpose aligns with the PR's goal of structured, privacy-conscious logging.


164-164: LGTM!

The initialization follows the established pattern and provides a sensible default value.


247-251: LGTM!

The signature change to accept ProcessedMessageMetadata aligns with the centralized metadata-driven logging approach described in the PR objectives.


253-277: LGTM!

The new logMessageProcessed method provides comprehensive, structured logging:

  • Safely serializes messageMetadata using stringValueSerializer
  • Includes all relevant processing metadata
  • Allows optional custom message formatting via resolveMessageLog

This implementation aligns well with the PR's privacy and centralized logging objectives.


313-326: LGTM!

The renamed debugMessageLoggingEnabled variable is more descriptive, and the call to logMessageProcessed correctly uses the new logging API.


350-366: LGTM!

The messageMetadata extraction correctly uses this.messageMetadataField and follows the same pattern as other field extractions. The metadata is properly included in the returned ProcessedMessageMetadata object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants