-
Notifications
You must be signed in to change notification settings - Fork 50
Added web profiler and toolbar #19
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
Conversation
c678539
to
2b2ad74
Compare
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function collect(Request $request, Response $response, \Exception $exception = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this intentionally empty? if so, please add a comment why it is there and empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey, thank you.
A upcoming PR maybe want to log which Symfony Request that made which Httplug Request. But it should be empty for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
very cool! i am impressed how simple this looks! |
Thank you. So am I. I barley wrote any code just some clue to make |
@@ -51,14 +51,16 @@ For information how to write applications with the services provided by this bun | |||
| httplug.stream_factory | Service* that provides the `Http\Message\StreamFactory` | |||
| httplug.client.[name] | This is your Httpclient that you have configured. With the configuration below the name would be `acme_client`. | |||
| httplug.client | This is the first client configured or a client named `default`. | |||
| httplug.plugin.content_length <br> httplug.plugin.decoder<br> httplug.plugin.error<br> httplug.plugin.logger<br> httplug.plugin.redirect<br> httplug.plugin.retry | These are build in plugins that lives in the `php-http/plugins` package. These servcies are not public and may only be used when configure HttpClients or services. | |||
| httplug.plugin.content_length <br> httplug.plugin.decoder<br> httplug.plugin.error<br> httplug.plugin.history<br> httplug.plugin.logger<br> httplug.plugin.redirect<br> httplug.plugin.retry | These are built in plugins that lives in the `php-http/plugins` package. These servcies are not public and may only be used when configure HttpClients or services.<br><br>*The History plugin is only available when the kernel runs on debug mode and `httplug.toolbar: true`. It gets automatically injected to all clients.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/that lives/that live/
@@ -27,6 +27,13 @@ public function load(array $configs, ContainerBuilder $container) | |||
$loader->load('services.xml'); | |||
$loader->load('plugins.xml'); | |||
$loader->load('discovery.xml'); | |||
if ($config['toolbar']['enabled'] && $container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this state of the art to detect whether the debug toolbar is active? what if somebody has it active in prod env or deactivated in dev env? i guess in the latter case, we just waste some cpu cycles in dev mode which is no big deal. the other might be a problem. or is debug toolbar hard coupled to kernel.debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. I should redo this.
What I really want to know is if the service profiler
exits and if its configuration for toolbar
is true.
I'll investigate some more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or is debug toolbar hard coupled to kernel.debug?
No it is not. To get the toolbar you need framework.profiler
enabled and of course the WebProfilerBundle. There is nothing that ties it to kernel.debug. So this is technically wrong, but it works for most cases. Others are doing the same.
I could use a compiler pass and check for the web_profiler.debug_toolbar.mode
parameter if it is enabled or disabled. But I think that will complicate how I inject the HistoryPlugin because that would also be done in the compiler pass.
Question: Are we happy with postponing support for the use case where you want the debug Httplug request via the toolbar with kernel.debug: false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe look at what other bundles that plug into the toolbar do
I've looked at a few. It is common that you inject a logger or a collector to a decorating class. That injection is done in a compiler pass. Some bundles (like GeocoderBundle do always inject the logger, no matter debug or environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always a good idea to inject logger. Fingers Crossed handler can
decide then when and what to log.
Tobias Nyholm [email protected] ezt írta (2016. január 8., péntek):
In DependencyInjection/HttplugExtension.php
#19 (comment):@@ -27,6 +27,13 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');
$loader->load('plugins.xml');
$loader->load('discovery.xml');
if ($config['toolbar']['enabled'] && $container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) {
maybe look at what other bundles that plug into the toolbar do
I've looked at a few. It is common that you inject a logger or a collector
to a decorating class. That injection is done in a compiler pass. Some
bundles (like GeocoderBundle
https://github.com/geocoder-php/BazingaGeocoderBundle do always inject
the logger, no matter debug or environment.—
Reply to this email directly or view it on GitHub
https://github.com/php-http/HttplugBundle/pull/19/files#r49206816.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always a good idea to inject logger. Fingers Crossed handler candecide then when and what to log.
Yes, I meant more of a DataCollector to collect data for the profiler. That is injected all the time
@@ -34,8 +34,7 @@ public function getConfigTreeBuilder() | |||
return !empty($v['classes']['client']) | |||
|| !empty($v['classes']['message_factory']) | |||
|| !empty($v['classes']['uri_factory']) | |||
|| !empty($v['classes']['stream_factory']) | |||
; | |||
|| !empty($v['classes']['stream_factory']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this styleci? my idea was that adding another check only does a diff on one line, like trailing comma in arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is styleci
5a17b31
to
5f71398
Compare
If you need a more custom setup, define the services in your application configuration and specify your service in the `main_alias` section. For example, to add authentication headers, you could define a service that decorates the service `httplug.client.default` with a plugin that injects the authentication headers into the request and configure `httplug.main_alias.client` to the name of your service. | ||
|
||
```yaml | ||
httplug: | ||
clients: | ||
clients: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a trailing space?
Thank you for your feedback. I've updated the PR. |
Sorry, CS fixes probably introduced a few conflicts. |
No worries, I've updated the PR. |
Cool. How far is it? I am eager to try it in a project. 😄 |
I'm done with the implementation, I've received a lot feedback and made some improvements. I have addressed all the issues that were brought up. Now Im waiting for @dbu to give this PR the final thumbs up. |
Cool. |
thanks a lot for this one, good job! |
👍 |
Thank you for merging. I'm also very exited to try this in a project =) |
@@ -54,6 +66,10 @@ protected function configureClients(ContainerBuilder $container, array $config) | |||
$first = $name; | |||
} | |||
|
|||
if (isset($config['_inject_collector_plugin'])) { | |||
array_unshift($arguments['plugins'], 'httplug.collector.history_plugin'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, adds the plugin first. does that mean we log before anything else? that will mean that if we have the redirect plugin active, we will not see that a redirect happened. then again, if redirect was activated, we might not care about it.
but it also means we will not log the request exactly as it was sent, with base url or credentials or whatever was added by the plugins. do we maybe need a flag to let the user decide whether to add to the beginning or to the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have the CachePlugin and put the HistoryPlugin last you will not see anything... But that might be okey, since no request was actually made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #26 for this idea. i guess what we have now is ok, but the other thing sure would be cool.
As mentioned in #3.
This PR implements a web debug toolbar. It uses the HistoryPlugin.