Skip to content

Instantly share code, notes, and snippets.

@beberlei
Last active August 12, 2026 21:16
Show Gist options
  • Select an option

  • Save beberlei/ace8e5feae0c797e1de281aa068bbb61 to your computer and use it in GitHub Desktop.

Select an option

Save beberlei/ace8e5feae0c797e1de281aa068bbb61 to your computer and use it in GitHub Desktop.

The event you want is controller_front_send_response_before, dispatched in Magento\Framework\App\Http::launch() right before the response is flushed. It passes the response object (Magento\Framework\App\Response\Http), and it fires late enough that the redirect status/headers are already set on the response but early enough that the Tideways profiler is still active — so renaming the transaction there takes effect.

Here's the full module. Drop it under app/code/Tideways/TransactionNaming/:

app/code/Tideways/TransactionNaming/
├── registration.php
├── etc/
│   ├── module.xml
│   └── events.xml
└── Observer/
    └── SetRedirectTransactionName.php

A few notes:

The response object is Magento\Framework\App\Response\Http (extends the Laminas/PhpEnvironment response), so getStatusCode() is the canonical accessor. The method_exists guard is just cheap defense in case a controller ever hands back a non-HTTP response type on that event.

Result\Redirect::renderResult() calls setRedirect() which sets the status code via setHttpResponseCode(), so by the time this event fires getStatusCode() reliably returns 301/302. This also catches redirects that don't come from a Result\Redirect — e.g. URL-rewrite 301s — since they end up on the same response object.

Then bin/magento setup:upgrade && bin/magento cache:flush to register it.

One thing worth deciding: at global scope this fires on admin redirects too (lots of 302s after form saves). If you only want storefront redirects grouped under redirect, move events.xml to etc/frontend/.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_front_send_response_before">
<observer name="tideways_redirect_transaction_name"
instance="Tideways\TransactionNaming\Observer\SetRedirectTransactionName"/>
</event>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Tideways_TransactionNaming"/>
</config>
<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Tideways_TransactionNaming',
__DIR__
);
<?php
declare(strict_types=1);
namespace Tideways\TransactionNaming\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class SetRedirectTransactionName implements ObserverInterface
{
private const REDIRECT_STATUS_CODES = [301, 302];
public function execute(Observer $observer): void
{
$response = $observer->getEvent()->getResponse();
if ($response === null || !method_exists($response, 'getStatusCode')) {
return;
}
if (!in_array($response->getStatusCode(), self::REDIRECT_STATUS_CODES, true)) {
return;
}
if (class_exists('Tideways\Profiler') && \Tideways\Profiler::getTransactionName() !== null) {
\Tideways\Profiler::setTransactionName('redirect');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment