getsentry / getsentry/sentry-php
Support for using own Representation Serializer
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 474
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 8
Description
I would like to support something similar as discussed in this issue: https://github.com/getsentry/sentry-php/issues/889

- Old: `Object: App\Entity\SomeEntity`
- New: `Object: App\Entity\SomeEntity(#123)`
A solution for this would be this:
```php
use Sentry\Serializer\Serializable;
class ExampleObject implements Serializable
{
private $id = 123;
public function toSentry(): array
{
return [
'internal_state' => 'Object: ExampleObject(#' . $this->id . ')' ,
];
}
}
```
But I would rather have a more re-usable solution, via a custom Serializer:
```yaml
# sentry.yaml
sentry:
representation_serializer: App\Sentry\RepresentationSerializer
```
```php
# App\Sentry\RepresentationSerializer.php
class RepresentationSerializer extends AbstractSerializer implements RepresentationSerializerInterface
{
public function representationSerialize($value)
{
if (\is_object($value)) {
return 'Object ' . \get_class($value) . '(#' . $value->getId() . ')';
}
}
}
```
For this we need to be able to pass a custom Serializer to this bundle. Would it be possible to support using a custom Serializer with the sentry-symfony bundle?
https://github.com/getsentry/sentry-symfony/blob/master/src/DependencyInjection/SentryExtension.php#L123-L125
Contributor guide
Assessment
This issue has not been assessed yet.