Skip to content

Add repr to MessageProxy#690

Merged
karolinepauls merged 1 commit into
masterfrom
messageproxy-repr
Apr 15, 2025
Merged

Add repr to MessageProxy#690
karolinepauls merged 1 commit into
masterfrom
messageproxy-repr

Conversation

@karolinepauls

Copy link
Copy Markdown
Collaborator

Small change to improve developer experience with Dramatiq+Sentry and possibly any other error aggregation platform.

Currently error messages in Sentry look like this:

image

This is caused by the following code is responsible for formatting log params in Sentry: https://github.com/getsentry/sentry-python/blob/adcfa0f6abf8850f3b007bde609d0f943f621786/sentry_sdk/logger.py#L24-L32. Sentry has its reasons to do this - __str__ is more lossy than __repr__, for example exceptions stringify to their arguments, losing their class name.

After this change MessageProxy repr looks as follows:

<MessageProxy Message(queue_name='default', actor_name='actor_name', args=('arg',), kwargs={}, options={}, message_id='fe5511da-59ed-4b45-80f2-526d02c935fb', message_timestamp=1743773870061)>

Existing logging will not be affected because Dramatiq uses "%s" for message formatting and MessageProxy.__str__ remains the same..

@LincolnPuzey LincolnPuzey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me! Probably will be useful in any debugging scenario

@synweap15

Copy link
Copy Markdown
Collaborator

Looks good to me

@karolinepauls karolinepauls merged commit 6d60a5f into master Apr 15, 2025
@LincolnPuzey LincolnPuzey deleted the messageproxy-repr branch April 16, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants