Please add possibility to send more data about object in frame context.
At https://github.com/getsentry/sentry-php/blob/master/lib/Raven/Serializer.php#L54
if(is_object($value) || gettype($value) == 'object') {
return 'Object '.get_class($value);
}
It will be excellent if you add interface with method serialize, when object implement you will run it:
if (is_object($value) || gettype($value) == 'object') {
if ($value instanceof Raven_Custom_Serializer) {
return $value->serialize();
} else {
return 'Object '.get_class($value);
}
}
It would be even cooler if you could supply a callable to serialize custom classes, for classes you cannot control. This could work something like:
(new Raven_Client(...))->addSerializerForType(Illuminate\Support\Collection::class, function ($value) {
return $value->toArray();
});
This would add a lot of value IMHO, the Raven_Custom_Serializer is also a great idea!
Would love to hear what the Sentry folks think about this, would be happy to write a PR.
I would be down with making serialization more flexible (and effectively a type registry).
In Python we created a list of instances, and each instance has two methods: canSerialize and serialize. This makes it easy to do things like "serialize all types of values this way".
How about checking whether the __debugInfo() method is defined and using its output instead of returning Object foo?
This way the "serialization" (which in fact it's not, it's merely dumping the variable to human readable form) is controlled by the end-user and Sentry itself does not need any infrastructure for tracking custom serializers.
I came here looking to see if there is a way to view the contents of objects in Sentry. Right now all I see is "Object ReleaseObject". This is an object I have created. Is there a way to send some fields along? Has anything been implemented or is this just the way it is right now? Can I use something like "JsonSerializable" on this class? Thanks!
Why not just use print_r or var_dump? Shouldn't that just work implicitly? http://stackoverflow.com/questions/3034530/php-print-all-properties-of-an-object
@archon810 it will create enormous objects in non-native types. Sure we could do it, but then you're going to by default sacrifice other data.
I'm all for allowing some simply callback for the serialization to allow you to manage it yourself, though I'm not sure the speed cost.
+1 for adding specialized serializer
@dcramer Is this officially on the todo list? @stayallive's suggestion feels like a vital feature, and I'd love to see it implemented.
I think that this kind of work should be done against the 2.x branch. But :+1: for it!
A custom serialization based on class types would be very welcome.
Real-life example:

but the actual values are Carbon\Carbon instances and nowhere in the stacktrace it's possible to see the values:

Something like ->addSerializerForType(\Carbon\Carbon::class, function (Carbon $obj) { return (string) $obj; }); would be really great.
We also need that very much.
I think @mfn's example shows that we should call the object's __toString method if it has one.
Current:
return 'Object ' . get_class($value);
Suggestion:
if(method_exists($value, '__toString')) {
return 'Object (' . get_class($value) . ') ' . $value->__toString();
} else {
return 'Object (' . get_class($value) . ')';
}
If we can't specify a custom serializer, using __toString() would be better than nothing I guess.
Even better in that case would be using jsonSerialize() for classes that implement JsonSerializable. The object can just be passed to json_encode() as-is.
Agreed, we should have custom serializers. I'm saying that __toString/jsonSerialize/etc would be an excellent default in addition to custom serializers.
What's the current state of this? Is it possible to serialize objects somehow instead of getting only Object?
up
At the moment I don't think that there is value in adding new features to the 1.x branch as 2.0 is in the works. I would like to rewrite the whole serializer (which is also a dumper in our case...) but afaik there might be some BC changes coming next week in 2.0 that will postpone it again. I would also explore some other ways with the Sentry guys to send a payload that provides more valuable information than now (it's pretty limited as data is being transferred as JSON, trimmed, etc)
Also running into this. To me it would be very helpful to have the example from @mike-grinspan implemented., even in 1.x.
This was already being worked on but much discussion so it might be good to re-think/do that PR with the current state of the discussions on that PR: #443
Closing this issue as it has been resolved in the referenced PR. Please note that there are no plans to backport the feature to version 1.x.
Most helpful comment
It would be even cooler if you could supply a callable to serialize custom classes, for classes you cannot control. This could work something like:
This would add a lot of value IMHO, the
Raven_Custom_Serializeris also a great idea!Would love to hear what the Sentry folks think about this, would be happy to write a PR.