Coder Social home page Coder Social logo

Comments (4)

MrMage avatar MrMage commented on August 22, 2024

The extension predates the JIT compiler, and it doesn't really receive future development anymore. In addition, its overriding of zend_execute_ex does cost a bit of performance (~20%).

I used to use this extension in the past (even contributed fixes to it), but mostly leave it disabled these days to benefit from better default performance. Instead, I manually trace performance-critical sections using Tracer::inSpan in the PHP library (i.e. without the native extension); it should get you the insights you need, without the performance penalty.

from opencensus-php.

kemurayama avatar kemurayama commented on August 22, 2024

@MrMage Thanks for sharing the performance information !! It is very useful for me when I instrument.
Do you have any recommendation when we want to capture traces with third party libraries (such as DB) ?
If I used Tracer::inSpan, I would want to trace more specifically to figure out if the latency comes from my implementation or not.

from opencensus-php.

MrMage avatar MrMage commented on August 22, 2024

I trace e.g. all Laravael controller route handlers and all DB queries automatically. From there, I know which routes are slow, and can add more instrumentation to those routes as needed.

Here's the code I use:

app/Http/Controllers/Controller.php

<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use OpenCensus\Trace\Tracer;

class Controller extends BaseController
{
    use DispatchesJobs,
        ValidatesRequests,
        AuthorizesRequests;

    public function callAction($method, $parameters)
    {
        return Tracer::inSpan(
            [
                'name' => static::class . '::' . $method,
            ],
            fn () => parent::callAction($method, $parameters)
        );
    }
}

app/Database/PostgresConnection.php

<?php

declare(strict_types=1);

namespace App\Database;

use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Database\Grammar;
use OpenCensus\Trace\Span;
use OpenCensus\Trace\Tracer;

class PostgresConnection extends \Illuminate\Database\PostgresConnection
{
    /* other methods */

    protected function run($query, $bindings, \Closure $callback)
    {
        // Trace any database queries. Alternatively, this could also be implemented by listening to
        // `\Illuminate\Database\Events\QueryExecuted` events; see e.g. `\Spatie\LaravelIgnition\Recorders\QueryRecorder`.
        $args = \func_get_args();
        return Tracer::inSpan(
            [
                'name' => 'DatabaseConnection::run',
                'attributes' => [
                    'query' => $query,
                ],
                'kind' => Span::KIND_CLIENT,
            ],
            // Can't use `\func_get_args()` directly here because the arguments to `fn ()` are empty.
            fn () => parent::run(...$args)
        );
    }
}

from opencensus-php.

kemurayama avatar kemurayama commented on August 22, 2024

@MrMage Thanks. These samples are really helpful for me to understand how to instrument the code.
And I really appreciate your kind response.

from opencensus-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.