Transactions

Monitoring and Profiling yields much better data if you can assign a transaction name to every request that is triggered in your application. If you don't do this, then every transaction will automatically get the name 'default' in version 4 and the SCRIPT_FILENAME (for example index.php) in version 5.

If you are using an MVC framework with controllers and actions, then a separation into the controller class and action method names for the transaction names yields much better results.

Compare these two results that you get on your application dashboard, the first one using only default transaction:

Without Transaction Names

and the second one collecting data with transaction names:

With Transaction Names

Adding transaction names allows you to see bottlenecks, number of requests and response times for each of these transaction individually, including historical data and graphs. Additionally it will group the profiling traces based on these transactions.

There are two approaches to configuring transaction names.

Configuring a Supported Framework

When you are using one of 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.

For version 4 you need to configure the framework, for example a Wordpress application using either a global INI setting or a PHP function:

tideways.framework=wordpress

Or in a PHP function:

<?php

\Tideways\Profiler::detectTransaction('wordpress');
\Tideways\Profiler::start(/*   */);

You can find a list of the supported frameworks in the Setup help of your application.

Manually Setting Transaction Names

If you don't use a supported framework, use XHProf or HHVM you must 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
    
    if (class_exists('Tideways\Profiler')) {
        $transactionName = $_SERVER['SCRIPT_NAME'];
        if (isset($_GET['mode'])) {
            $transactionName .= '?mode=' . $_GET['mode'];
        }
        \Tideways\Profiler::setTransactionName($transactionName);
    }
    	

You should not pass in fully dynamic URLs as transaction names. An endpoint describes the same kind of code being executed, indepenent 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 application (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
if (class_exists('Tideways\Profiler')) {
   \Tideways\Profiler::detectTransactionFunction(
        'Symfony\Component\HttpKernel\ControllerResolver\ControllerResolver::createController'
    );
}

Configuring Human Readable Names

After you have started using transction names based on framework or manual support you can go one step further with the configuration and set a human readable name for all the transacations, or just the ones you care about the most. This will improve the utility of Tideways, because it frees you from having to know what page each listed controller/action is actually responsible for, especially for the non-technical users in the weekly report.

For example in the transaction list:

Or in the transaction detail page:

You can configure the human readable names in the "Application Settings" screen, then click on "Configure Transactions".

Click on the pencil button on the right to open a dialog for each transaction, where you can enter the human readable name of the transaction and then save your change.

Still need help? Write [email protected] Write [email protected]