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

Filesystem operations

Flare can collect information about the filesystem operations that your application executes.

You can disable this behaviour by calling ignoreFilesystem() on the Flare config:

$config->ignoreFilesystemOperations();

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

$config->collectFilesystemOperations(maxItemsWithErrors: 10);

Collecting filesystem operations

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

use Spatie\FlareClient\Enums\FilesystemOperation;

$flare->filesystem()->recordOperationStart(
    operation: FilesystemOperation::Exists,
    attributes:  [  
        'filesystem.path' => '/path/to/file.txt',
        
    ]
);

When the operation has finished, you should call the recordOperationEnd method:

$flare->filesystem()->recordOperationEnd(
    operation: FilesystemOperation::Exists,
    attributes:  [  
        'filesystem.exists' => true, 
    ]
);

To make things a bit easier, we've provided a few helper methods to make it easier to record common filesystem operations:

Path

Gets the full filesystem path of a local path:

$flare->filesystem()->recordPath('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method, you can pass a filesystem.full_path attribute with the full path of the file.

Exists

Checks if a file exists:

$flare->filesystem()->recordExists('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.exists attribute with the operation's result.

Get

Gets the contents of a file:

$flare->filesystem()->recordGet('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method, you can pass a filesystem.contents.size attribute with the size of the contents.

Put

Writes the contents to a file:

$flare->filesystem()->recordPut('/path/to/file.txt', 'Hello World');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Prepend

Writes the contents to a file at the beginning:

$flare->filesystem()->recordPrepend('/path/to/file.txt', 'Hello World');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Append

Writes the contents to a file at the end:

$flare->filesystem()->recordAppend('/path/to/file.txt', 'Hello World');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Delete

Deletes a file:

$flare->filesystem()->recordDelete('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Copy

Copies a file:

$flare->filesystem()->recordCopy('/path/to/file.txt', '/path/to/file-copy.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Move

Moves a file:

$flare->filesystem()->recordMove('/path/to/file.txt', '/path/to/file-move.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Size

Gets the size of a file:

$flare->filesystem()->recordSize('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method, you can pass a filesystem.contents.size attribute with the file size.

Files

Gets the files in a directory:

$flare->filesystem()->recordFiles('/path/to/directory');

When getting the files recursively, you can pass a recursive parameter to the recordFiles method:

$flare->filesystem()->recordFiles('/path/to/directory', recursive: true);

When the operation has finished, you should call the recordOperationEnd method, and you can pass a filesystem.found_paths attribute with the paths of the files.

Directories

Gets the directories in a directory:

$flare->filesystem()->recordDirectories('/path/to/directory');

When getting the directories recursively, you can pass a recursive parameter to the recordDirectories method:

$flare->filesystem()->recordDirectories('/path/to/directory', recursive: true);

When the operation has finished, you should call the recordOperationEnd method, and you can pass a filesystem.found_paths attribute with the paths of the directories.

Make Directory

Creates a directory:

$flare->filesystem()->recordMakeDirectory('/path/to/directory');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Delete Directory

Deletes a directory:

$flare->filesystem()->recordDeleteDirectory('/path/to/directory');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

External http requests Git information
  • On this page
  • Collecting filesystem operations

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