Flare by Spatie
  • Features
  • Pricing
  • Docs
  • Blog
  • LOG IN
  • START TRACKING
  • Home
  • Features
  • Pricing
  • Docs
  • Blog
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript
  • General
  • Introduction
  • Installation
  • Censoring collected data
  • Ignoring collected data
  • Errors
  • Adding custom context
  • Customising error grouping
  • Handling errors
  • Linking to errors
  • Reporting errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Application lifecycle
  • Cache events
  • Console commands
  • Customise error report
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Logs
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Solutions
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V1

Application lifecycle

Flare can collect the lifecycle events of your application.

There are a few different types of events that can be collected:

  • The whole application runs from start to finish
  • The time it took to register everything in a dependency container
  • The time it took to boot up the application/framework
  • In the end, the time it took to terminate the application

Application lifecycle events are enabled by default and cannot be disabled.

Collecting application lifecycle events

Every application starts with the initialisation of the application:

$flare->applicationLifecycle()->recordStart();

For each lifecycle event, you can also define an additional time when the event happened:

use Carbon\CarbonImmutable;
use Spatie\FlareClient\Time\TimeHelper;

$flare->applicationLifecycle()->recordStart(
    time: TimeHelper::dateTimeToNano(CarbonImmutable::now()),
);

And add extra attributes to the event:

$flare->applicationLifecycle()->recordStart(attributes: [
    'framework.version' => '12'
]);

When your application registers services in the container, you can keep track of it as follows:

$flare->applicationLifecycle()->recordRegistering();

// Register services within the container

$flare->applicationLifecycle()->recordRegistered();

Next up, when your application is booting, you can keep track of it as such:

$flare->applicationLifecycle()->recordBooting();

// Boot your application

$flare->applicationLifecycle()->recordBooted();

Now it's time to run your application, feel free to keep track of requests, jobs, commands, queries, ...:

use Spatie\FlareClient\Time\TimeHelper;

$flare->request()->recordStart();

$flare->query()->record("select * from users", TimeHelper::milliseconds(300), ['id' => 1]);

$flare->request()->recordEnd();

In the end, when your application runs and starts terminating, you can keep track of it as follows:

$flare->applicationLifecycle()->recordTerminating();

// Terminate your application

$flare->applicationLifecycle()->recordTerminated();

When your application is entirely ended, you should call:

$flare->applicationLifecycle()->recordEnd();
Application info Cache events
  • On this page
  • Collecting application lifecycle events

Monitor your web apps and sites from errors to slowdowns with Flare, the easiest application monitoring platform for Laravel, PHP & Javascript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Blog
  • Changelog
  • Documentation
  • Affiliate program
  • Service status
  • Terms of use
  • DPA
  • Privacy & Cookie Policy
Flare