# Requests



Flare can collect information about the requests being made to your application. This includes:

- The request method
- The request URL
- The body size & contents
- The user agent
- The IP address of the user
- The request headers
- The request cookies
- The request query parameters
- The request files
- The request session data

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

```php
$config->ignoreRequests();
```

It is possible to filter out fields from the request body, headers, and the user's IP address. You can read more about this [here](/docs/php/general/censoring-collected-data).

## Ignoring specific requests

You can drop traces for individual URLs, paths, or routes by passing patterns to `collectRequests()`. When a request matches one of these patterns, the trace is unsampled and no spans are sent for it.

```php
$config->collectRequests(
    ignoredRoutes: ['horizon.*', 'telescope.*'],
    ignoredUrls: ['https://example.com/internal/*'],
    ignoredPaths: ['/health-check', '/metrics/*'],
);
```

Patterns are literal strings with `*` as a wildcard (the same syntax used by [sampling rules](/docs/php/performance/sampling)). Routes are matched once the framework has resolved the route name, so route patterns are evaluated through deferred sampling.

## Collecting requests

In our framework-specific versions of the Flare clients, requests are automatically traced to find performance issues.

In the framework-agnostic version of the package, your integration is responsible for calling the request recorder. The recorder accepts an [attribute provider](/docs/php/general/attribute-providers); use the helpers below for the common cases.

The trace itself is opened through `$flare->start()` (or the granular [lifecycle](/docs/php/general/application-lifecycle) methods for framework integrators), not directly on the tracer. A typical request flow looks like this:

```php
$flare->start();

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

// Handle your request

$flare->request()->recordEndFromDefined(statusCode: 200);

$flare->end();
```

`recordStartFromGlobals()` builds a `PhpRequestAttributesProvider` from the PHP superglobals (`$_GET`, `$_POST`, `$_COOKIE`, `$_SERVER`, and so on). For frameworks built on Symfony's HttpFoundation, use the Symfony helper instead:

```php
$flare->request()->recordStartFromSymfonyRequest($request);
```

For any other request object, implement `RequestAttributesProvider` and pass it to `recordStart()`:

```php
$flare->request()->recordStart(new YourRequestAttributesProvider($request));
```

Flare tries to group requests based on URLs. While this is useful, as soon as you have id's within your URL, this can be a problem.

For example, `blog/1` and `blog/2` are the same route; they show a blog post, yet due to their different id's, they will be grouped as different requests.

To group these requests together, supply a `RouteAttributesProvider` when ending the request (or call the [routing recorder](/docs/php/data-collection/routing) when your framework resolves the route):

```php
use Spatie\FlareClient\AttributesProviders\PhpRouteAttributesProvider;

$flare->request()->recordEnd(
    routeAttributesProvider: new PhpRouteAttributesProvider('blog/{id}', method: 'GET'),
);
```

The class (or closure) that handled the request is captured through the [entry point](/docs/protocol/general/entry-points) system. Most integrations do not need to set it manually: the [routing recorder](/docs/php/data-collection/routing) and the request providers fill it in. If you do need to populate it from a custom provider, implement `EntryPointHandlerProvider` alongside your `RequestAttributesProvider`.

You can also pass extra attributes alongside the standard ones:

```php
$flare->request()->recordStart(
    new YourRequestAttributesProvider($request),
    attributes: [
        'server.port' => 80,
    ],
);
```

When ending the request, you can pass a response provider so the response status code, body size, and headers are recorded:

```php
$flare->request()->recordEndFromSymfonyResponse($response);

$flare->request()->recordEndFromDefined(statusCode: 200, bodySize: 1234);
```
