Skip to content

Commit

Permalink
Merge branch 'master' of github.com:facade/ignition
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 24, 2021
2 parents a2ad680 + 672d309 commit 1b8b8d6
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 68 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to `ignition` will be documented in this file

## 2.5.14 - 2021-03-03

- fix ignition not working when there is no argv

## 2.5.13 - 2021-02-16

- remove custom grouping

## 2.5.12 - 2021-02-15

- fix wrong config usage (#354)

## 2.5.11 - 2021-02-05

- fix memory leaks caused by log and query recorder (#344)

## 2.5.10 - 2021-02-02

- fix tinker logs not being sent to Flare

## 2.5.9 - 2021-01-26

- fix logged context not being sent to Flare
Expand Down Expand Up @@ -43,6 +63,10 @@ All notable changes to `ignition` will be documented in this file
- add PHP 8.0-dev support
- remove unnecessary `scrivo/highlight.php` dependency

## 2.4.2 - 2021-03-08

- fix `MakeViewVariableOptionalSolution` to disallow stream wrappers and files that do not end in .blade.php (#356)

## 2.4.1 - 2020-10-14

- fix copy casing
Expand Down
2 changes: 2 additions & 0 deletions config/flare.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
'report_query_bindings' => true,
'report_view_data' => true,
'grouping_type' => null,
'report_logs' => true,
'maximum_number_of_collected_logs' => 200,
],

/*
Expand Down
86 changes: 55 additions & 31 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Facade\Ignition;

use Exception;
use Facade\FlareClient\Api;
use Facade\FlareClient\Flare;
use Facade\FlareClient\Http\Client;
use Facade\Ignition\Commands\SolutionMakeCommand;
Expand All @@ -28,7 +29,6 @@
use Facade\Ignition\Middleware\AddLogs;
use Facade\Ignition\Middleware\AddQueries;
use Facade\Ignition\Middleware\AddSolutions;
use Facade\Ignition\Middleware\CustomizeGrouping;
use Facade\Ignition\Middleware\SetNotifierName;
use Facade\Ignition\QueryRecorder\QueryRecorder;
use Facade\Ignition\SolutionProviders\BadMethodCallSolutionProvider;
Expand Down Expand Up @@ -79,6 +79,10 @@ public function boot()
$this->publishes([
__DIR__.'/../config/ignition.php' => config_path('ignition.php'),
], 'ignition-config');

if (isset($_SERVER['argv']) && ['artisan', 'tinker'] === $_SERVER['argv']) {
Api::sendReportsInBatches(false);
}
}

$this
Expand All @@ -91,8 +95,14 @@ public function boot()
$this->setupQueue($this->app->get('queue'));
}

$this->app->make(QueryRecorder::class)->register();
$this->app->make(LogRecorder::class)->register();
if (config('flare.reporting.report_logs')) {
$this->app->make(LogRecorder::class)->register();
}

if (config('flare.reporting.report_queries')) {
$this->app->make(QueryRecorder::class)->register();
}

$this->app->make(DumpRecorder::class)->register();
}

Expand All @@ -107,9 +117,12 @@ public function register()
->registerWhoopsHandler()
->registerIgnitionConfig()
->registerFlare()
->registerLogRecorder()
->registerDumpCollector();

if (config('flare.reporting.report_logs')) {
$this->registerLogRecorder();
}

if (config('flare.reporting.report_queries')) {
$this->registerQueryRecorder();
}
Expand Down Expand Up @@ -280,13 +293,14 @@ protected function getLogLevel(string $logLevelString): int
return $logLevel;
}

protected function registerLogRecorder()
protected function registerLogRecorder(): self
{
$logCollector = $this->app->make(LogRecorder::class);

$this->app->singleton(LogRecorder::class);

$this->app->instance(LogRecorder::class, $logCollector);
$this->app->singleton(LogRecorder::class, function (Application $app): LogRecorder {
return new LogRecorder(
$app,
$app->get('config')->get('flare.reporting.maximum_number_of_collected_logs')
);
});

return $this;
}
Expand Down Expand Up @@ -320,37 +334,45 @@ protected function registerCommands()
return $this;
}

protected function registerQueryRecorder()
protected function registerQueryRecorder(): self
{
$queryCollector = $this->app->make(QueryRecorder::class);

$this->app->singleton(QueryRecorder::class);

$this->app->instance(QueryRecorder::class, $queryCollector);
$this->app->singleton(QueryRecorder::class, function (Application $app): QueryRecorder {
return new QueryRecorder(
$app,
$app->get('config')->get('flare.reporting.report_query_bindings'),
$app->get('config')->get('flare.reporting.maximum_number_of_collected_queries')
);
});

return $this;
}

protected function registerBuiltInMiddleware()
{
$middleware = collect([
$middlewares = [
SetNotifierName::class,
AddEnvironmentInformation::class,
AddLogs::class,
AddDumps::class,
AddQueries::class,
AddSolutions::class,
])
->map(function (string $middlewareClass) {
return $this->app->make($middlewareClass);
});
];

if (config('flare.reporting.collect_git_information')) {
$middleware[] = (new AddGitInformation());
if (config('flare.reporting.report_logs')) {
$middlewares[] = AddLogs::class;
}

$middlewares[] = AddDumps::class;

if (config('flare.reporting.report_queries')) {
$middlewares[] = AddQueries::class;
}

if (! is_null(config('flare.reporting.grouping_type'))) {
$middleware[] = new CustomizeGrouping(config('flare.reporting.grouping_type'));
$middlewares[] = AddSolutions::class;

$middleware = collect($middlewares)
->map(function (string $middlewareClass) {
return $this->app->make($middlewareClass);
});

if (config('flare.reporting.collect_git_information')) {
$middleware[] = (new AddGitInformation());
}

foreach ($middleware as $singleMiddleware) {
Expand Down Expand Up @@ -437,12 +459,14 @@ protected function setupQueue(QueueManager $queue)
$queue->looping(function () {
$this->app->get(Flare::class)->reset();

if (config('flare.reporting.report_logs')) {
$this->app->make(LogRecorder::class)->reset();
}

if (config('flare.reporting.report_queries')) {
$this->app->make(QueryRecorder::class)->reset();
}

$this->app->make(LogRecorder::class)->reset();

$this->app->make(DumpRecorder::class)->reset();
});
}
Expand Down
22 changes: 21 additions & 1 deletion src/LogRecorder/LogRecorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ class LogRecorder
/** @var \Illuminate\Contracts\Foundation\Application */
protected $app;

public function __construct(Application $app)
/** @var int|null */
private $maxLogs;

public function __construct(Application $app, ?int $maxLogs = null)
{
$this->app = $app;
$this->maxLogs = $maxLogs;
}

public function register(): self
Expand All @@ -33,6 +37,10 @@ public function record(MessageLogged $event): void
}

$this->logMessages[] = LogMessage::fromMessageLoggedEvent($event);

if (is_int($this->maxLogs)) {
$this->logMessages = array_slice($this->logMessages, -$this->maxLogs);
}
}

