Skip to content

Add helpful remarks on custom DataCollector #7773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions profiler/data_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ The
:method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::collect`
method is responsible for storing the collected data in local properties.

.. caution::

The :method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::collect` method is only called once.
It is not used to "gather" data but is there to "pick up" the data that has been stored by your service.

Most of the time, it is convenient to extend
:class:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollector` and
populate the ``$this->data`` property (it takes care of serializing the
Expand Down Expand Up @@ -71,6 +76,11 @@ collects the method and accepted content types from the request::

The getters are added to give the template access to the collected information.

.. caution::

If the data that is not directly related to the request or response, you need to make the data accessible to your DataCollector.
This can be achieved by injecting the service that holds the information you intend to profile into your DataCollector.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would a code example (CustomService in constructor, gathering data in the collect method) be helpful here? Or would you consider it to be too specific?

Copy link
Member

Choose a reason for hiding this comment

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

I think that's a bit too specific. But let's see what other members of the @symfony/team-symfony-docs team think about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is needed, this note sounds clear enough, also a constructor is not this only way to inject data.
Note that the collector itself can be used as listener in order to grab anything, and then collect data using it, both injection and observation are used in the core btw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Then why not put this into the doc as a note as well?
I think this is clear once you are familiar with the concepts of Symfony but not for the n00b reading this for the first time

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think a code example would improve anything here. At the point you're creating your own DataCollector, you're probably already aware of injection and DI. The comment is a nice addition as it is right now imo. In case people get stuck here, there's always IRC or Slack, where they will probably be forwarded to the DIC docs.


.. caution::

As the profiler serializes data collector instances, you should not
Expand Down