-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
debug module events panel #3842
Comments
What would you display in the panel? What information exactly? |
what events occured in system and with what data, for example: UserSignupedEvent([
'user' => ...,
])
UserChangedPasswordEvent([
'user' => ...,
'oldPassword' => ...,
'newPassword' => ...
])
ItemOrderAddedEvent([
'item' => ...,
'order' => ...
]) and so on. You can look for similar things in L4 or Symfony . |
👍 |
@cebe Also i think we should add |
Could be useful. |
Also, @qiangxue @samdark need your advice here, we have 2 ways to implement this one:
As for me first one ( |
I'd go for events. |
How are you planing to do this? There is no way to specify event handler (event a class event handler) without knowing the event name. This means you should either specify all affected events at panel config, which reduces the benefit of such panel, or try to define it in automatic mode, which elimiates the ability to track any custom events.
Would not this produce too much log entries at the end of application run? What about memory usage? |
Using trace will produce lots of log entries in debug mode, true. That's why I prefer adding an ability to subscribe to any events. Of course, it should be performance-profiled since it will require executing some additional code on each event. |
this is how it supposed to be used. I dont think that developer will change subscribed events very often. It is only one time setup, see above first comment about how to configure panel. So i think it will be implemented with first approach, direct subscribing to events. |
Such panel may be very useful while debugging application, because it allows to see, which events are actually fired. This is exceptionaly useful for the newcomers, who may not yet realize how events work and what they may affect. |
@klimov-paul not sure if i understand you ) you are against or for this one ? Mainly it is not for newcomers but for EDA and SOA applications, yet we can make somethign like |
Also stacktrace should be supported ofcourse . |
What was their solution on this matter? |
they have central point and if needed can subscribe with wildcards, that was restricted and discarded in Yii2 . |
Also do we really need to log all fired events? Does it makes sense? |
Well, main thing here is that event is raised and not that handler is attached to it, handlers can cause some 3rd party libs to act, and developer can deatach them for debugging purposes, so we should only catch events. |
so should i implement this one ? will also check on how to collect info about called and not called listeners too, as it is done in syfmony webprofilerbundle. |
@klimov-paul as for your request, we can make it in two ways:
What do you prefer better ? As for me last one is better. |
Don't we trying to track all events here? Who will track
Perhaps
Сertainly it worth trying. Maybe having some implementation at sight we can figure out all details. |
some kind of, |
Would not it create a recursion inside the code? |
well, for this case user just need to handle this situation by himself as for me. We can get in trouble with recursion almost at any event if it can trigger actions that are generating event on what class is subscribed. So i think it is fine here. |
@qiangxue @klimov-paul need your opinion here for this question and probably solutions:
We need to get list of all subscribers to the particular event of component and track what subscribers where called and what was not.
the only good solution i see as was noted by introducing new event to make it possible to determine on what event subscriber was called, We cant use some Will this (introducing new event) result in some performance disadvantages? Currently it is the only way as i see to solve this problem. Brief overview: //in events panel after catch event
$this->_eventsInfo[$eventId]['subscribers'] = $event->sender->getSubscribers();
//after catch SubsriberCalledEvent
$this->_eventsInfo[$eventId]['called_subscribers'] = $event->subscriber; of course above is just short code to get understading of how it should works. So what would be the solution? Maybe we need to check performance but currently i don't understand how to do this. Also not sure if it will have big impact on performance since this event is more for some internal processing and usually developers should not use it. Also where is |
I don't think we should raise another event for each event. It's too much overhead and also mess up with the normal event triggering workflow.
I think we may consider introducing some broadcasting mechanism (something like global events but much lighter). For example, // register a callback for a specified channel
Yii::watch('channel', $callback);
...
// send $content to the channel, which will call the callbacks registered with the channel
Yii::broadcast('channel', $content); Now inside of This mechanism is a bit similar to the event mechanism, but it's much lighter because it doesn't need to create a new event object, and the watchers are not allowed to interrupt the broadcasting (event handlers can stop event handling). This is just a rough idea. Not sure if there's any loophole. |
i see, so callback will have For now will implement first part without history of called / not called subscribers . And same question as in above:
How to get all subscribers? |
Callback will get Nope, this will not replace the current event mechanism. In most cases, you should use events which are essential if you want a component to support behaviors. You may view this approach as a sort of logging. The difference is that the content is processed right away instead of being sent to the targets in batches. Also, no inspection on this approach will be supported. We can add |
yes, that would be great, not sure why it was removed. Not critical for now though, after first implementation we can do this |
thanks Paul.
Of course, this functionality should not go at too much cost of memory. I think we should keep it easy. A simple trace of $class + $name should be already enough to get a good point of whats happening (see #7277) at what time. When using Event to trace & debug data, performance will be lost. Solutions like Qiang suggested, are then necessary. It will definately be of use, as we can then put a magnify glass on specific data throughput. It should be optimal though, performance wise. |
Issue moved to yiisoft/yii2-debug#77 |
Usually when creating application and using EDA or SOA it is good to have ability to check events and data that they hold.
I think this panel would be useful in debug module, several modern fw also includes it.
The only thing here we have to solve is how to subscribe to all or part of events, since we dont have wildcard matching and we dont have any central point for event. My suggestion is to either add wildcard matching or introduce in events panel property
neededEvents
in format:In the same way we can make
exclude
option. Data that will be collected upon each event is its public properties json encoded or we can use Yii2var_export
not sure about the last one though .The text was updated successfully, but these errors were encountered: