Support for using own Representation Serializer

Open
#1,892 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
backend

Research direction

Start in src/DependencyInjection/SentryExtension.php around lines 123-125 and compare the requested sentry.yaml representation_serializer option with the existing bundle configuration. Trace how representation serialization is wired, then verify that a configured custom serializer can format objects with values such as an entity ID without breaking the default behavior.

Written by the indexing model from the issue text.

Description

5.0 Feature

I would like to support something similar as discussed in this issue: https://github.com/getsentry/sentry-php/issues/889

image
  • Old: Object: App\Entity\SomeEntity
  • New: Object: App\Entity\SomeEntity(#123)

A solution for this would be this:

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:

# sentry.yaml
sentry:
  representation_serializer: App\Sentry\RepresentationSerializer
# 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

Dominant language
PHP
Stars
1.9k
Forks
474
Avg merge
2d 3h
Merged PRs (30d)
8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from getsentry/sentry-php

All issues in getsentry/sentry-php

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.