Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript React React Vue Vue Protocol Protocol
  • General
  • Installation
  • Integrating into a framework
  • Attribute providers
  • Application lifecycle
  • Censoring collected data
  • Ignoring collected data
  • Flare daemon
  • Errors
  • Introduction
  • Customise error report
  • Customising error grouping
  • Linking to errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Custom context
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Jobs and queues
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V2
  • Flare Client PHP V1

Introduction

Flare allows you to run performance monitoring on your application. This means you can see how long certain parts of your code take to execute.

To do this, we'll follow the Open Telemetry tracing standard. Let's give you a quick introduction:

An application always starts a trace for every request, command or job. A sampler decides whether a trace will be sampled based on the sampling rate and a randomiser. When a trace is sampled, spans will be recorded for the trace. A span is a work unit executed within a trace. A span can have a parent span, which means that the span is executed within the timeframe of another span. A span always has a start and end time. Whenever a time-based event happens within a span (with only a single timestamp and no specific start or end time), then we'll call such an event a span event. Sometimes a trace is distributed over multiple machines/services, think a request triggering a queued job. In such a case, the application sends the trace_id, span_id and sampling decision to the next server/service to continue the trace, we call this propagation.

That's it, you're now a tracing expert!

Enabling performance monitoring

Performance monitoring is enabled by default.

Starting traces

You can start a trace by using the lifecycle:

$flare->lifecycle->start();

Now it's time to run your application and additional spans, more on that later.

When your application exits, you should end the lifecycle as such:

$flare->lifecycle->terminated();

This will close the trace and send it to Flare.

The lifecycle manages trace creation, sampling decisions and flushing data automatically. It also supports distributed tracing via traceparents and subtask-based lifecycles for queue workers. You can read more about the lifecycle here.

Collecting spans & span events

We've got a complete chapter on collecting data for Flare, from queries to logs to external HTTP calls. While it is technically possible to create your own spans and span events, we recommend using the built-in data collectors.

For example, tracing a query is as simple as:

use Spatie\FlareClient\Time\TimeHelper;

$config->collectQueries();

$flare->query()->record(
    sql:'SELECT * FROM users WHERE id = ?',
    duration: TimeHelper::milliseconds(300),
    bindings: [1],
    databaseName: 'Flare',
    driverName: 'mysql'
);

When recording this span, the end time will be the current time, and the start time will be the current time minus the duration.

Notice the TimeHelper? Open telemetry collects the duration in nanoseconds, but PHP can only keep track of milliseconds. The TimeHelper will convert the milliseconds to nanoseconds for you.

We have excellent documentation on traces, spans, span events, and propagation. You can read it here.

Disabling performance monitoring

Sometimes you might not want to enable performance monitoring for your application. This can be done as such:

$config->trace(false);
With errors Sampling
  • On this page
  • Enabling performance monitoring
  • Starting traces
  • Collecting spans & span events
  • Disabling performance monitoring

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by
Flare