# Console commands



Flare can collect information about the console commands that are being executed. Whether an error happens during a command or you want to trace a long-running command, Flare will collect the following information:

- The command name
- The command arguments
- The exit code

It is possible to disable this behaviour by ignoring commands in the Flare config:

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

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

```php
$config->collectCommands(maxItemsWithErrors: 3);
```

## Ignoring specific commands

You can drop traces for individual commands by name or class. Names are matched against the command identifier (e.g. `horizon:work`), classes are matched against the fully qualified command class.

```php
$config->collectCommands(
    ignoredCommands: ['horizon:*', 'schedule:run'],
    ignoredClasses: [App\Console\Commands\InternalCleanup::class],
);
```

Patterns are literal strings with `*` as a wildcard (the same syntax used by [sampling rules](/docs/php/performance/sampling)). 

When the ignored command is the top-level command, the trace is unsampled. When it runs nested inside another sampled trace (for example, a synchronous subcommand), the recorder skips the inner span and resumes recording afterwards.

## Collecting commands

The command recorder accepts a [command attribute provider](/docs/php/general/attribute-providers). Use the helpers below for the common cases.

```php
$flare->command()->recordStartFromCli('my:command', commandClass: MyCommand::class);
```

For Symfony Console (or framework) commands that hand you an `InputInterface`, use the Symfony helper so the named arguments and options are captured:

```php
$flare->command()->recordStartFromSymfonyInput('my:command', $input, MyCommand::class);
```

When you already have the resolved arguments as an array, use `recordStartFromDefined`:

```php
$flare->command()->recordStartFromDefined(
    command: 'my:command',
    arguments: ['--option' => 'value'],
    commandClass: MyCommand::class,
);
```

The recorder sets the [entry point](/docs/protocol/general/entry-points) for the trace to `cli` and fills in the handler attributes from the command class. You do not need to interact with `EntryPointResolver` directly.

Extra attributes can be passed alongside the standard ones:

```php
$flare->command()->recordStartFromCli('my:command', attributes: [
    'process.pid' => 80,
]);
```

When the command ends (or fails), call `recordEnd` with the exit code:

```php
$flare->command()->recordEnd(exitCode: 0);
```

Extra attributes can be added when the command ends as well:

```php
$flare->command()->recordEnd(exitCode: 0, attributes: [
    'process.pid' => 80,
]);
```
