hannesvdvreken / guzzle-clockwork

A Guzzle plugin that lets you debug everything in the Clockwork browser extension.
MIT License
43 stars 9 forks source link

GuzzleHttp\Middleware\Log\Clockwork doesn't exist #7

Closed NGTmeaty closed 6 years ago

NGTmeaty commented 6 years ago

GuzzleHttp\Middleware\Log\Clockwork doesn't exist. I cannot use the example code to get it working.

hannesvdvreken commented 6 years ago

Eek, you're right. The docs are outdated.

Should be more like

$middleware = new GuzzleHttp\Profiling\Middleware(new GuzzleHttp\Profiling\Clockwork\Profiler($clockwork->getTimeline()));
$stack->push($middleware);

Could you double check and send a PR for the README.md file, please?

Cheers

NGTmeaty commented 6 years ago

Hey, back again. Can't seem to get this working! Here's my code.

                $clockwork = new \Clockwork\Clockwork();
                $middleware = new \GuzzleHttp\Profiling\Middleware(new \GuzzleHttp\Profiling\Clockwork\Profiler($clockwork->getTimeline()));
                $stack = \GuzzleHttp\HandlerStack::create();
                $stack->push($middleware);
hannesvdvreken commented 6 years ago

That's not enough information for me to find out what's wrong. Looks good to me. I'm not at my computer so I can't help you out.

Figuring stuff like this out without asking for help at every hurdle, is an essential tool for anyone to become a successful developer.

NGTmeaty commented 6 years ago

Sorry, was just looking to see if you had any insights into it. It seems like Clockwork isn't getting any of the data being passed.

hannesvdvreken commented 6 years ago

Check with https://github.com/itsgoingd/clockwork. It's possible that isn't setup correctly to add the X-Clockwork headers to your Response.

NGTmeaty commented 6 years ago

Regular clockwork is working. I can see the actual data is being passed to the middleware, the data from Guzzle isn't being put into Clockwork. I'll check over there. Thanks! 👍

hannesvdvreken commented 6 years ago

Did you new up Guzzle Client with the correct stack that has the middleware?

NGTmeaty commented 6 years ago

Yup, I did.

marcus-at-localhost commented 5 years ago

I dealt with the same problem and partially solved it.

For a Vanilla PHP integration (I don't know if that was the case for @NGTmeaty) you have to call $clockwork->requestProcessed(); as described in the docs.

Here is my code:

    public function __construct(array $config)
    {
        $this->stack = HandlerStack::create();

        $this->stack->push(Middleware::tap( /* Monolog Logging*/ ), 'log');

        $this->clockwork = \Clockwork\Support\Vanilla\Clockwork::init();
        $profiler = new \GuzzleHttp\Profiling\Clockwork\Profiler($this->clockwork->getTimeline(););
        $middleware = new \GuzzleHttp\Profiling\Middleware($profiler);
        $this->stack->push( $middleware, 'clockwork');

        $this->client = new Client([
            'base_uri' => $this->getOption('base_uri'),
            'handler' => $this->stack
        ]);

    }

    public function request($method, $path, $data = [])
    {
        $response = $this->client->request($method, $path, $data);
        $this->clockwork->requestProcessed();
    }

This is not very elegant, and I have to figure out how to use Clockwork globally in my app (Fatfreeframework), but at least I get the timeline for all calls.