public function getLogMessages(): array
Expand Down Expand Up @@ -68,4 +76,16 @@ public function reset(): void
{
$this->logMessages = [];
}

public function getMaxLogs(): ?int
{
return $this->maxLogs;
}

public function setMaxLogs(?int $maxLogs): self
{
$this->maxLogs = $maxLogs;

return $this;
}
}
27 changes: 0 additions & 27 deletions src/Middleware/CustomizeGrouping.php

This file was deleted.

49 changes: 41 additions & 8 deletions src/QueryRecorder/QueryRecorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ class QueryRecorder
/** @var \Illuminate\Contracts\Foundation\Application */
protected $app;

public function __construct(Application $app)
{
/** @var bool */
private $reportBindings;

/** @var int|null */
private $maxQueries;

public function __construct(
Application $app,
bool $reportBindings = true,
?int $maxQueries = null
) {
$this->app = $app;
$this->reportBindings = $reportBindings;
$this->maxQueries = $maxQueries;
}

public function register()
Expand All @@ -27,13 +38,11 @@ public function register()

public function record(QueryExecuted $queryExecuted)
{
$maximumQueries = $this->app['config']->get('flare.reporting.maximum_number_of_collected_queries', 200);
$this->queries[] = Query::fromQueryExecutedEvent($queryExecuted, $this->reportBindings);

$reportBindings = $this->app['config']->get('flare.reporting.report_query_bindings', true);

$this->queries[] = Query::fromQueryExecutedEvent($queryExecuted, $reportBindings);

$this->queries = array_slice($this->queries, $maximumQueries * -1, $maximumQueries);
if (is_int($this->maxQueries)) {
$this->queries = array_slice($this->queries, -$this->maxQueries);
}
}

public function getQueries(): array
Expand All @@ -51,4 +60,28 @@ public function reset()
{
$this->queries = [];
}

public function getReportBindings(): bool
{
return $this->reportBindings;
}

public function setReportBindings(bool $reportBindings): self
{
$this->reportBindings = $reportBindings;

return $this;
}

public function getMaxQueries(): ?int
{
return $this->maxQueries;
}

public function setMaxQueries(?int $maxQueries): self
{
$this->maxQueries = $maxQueries;

return $this;
}
}
Loading

0 comments on commit 1b8b8d6

Please sign in to comment.