Skip to content

Conversation

@stayallive
Copy link
Collaborator

We should try (harder) to represent values the user provides us as log attributes. So we now as last resort JSON encode the value which results in almost any value to be serialized and correctly logged. Also null values are now serialized as string instead of discarded.

@stayallive stayallive requested a review from Litarnus October 28, 2025 13:13
Comment on lines 90 to 96
if ($value instanceof SerializableInterface) {
try {
return new self(JSON::encode($value->toSentry()), 'string');
} catch (\Throwable $e) {
// Ignore the exception and continue trying other methods
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because we have it, I prefered this over the __toString or just raw JSON encode.

For safety we do ignore any errors to prevent crashing because serializing fails.

Comment on lines +138 to +139
// Since we support almost any type, we use a resource to trigger the exception
Attribute::fromValue(fopen(__FILE__, 'r'));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's now a challenge to find something we can't represent as an attribute.

Copy link
Contributor

@Litarnus Litarnus left a comment

Choose a reason for hiding this comment

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

nice! :shipit:

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