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

External HTTP requests

Flare can collect information about the external HTTP requests that are being made from your application. This includes:

  • The request method
  • The request URL
  • The request body size
  • The request headers
  • The response status code
  • The response body size
  • The response headers

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

$config->ignoreExternalHttp();

You can configure the maximum number of external HTTP requests tracked while collecting data in the case of an error as follows:

$config->collectExternalHttp(maxItemsWithErrors: 10);

It is possible to filter out headers. You can read more about this here.

Collecting Guzzle HTTP requests

Flare can automatically collect Guzzle HTTP requests. This is done by using a middleware that will be added to the Guzzle client:

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Spatie\FlareClient\Recorders\ExternalHttpRecorder\Guzzle\FlareMiddleware;

$stack = HandlerStack::create();

$stack->push(new FlareMiddleware($flare));

$client = new Client([
    'handler' => $stack,
]);

You can also use the FlareHandlerStack, which requires less code:

use Spatie\FlareClient\Recorders\ExternalHttpRecorder\Guzzle\FlareHandlerStack;

$client = new Client([
    'handler' => new FlareHandlerStack($flare)
]);

Manually collecting external HTTP requests

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

$flare->externalHttp()->recordSending(
    url: 'https://example.com',
    method: 'POST',
);

You can also add the size of the request body and the headers:

$flare->externalHttp()->recordSending(
    url: 'https://example.com',
    method: 'POST',
    bodySize: 1234,
    headers: $request->headers,
);

It is also possible to add extra attributes to the request:

$flare->externalHttp()->recordSending(
    url: 'https://example.com',
    method: 'POST',
    attributes: [
        'http.request.cookies' => json_encode($request->cookies),
    ]
);

When the request ends, you can call the recordReceived method:

$flare->externalHttp()->recordReceived(
    statusCode: 200,
);

Here you can also add the size of the response body and the headers:

$flare->externalHttp()->recordReceived(
    responseStatusCode: 200,
    responseBodySize: 1234,
    responseHeaders: $response->headers,
);

Or add extra attributes:

$flare->externalHttp()->recordReceived(
    statusCode: 200,
    attributes: [
        'server.port' => 80,
    ]
);

When the request failed due to a connection error, you can call the recordConnectionFailed method:

$flare->externalHttp()->recordConnectionFailed(
    'Connection refused',
);
Exception context Filesystem operations
  • On this page
  • Collecting Guzzle HTTP requests
  • Manually collecting external HTTP requests

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