Skip to content
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

Example #1

Open
Pidz-b opened this issue Jul 23, 2019 · 3 comments
Open

Example #1

Pidz-b opened this issue Jul 23, 2019 · 3 comments

Comments

@Pidz-b
Copy link

Pidz-b commented Jul 23, 2019

Hello,

Your project seems promising for our system.
Could you maybe incorporate an example in the README of how to use your code?

Or is the project not completed yet?

Best regards

@subzerobo
Copy link
Owner

Hello,

Project is completed, couple of examples will be updated in next 3 days

Kind Regards

@AnicetR
Copy link

AnicetR commented Jul 31, 2019

Hello,

I'm searching for the same thing as Pdz-b. Your project seems very promising, can you please keep in touch when the examples would be updated ?

Regards

@BboyKeen
Copy link
Contributor

Hello

We successfully use this library like this in Symfony for HTTP request tracing

<?php


namespace App\Performance;


use Subzerobo\ElasticApmPhpAgent\ApmAgent;
use Subzerobo\ElasticApmPhpAgent\Wrappers\TransactionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;


class HttpTransactionListener implements EventSubscriberInterface
{
    private $apmAgent;

    /** @var TransactionEvent */
    private $transactionEvent;

    /**
     * HTTPTransactionListener constructor.
     */
    public function __construct(ApmAgent $apmAgent)
    {
        $this->apmAgent = $apmAgent;
    }

    public static function getSubscribedEvents()
    {
        return [
            RequestEvent::class => ['onKernelRequest', 4096],
            TerminateEvent::class => ['onKernelTerminate', 4096]
        ];
    }

    public function onKernelRequest(RequestEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $this->transactionEvent = $this->apmAgent->startTransaction();
    }

    public function onKernelTerminate(TerminateEvent $event)
    {
        if (!$this->transactionEvent) {
            return;
        }

        $response = $event->getResponse();

        $this->transactionEvent->setResult("HTTP " . $response->getStatusCode());
        $this->transactionEvent->setType("request");
        $this->transactionEvent->setIsSampled(true);
        $this->transactionEvent->setResponseFromArray([
                'finished'     => true,
                'headers_sent' => true,
                'status_code'  => $response->getStatusCode(),]
        );
        $this->transactionEvent->stop();

        $this->apmAgent->send();
    }
}

What are you trying to achieve ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants