Tinkerwell - The PHP Scratchpad

Laravel Vapor application observability with Inspector

Published on by

Laravel Vapor application observability with Inspector image

Recently, more and more Inspector customers are writing to me for advice on how to integrate our observability platform to monitor their Laravel application deployed in the AWS serverless environment with Vapor.

So I decided to write an extended tutorial for the different options you have to use Inspector to monitor your serverless Laravel application.

Let me start by giving you a bit of context.

What is Inspector? When should you take it into consideration?

Inspector is a composer package to add real-time code execution monitoring to your Laravel application. It allows you to work on continuous code changes while catching bugs and bottlenecks automatically. Before your users do.

To be honest, not all software development teams need to monitor their applications "professionally". You have to experience the pain of not having a monitoring tool on your skin before you decide to invest in it.

Monitoring is the way to connect developers to the customers experience, to make them accountable for the success of the software development project.

You don't need a monitoring tool if:

  • You don't care about the users – Maybe they're not paying you, and the decision to adopt a monitoring system rests with the company you work for as a consultant.
  • The application you are working on, doesn't generate income to sustain your business – Many projects are managed only to make a customer happy, from which, however, you earn little or nothing.
  • You work for short-term projects – If the project you are working on has a short duration by nature, it is useless to waste time with monitoring.

Monitoring is to take care of your customers over time and protect the sources of income that are important to grow your business. If this resonates with you check out our website for more information: https://inspector.dev/laravel

How to make Inspector work on Laravel Vapor

The serverless environment has different default settings than a normal LAMP server. So the integration in the Vapor environment depends on the type of runtime you use.

You can learn more about Vapor runtimes in this official video lesson.

Inspector requires two native PHP functions to send monitoring data to the remote API: proc_open, and proc_close. So the integration depends by the type of runtime you use for your Vapor application.

Use Docker runtime (recommended)

Docker based runtimes offer much more control over the configuration of the execution environment. You can deploy applications up to 10GB in size and it allows you to install additional PHP extensions or libraries.

In order to use a Docker image instead of the Vapor native runtimes, set the runtime configuration option to docker within your vapor.yml.

id: 2
name: vapor-laravel-app
environments:
production:
runtime: docker # Use docker as runtime environment
build:
- 'composer install --no-dev'

Learn more about Docker runtime in Vapor.

To make Inspector work you must be sure that the current PHP installation in the Docker image has proc_open, and proc_close php native functions enabled.

The default Docker runtime should have these functions enabled by default. In alternative you need to create a custom php.ini file in your project root directory with these two functions not listed in the disable_functions parameter:

disable_functions=exec,passthru,shell_exec,system,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

Add the entry below to your environment .Dockerfile to override the default php.ini configuration:

# Update the `php.ini` file...
# Requires a `php.ini` file at the root of your project...
COPY ./php.ini /usr/local/etc/php/conf.d/overrides.ini

Use Vapor native runtimes

The AWS standard serverless environment has the proc_open and proc_close functions disabled by default. So Inspector isn't able to send data to the inspection API with the standard transport class included in the package.

In a normal server environment you can enable these functions by changing the php.ini settings, but Vapor native runtimes currently don't provide a way to overwrite this configuration during deployment, so you can’t enable them.

Set up a custom transport

The design of the Inspector package allows you to inject a custom transport implementation at runtime. Add the code below in the boot method of your ApplicationServiceProvider:

$this->app->inspector->setTransport(function ($configuration) {
return new QueueTransport($configuration);
});

The callback will receive an instance of the Inspector\Configuration class, that contains the Ingestion Key, the URL of our remote API, and all other information needed to build the appropriate HTTP call.

QueueTransport implementation

To keep the data sending process "asynchronously" the QueueTransport class should schedule a job to send monitoring data in background:

namespace App\Inspector\Transports;
 
 
use Exception;
use Inspector\Transports\AbstractApiTransport;
use Inspector\Transports\TransportInterface;
use App\Inspector\Jobs\SendInspectorChunkJob;
 
class QueueTransport extends AbstractApiTransport implements TransportInterface
{
/**
* @param string $data
* @throws Exception
*/
protected function sendChunk($data)
{
dispatch(new SendInspectorChunkJob($this->config, $data));
}
}

SendInspectorChunkJob receives the data in its constructor to be sent when the job is scheduled for execution. Here is the implementation of the Job:

namespace App\Inspector\Jobs;
 
 
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Inspector\Transports\AbstractApiTransport;
use Inspector\Transports\TransportInterface;
use Inspector\Configuration;
 
class SendInspectorChunkJob implements ShouldQueue
{
use Queueable;
 
/**
* Monitoring Data
*
* @var string
*/
protected $data;
 
/**
* Inspector configuration.
*
* @var Configuration
*/
protected $configuration;
 
/**
* SendInspectorChunkJob constructor.
*
* @param Configuration $configuration
* @param string $data
*/
public function __construct(Configuration $configuration, string $data)
{
$this->data = $data;
$this->configuration = $configuration;
}
 
/**
* Use the original CurlTransport.
*
* @param \Inspector\Configuration $configuration
* @throws \Inspector\Exceptions\InspectorException
*/
public function handle()
{
$transport = new \Inspector\Transports\CurlTransport($this->configuration);
 
$transport->sendChunk($this->data);
}
}

Avoid the infinite loop

Finally, we must inform Inspector to ignore the SendInspectorChunkJob from monitoring. Otherwise when the job is executed it will run a new transaction itself that generates another job and so on… the infinite loop start.

Inspector provides a configuration property to specify the job classes that you want to exclude from monitoring.

Publish the inspector config file if you haven't already done, using the command below:

php artisan vendor:publish --provider="Inspector\Laravel\InspectorServiceProvider"

Now you should have the inspector.php file in your config directory. Add the SendInspectorChunkJob:

/*
|--------------------------------------------------------------------------
| Job classes to ignore
|--------------------------------------------------------------------------
|
| Add at this list the job classes that you don't want monitoring
| in your Inspector dashboard.
|
*/
 
'ignore_jobs' => [
\App\Inspector\Jobs\SendInspectorChunkJob::class,
],

Running the job to send data will consume additional execution resources on your AWS account. For this reason we strongly encourage you to consider using the Docker runtime that natively support, the built-in transport method with no additional costs.

Conclusion

Vapor allows you to move to a serverless execution environment for your application with ease. Anyway the serverless environment can require some adjustments to your application to be able to work in this new execution context.

The same is for the other part of your tech stack including monitoring.

Inspector is designed to work with a simple software library. It's not installed on the underlying infrastructure, so you are free to customize your integration as per your needs, no matter what infrastructure you use.

Navigate to our website for more information or drop in a live chat if you need help. We are happy to support you and your team to avoid losing customers and money due to unexpected technical errors in your application.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Speeding Up Laravel News With Cloudflare image

Speeding Up Laravel News With Cloudflare

Read article
Livewire 4 Support in Laravel VS Code Extension v1.4.3 image

Livewire 4 Support in Laravel VS Code Extension v1.4.3

Read article
Fair Queue Distribution with Laravel Balanced Queue image

Fair Queue Distribution with Laravel Balanced Queue

Read article
Migrating Laravel News from Laravel Forge to Cloud image

Migrating Laravel News from Laravel Forge to Cloud

Read article
Laravel News Is the Live Stream Partner for Laracon EU 2026 image

Laravel News Is the Live Stream Partner for Laracon EU 2026

Read article
Query Builder Expression Aliases in Laravel 12.48 image

Query Builder Expression Aliases in Laravel 12.48

Read article