Detecting Transaction Names

To separate the profiling results for different endpoints in your projects you can name these Transactions. For the supported frameworks the Tideways can automatically detect the transaction name. With version 5 of the Tideways extension (released August 2018) you don’t have to configure anything else and all the supported frameworks are automatically detected.

If you don’t use one of the supported frameworks, you can set the transaction name manually in your application. You can do this as soon you know the name of the transaction or endpoint.

There are multiple ways to pick a transaction name:

  1. The best way in Model-View-Controller based applications is setting the controllers class name and the actions method as soon as they are known in the application.

    This can usually be hooked into or directly built into the code that handles the dispatching of requests to controllers.

    See this example of a hypothetical dispatcher in your application:

    <?php
    
    class Dispatcher
    {
        public function dispatch($controllerClass, $actionName)
        {
            // Add this four lines to set the transaction name
            $transactionName = $controllerClass . '::' . $actionName;
            if (class_exists('Tideways\Profiler')) {
                \Tideways\Profiler::setTransactionName($transactionName);
            }
    
            $controller = new $controllerClass();
            return $controller->$actionName();
        }
    }
  2. If your application does not use model-view-controller with a Front Controller, then maybe it is using a script based approach, such as phpBB which uses its own script for each controller, optionally modified by a mode parameter. In your bootstrap code that gets called in every script you can then add code along the following lines:

    <?php
    
    use Tideways\Profiler;
    
    if (class_exists('Tideways\Profiler')) {
        $transactionName = $_SERVER['SCRIPT_NAME'];
        if (isset($_GET['mode'])) {
            $transactionName .= '?mode=' . $_GET['mode'];
        }
        Profiler::setTransactionName($transactionName);
    }

You should not pass in fully dynamic URLs as transaction names. An endpoint describes the same kind of code being executed, independent of the data being actually send to this endpoint. You should make sure that the way you define transaction names does not generate more than 1000 transactions per project (the current limit).

Configuring a Transaction Detection Function

Alternatively to setting a transaction name manually, in version 5 of the PHP extension we added a new API \Tideways\Profiler::detectTransactionFunction.

If your application has a factory method for the controller + action and passes this information as a string into the first argument of this function, then you can let Tideways use this string whenever the function is called. For example Symfony uses a class ControllerResolver with a method createController and you could configure it this way:

<?php
use Tideways\Profiler;

if (class_exists('Tideways\Profiler')) {
   Profiler::detectTransactionFunction(
        'Symfony\Component\HttpKernel\ControllerResolver\ControllerResolver::createController'
    );
}
Still need help? Email [email protected]