Fundamental support for the Laravel framework

September 23, 2020

Post

Laravel is one of the most beloved web framework for PHP. It was developed as an alternative to CodeIgniter and today is the most popular PHP project on GitHub based on the amount of stars it has received.

With the PHP tracing extension v1.8.0, Instana introduced full-featured support for the Laravel framework.

A distributed tracing centric view of Laravel Monitoring

Laravel is an MVC framework built around the concepts of controllers, actions, and routes. As a developer, your mental model of how requests are served is expressed in terms of controllers and actions, and which of these are involved largely depends on routes. Because of this, these concepts should be treated as first-class citizens in Instana and you should be able to use your knowledge of your codebase to navigate Instana’s views and drill down into the data it offers you.

Additionally, a large amount of Laravel’s doing in serving your web pages is rendering Blade templates. Understanding how many templates are rendered and which are slow is often key in troubleshooting sluggish performance of your Laravel applications.

What Laravel looks like in Instana

Short answer: it looks good! With Instana’s Unbounded Analytics functionality, it is straightforward to find all the important data about how your Laravel instances are servicing requests. For example, you can easily find every single call of interest to you (because Instana has all of them, no sampling!) segmenting calls by Laravel-specific tags:

Word Image 250

Segmenting calls by Laravel specific tags (Available with our upcoming SaaS release 184)

From there, one click brings you to detailed insights into how your application has served particular requests:

Word Image 251

Single View of the execution of a Laravel HTTP Controller

Routes

The support for Laravel extends to both detecting and categorizing calls by controller and by route. For example, a Laravel application will define HTTP routes like the following:

    Route::get(‘news/{category}/articles/{year}-{month}-{day}-{title}’, ‘[email protected]’);

Previously, in Instana these urls were mapped to separate endpoints such as:

    http://my-host.io/news/bogus-things/articles/2020-08-01-why-does-it-always-have-to-rain
    and
    http://my-host.io/news/australia/articles/1998-04-01-wild-roo-punches-man

Having requests to the same route spread across potentially very many endpoints made it harder to troubleshoot issues. It also made it harder to understand which Laravel controller is acting up or even involved in serving requests. So it could happen that wrongly mapped routes would go unnoticed, and the billing endpoint charges your customers unnoticed.

But those days are over: now, with the Laravel support in Instana, when you declare a route containing placeholders, we will group it by the path containing placeholders. For example, with the following route declared:

    Route::get("news/{category}/articles/{year}-{month}-{day}-{title}", "[email protected]")->name("news.show");

… in Instana it looks like this:

Word Image 252

See exactly which of those input parameters will make your application logic fail.

Blade

Blade is the canonical view engine for Laravel based applications.

In addition to Laravel support, the PHP extension version 1.8.0, traces the execution of Blade templates.

By tracing Blade templates, Instana allows you, out of the box, to track where your application spends its time when it should be spent on rendering a defined set of data.

For example, is there a relation loaded lazily that could have been loaded eagerly when interacting with your Eloquent model in the first place?

Word Image 253

The view is loading the “categories” relation lazily, a 100 times – easy find, fetch the relevant fields eagerly instead.

Or maybe the issue is that your templates invoke over and over the same database query? Easy as pie!

Word Image 254

With this level of insight, by applying some eager-loading when building out your application, we are able to immediately improve on the database calls:

Word Image 255

Happy tracing Laravel and Blade, folks!

Bonus: End User Monitoring

Ever wondered what trouble specific users had? Failed to reproduce a bug that your users reported? Since Instana does capture and store every single call to your application, it’s easy to spot erroneous calls – and when you add our end-user monitoring (EUM) JavaScript agent to your application default layout, you’ll be able get a comprehensive overview of all the calls involved in one pageview and even the option to inspect all the async calls to your endpoints to have a better understanding of the context.
To be able so segment your data by user, you can use the JavaScript Agent API (https://www.instana.com/docs/website_monitoring/api#identifying-users):

    <!-- after including the EUM script -->
    <script>
    @if(Auth::user() !== null)
    
    ineum('user', '{{ Auth::user()->id }}');
    
    @endif
    </script>

Play with Instana’s APM Observability Sandbox

Announcement, Developer, Product
PHP profiling is used by developers to identify performance issues or bottlenecks in their code. Profilers enable developers to drill into individual lines of code to ascertain which ones are running slow...
|
Announcement, Developer, Product
Instana captures a lot of information about activities happening on websites through our website monitoring, also known as end-user or real-user monitoring. Information about page loads, page transitions, HTTP calls, errors and...
|
Announcement, Developer, Product
Instana has been leading the Application Performance Monitoring (APM) industry with our automated distributed tracing technology, AutoTrace™. With AutoTrace, Instana has eliminated the need to manually instrument distributed tracing in your environment....
|

Start your FREE TRIAL today!

As the leading provider of Automatic Application Performance Monitoring (APM) solutions for microservices, Instana has developed the automatic monitoring and AI-based analysis DevOps needs to manage the performance of modern applications. Instana is the only APM solution that automatically discovers, maps and visualizes microservice applications without continuous additional engineering. Customers using Instana achieve operational excellence and deliver better software faster. Visit https://www.instana.com to learn more.