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.
Automatic Detection for Supported Frameworks
When using one of the supported PHP frameworks and systems, transactions are automatically detected.
Manually Setting Transaction Names
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.
Application using Model-View-Controller (MVC) pattern
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();
}
}
Application with individual PHP scripts
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 = basename(dirname($_SERVER['SCRIPT_NAME'])) . '/' . basename($_SERVER['SCRIPT_NAME']);
if (isset($_GET['mode'])) {
$transactionName .= '?mode=' . $_GET['mode'];
}
Profiler::setTransactionName($transactionName);
}
You should avoid to 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 the limit of 250-5000 transactions per project. |
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'
);
}