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

Queries

Flare can collect information about the queries being executed in your application. This includes:

  • The query
  • The query bindings
  • The database name
  • The database driver

This functionality is enabled by default, but you can disable it by calling ignoreQueries() on the Flare config:

$config->ignoreQueries();

You can configure the maximum number of queries tracked while collecting data in the case of an error as such:

$config->collectQueries(maxItemsWithErrors: 10);

Collecting queries

We cannot automatically collect queries in the framework-agnostic version of the package. You can manually add queries as such:

use Spatie\FlareClient\Time\TimeHelper;

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

The duration should be in milliseconds. When you don't want to pass the duration, you can use the recordStart and recordEnd methods:

$flare->query()->recordStart(
    query: 'SELECT * FROM users WHERE id = ?',
    bindings: [1],
    databaseName: 'mysql',
    driverName: 'mysql',
);

// Do your query

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

It is always possible to add extra attributes to the query:

use Spatie\FlareClient\Time\TimeHelper;

$flare->query()->record(
    query: 'SELECT * FROM users WHERE id = ?',
    duration: TimeHelper::millisecond(300),
    bindings: [1],
    databaseName: 'mysql',
    driverName: 'mysql',
    attributes: [
        'database.connection' => 'mysql',
    ]
);

Finding the origin

Database queries sometimes become a bit tricky to debug. You can find the origin of the query by setting the findOrigin parameter to true:

$config->collectQueries(findOrigin: true);

Now, every query will include the file and line number where the query was executed.

If you only want to find the origins of slow queries, you can pass a findOriginThreshold parameter to the collectQueries method in milliseconds:

$config->collectQueries(findOriginThreshold: TimeHelper::milliseconds(100));

Now, only queries that take longer than 100 milliseconds will include the file and line number where the query was executed. By default, queries slower than 300 milliseconds will be collected.

Be careful not to set this threshold too low, as it can cause a lot of overhead in your application.

Small note, don't set findOrigin when using findOriginThreshold, as this will cause the Flare client to always look for the origin of the query, even if it is not slow.

Bindings

When you're passing bindings alongside your query, Flare will automatically collect them. You can also pass the bindings manually.

You can either not pass bindings at all, or disable sending query bindings as such:

$config->collectQueries(includeBindings: false);
Jobs and queues Redis commands
  • On this page
  • Collecting queries
  • Finding the origin
  • Bindings

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