Skip to content

Commit

Permalink
More docs (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz authored Jan 8, 2024
1 parent 8805959 commit e8d625e
Show file tree
Hide file tree
Showing 11 changed files with 639 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
- [Log Collector](./collector/logger.md)
- [Event Collector](./collector/event-dispatcher.md)
- [HttpClient Collector](./collector/http-client.md)
- [Exception Collector](./collector/exception.md)

### Web collectors
- [Middleware Collector](collector/web/middleware.md)
- [Request Collector](collector/web/request.md)
- [WebAppInfo Collector](collector/web/web-app-info.md)

### Console collectors
- [Command Collector](collector/console/command.md)
- [ConsoleAppInfo Collector](collector/console/console-app-info.md)

## Console commands
- [`debug:reset`](./command-reset.md)
Expand Down
82 changes: 82 additions & 0 deletions docs/en/collector/console/command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# [Command collector](./../../../../src/Collector/Console/CommandCollector.php)

`CommandCollector` collects all data about an executed console command.

It uses the following events to collect data:
- [`\Symfony\Component\Console\Event\ConsoleCommandEvent`](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Console/Event/ConsoleCommandEvent.php)
- [`\Symfony\Component\Console\Event\ConsoleTerminateEvent`](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Console/Event/ConsoleTerminateEvent.php)
- [`\Symfony\Component\Console\Event\ConsoleErrorEvent`](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Console/Event/ConsoleErrorEvent.php)

## Collected data

### Common

Example:

`console/commands.php`

```php
return [
'app:hello' => \App\Command\HelloCommand::class,
];
```

`App\Command\HelloCommand`

```php
final class HelloCommand extends Command
{
protected static $defaultName = 'app:hello';

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Hello world!');
return 0;
}
}
```

Output:

```json
{
"Symfony\\Component\\Console\\Event\\ConsoleCommandEvent": {
"name": "app:hello",
"command": "object@App\\Command\\HelloCommand#8454",
"input": "'app:hello'",
"output": "",
"arguments": {
"command": "object@Symfony\\Component\\Console\\Input\\InputArgument#8532"
},
"options": {
"help": "object@Symfony\\Component\\Console\\Input\\InputOption#8523",
"quiet": "object@Symfony\\Component\\Console\\Input\\InputOption#8520",
"verbose": "object@Symfony\\Component\\Console\\Input\\InputOption#8524",
"version": "object@Symfony\\Component\\Console\\Input\\InputOption#8522",
"ansi": "object@Symfony\\Component\\Console\\Input\\InputOption#8521",
"no-interaction": "object@Symfony\\Component\\Console\\Input\\InputOption#8517",
"config": "object@Symfony\\Component\\Console\\Input\\InputOption#40"
}
},
"Symfony\\Component\\Console\\Event\\ConsoleTerminateEvent": {
"name": "app:hello",
"command": "object@App\\Command\\HelloCommand#8454",
"input": "'app:hello'",
"output": "Hello world!\n",
"exitCode": 0
}
}
```

### Summary

```json
{
"command": {
"name": "app:hello",
"class": "App\\Command\\HelloCommand",
"input": "'app:hello'",
"exitCode": 0
}
}
```
71 changes: 71 additions & 0 deletions docs/en/collector/console/console-app-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# [ConsoleAppInfo collector](./../../../../src/Collector/Console/ConsoleAppInfoCollector.php)

`ConsoleAppInfoCollector` collects information about the application.

It uses the following events to collect data:
- [`\Yiisoft\Yii\Console\Event\ApplicationStartup`](https://github.com/yiisoft/yii-console/blob/master/src/Event/ApplicationStartup.php)
- [`\Yiisoft\Yii\Console\Event\ApplicationShutdown`](https://github.com/yiisoft/yii-console/blob/master/src/Event/ApplicationShutdown.php)
- [`\Symfony\Component\Console\Event\ConsoleCommandEvent`](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Console/Event/ConsoleCommandEvent.php)
- [`\Symfony\Component\Console\Event\ConsoleTerminateEvent`](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Console/Event/ConsoleTerminateEvent.php)
- [`\Symfony\Component\Console\Event\ConsoleErrorEvent`](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Console/Event/ConsoleErrorEvent.php)

## Collected data

### Common

Example:

`console/commands.php`

```php
return [
'app:hello' => \App\Command\HelloCommand::class,
];
```

`App\Command\HelloCommand`

```php
final class HelloCommand extends Command
{
protected static $defaultName = 'app:hello';

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Hello world!');
return 0;
}
}
```

Output:

```json
{
"applicationProcessingTime": 0.016509056091308594,
"preloadTime": -0.014687061309814453,
"applicationEmit": 0.0016329288482666016,
"requestProcessingTime": 0.00018906593322753906,
"memoryPeakUsage": 16445144,
"memoryUsage": 16347512
}
```

### Summary

```json
{
"console": {
"php": {
"version": "8.2.8"
},
"request": {
"startTime": 1704625438.335058,
"processingTime": 0.00018906593322753906
},
"memory": {
"peakUsage": 20338080
}
}
}
```
4 changes: 3 additions & 1 deletion docs/en/collector/event-dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Output:

```json
{
"total": 1
"event": {
"total": 1
}
}
```
88 changes: 88 additions & 0 deletions docs/en/collector/exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# [Exception collector](./../../../src/Collector/ExceptionCollector.php)

`ExceptionCollector` collects all data about an exception that was not caught by the application.

It uses [`\Yiisoft\ErrorHandler\Event\ApplicationError`](https://github.com/yiisoft/error-handler/blob/master/src/Event/ApplicationError.php) event to collect data.

## Collected data

### Common

Example:

```php
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withController($this);
}

public function index(LoggerInterface $logger): ResponseInterface
{
throw new \Exception('Hello, world!');
return $this->viewRenderer->render('index');
}
}

```

Output:

```json
[
{
"class": "Exception",
"message": "Hello, world!",
"file": ".../demo\/blog\/src\/Controller\/SiteController.php",
"line": 19,
"code": 0,
"trace": [
{
"function": "index",
"class": "App\\Controller\\SiteController",
"type": "->",
"args": [
"object@HttpSoft\\Message\\ServerRequest#8094",
"object@App\\Handler\\NotFoundHandler#8503"
]
},
// long long stack trace
// ...
{
"file": ".../demo\/blog\/vendor\/yiisoft\/yii-runner-http\/src\/HttpApplicationRunner.php",
"line": 144,
"function": "handle",
"class": "Yiisoft\\Yii\\Http\\Application",
"type": "->",
"args": [
"object@HttpSoft\\Message\\ServerRequest#8354"
]
},
{
"file": ".../demo\/blog\/public\/index.php",
"line": 40,
"function": "run",
"class": "Yiisoft\\Yii\\Runner\\Http\\HttpApplicationRunner",
"type": "->",
"args": []
}
],
"traceAsString": "..." // same long stack trace, but as a string
}
]
```

### Summary

```json
{
"exception": {
"class": "Exception",
"message": "Hello, world!",
"file": ".../demo\/blog\/src\/Controller\/SiteController.php",
"line": 19,
"code": 0
}
}
```
6 changes: 4 additions & 2 deletions docs/en/collector/http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Output:

```json
{
"count": 1,
"totalTime": 0.14657306671142578
"http": {
"count": 1,
"totalTime": 0.14657306671142578
}
}
```
4 changes: 3 additions & 1 deletion docs/en/collector/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Output:

```json
{
"total": 2
"logger": {
"total": 2
}
}
```
4 changes: 3 additions & 1 deletion docs/en/collector/var-dumper.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Output:

```json
{
"total": 3
"var-dumper": {
"total": 3
}
}
```
Loading

0 comments on commit e8d625e

Please sign in to comment.