Magento 2 Module: Page Type Header Plugin to review requests on New Relic
Recently, I wanted a simple way to check the cache hit ratio for different pages—like product views or category pages—in our Adobe Commerce store using New Relic. Because each page has a unique URL, it was hard to group them by type.
I solved this by adding a custom header using a before plugin on Magento\Framework\App\Response\Http
. Here’s a simple example:
$subject->setHeader('X-Page-Type', $pageType);
This extra header gets logged with each request, making it easier to filter and review cache performance for each page type.
- Log in to the admin panel.
- Go to Stores > Configuration.
- Expand the "Advanced" section and click on "System".
- Under the "Full Page Cache" section, expand "Fastly Configuration".
- Go to "Tools > Real-Time Log Streaming".
- Find the endpoint for New Relic Logs and edit it.
- Add the field with your header, example:
"page_type": "%{resp.http.x-page-type}V",
- Click "Update", then "Upload VCL to Fastly".
This small change makes it much easier to monitor cache hits by page type using New Relic in Adobe Commerce.