Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds projects support #150

Merged
merged 21 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code refactoring
1. Reduced payload size for preview cards in WS events, optimizing data transmission to clients and HTTP requests for event lists.
2. Resolved issue with event clearing when utilizing the database driver.
3. Addressed sorting inconsistencies with events when utilizing the database driver.
  • Loading branch information
butschster committed Apr 28, 2024
commit 499d24a9de0600b8be81e55964bdf1af8d1429d2
31 changes: 17 additions & 14 deletions app/database/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Database\Factory\Partials\SmtpType;
use Database\Factory\Partials\VarDumperType;
use Modules\Events\Domain\Event;
use Modules\Events\Domain\ValueObject\Timestamp;
use Modules\Projects\Domain\ValueObject\Key;
use Spiral\DatabaseSeeder\Factory\AbstractFactory;

Expand All @@ -39,22 +40,10 @@ public function definition(): array
{
$type = $this->faker->randomElement(['sentry', 'monolog', 'var-dump', 'inspector', 'ray', 'profiler']);

$payload = match ($type) {
'sentry' => self::getSentryPayload(),
'monolog' => self::getMonologPayload(),
'var-dump' => self::getVarDumperPayload(),
'inspector' => self::getInspectorPayload(),
'ray' => self::getRayPayload(),
'profiler' => self::getProfilerPayload(),
'smtp' => self::getSmtpPayload(),
default => ['foo' => 'bar'],
};

return [
'uuid' => Uuid::generate(),
'type' => $this->faker->randomElement(['sentry', 'monolog', 'var-dump', 'inspector', 'ray', 'profiler']),
'payload' => new Json($payload),
'timestamp' => \microtime(true),
'timestamp' => Timestamp::create(),
'project' => null,
];
}
Expand All @@ -65,9 +54,23 @@ public function makeEntity(array $definition): object
return new Event(
uuid: $definition['uuid'],
type: $definition['type'],
payload: $definition['payload'],
payload: new Json($this->getPayload($definition['type'])),
timestamp: $definition['timestamp'],
project: $definition['project'] ? Key::create($definition['project']) : null,
);
}

public function getPayload(string $type): array
{
return match ($type) {
'sentry' => self::getSentryPayload(),
'monolog' => self::getMonologPayload(),
'var-dump' => self::getVarDumperPayload(),
'inspector' => self::getInspectorPayload(),
'ray' => self::getRayPayload(),
'profiler' => self::getProfilerPayload(),
'smtp' => self::getSmtpPayload(),
default => ['foo' => 'bar'],
};
}
}
282 changes: 258 additions & 24 deletions app/database/Factory/Partials/InspectorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,271 @@ protected static function getInspectorPayload(): array
return [
[
'model' => 'transaction',
'name' => '/foo',
'type' => 'process',
'hash' => '979ffbcecfcd3a72c1c4d536aa1fe85b3e996df1d7093755b9b4a1ded8e33b5c',
'host' =>
[
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
'name' => 'http:https://127.0.0.1:8080/blog/post/1',
'type' => 'request',
'hash' => 'a78992af325ea2335d102726ad8bc323a8ffcb5e4a004df9633f988a24c6fd4c',
'host' => [
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'http' => [
'request' => [
'method' => 'GET',
'version' => 'unknown',
'socket' => [
'remote_address' => '127.0.0.1',
],
],
'url' => [
'protocol' => 'http',
'path' => 'app.php',
'search' => '?',
],
'timestamp' => 1701464039.650622,
'memory_peak' => 15.53,
'duration' => 0.22,
],
'timestamp' => 1714336189.047214,
'memory_peak' => 17.08,
'duration' => 2.73,
],
[
'model' => 'segment',
'type' => 'my-process',
'host' =>
[
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
'type' => 'App\\\\Middleware\\\\InspectorMiddleware',
'host' => [
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'transaction' => [
'name' => 'http:https://127.0.0.1:8080/dump1',
'hash' => 'a78992af325ea2335d102726ad8bc323a8ffcb5e4a004df9633f988a24c6fd4c',
'timestamp' => 1714336189.047214,
],
'start' => 0.07,
'timestamp' => 1714336189.047291,
'duration' => 1.49,
],
[
'model' => 'segment',
'type' => 'exception',
'label' => 'Test exception',
'host' => [
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'transaction' => [
'name' => 'http:https://127.0.0.1:8080/dump1',
'hash' => 'a78992af325ea2335d102726ad8bc323a8ffcb5e4a004df9633f988a24c6fd4c',
'timestamp' => 1714336189.047214,
],
'start' => 1.65,
'timestamp' => 1714336189.048868,
'context' => [
'Error' => [
'model' => 'error',
'timestamp' => 1714336189.048884,
'host' => [
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'message' => 'Test exception',
'class' => 'Exception',
'file' => '/root/repos/spiral-apps/filters-bridge/app/src/Middleware/InspectorMiddleware.php',
'line' => 32,
'code' => 0,
'stack' => [
[
'class' => 'App\\Middleware\\InspectorMiddleware',
'function' => 'process',
'args' => [],
'type' => '->',
'file' => '/root/repos/spiral-apps/filters-bridge/app/src/Middleware/InspectorMiddleware.php',
'line' => 32,
'code' => [
[
'line' => 29,
'code' => ' $response = $this->inspector->addSegment(function ($segment) use ($handler, $request) {',
],
[
'line' => 30,
'code' => ' return $handler->handle($request);',
],
[
'line' => 31,
'code' => ' }, self::class);',
],
[
'line' => 32,
'code' => '',
],
[
'line' => 33,
'code' => ' $this->inspector->reportException(new \\Exception(\'Test exception\'));',
],
[
'line' => 34,
'code' => '',
],
[
'line' => 35,
'code' => ' $this->inspector->flush();',
],
[
'line' => 36,
'code' => '',
],
[
'line' => 37,
'code' => ' dump($this->inspector);',
],
[
'line' => 38,
'code' => '',
],
],
],
[
'class' => 'Spiral\\Http\\Pipeline',
'function' => 'Spiral\\Http\\{closure}',
'args' => [],
'type' => '->',
'file' => '[internal]',
'line' => '0',
'code' => [],
],
[
'class' => 'ReflectionFunction',
'function' => 'invokeArgs',
'args' => [],
'type' => '->',
'file' => '/root/repos/spiral-apps/filters-bridge/vendor/spiral/framework/src/Core/src/Internal/Invoker.php',
'line' => 74,
'code' => [
[
'line' => 71,
'code' => ' throw new ContainerException($e->getMessage(), $e->getCode(), $e);',
],
[
'line' => 72,
'code' => ' }',
],
[
'line' => 73,
'code' => '',
],
[
'line' => 74,
'code' => ' // Invoking Closure with resolved arguments',
],
[
'line' => 75,
'code' => ' return $reflection->invokeArgs(',
],
[
'line' => 76,
'code' => ' $this->resolver->resolveArguments($reflection, $parameters)',
],
[
'line' => 77,
'code' => ' );',
],
[
'line' => 78,
'code' => ' }',
],
[
'line' => 79,
'code' => '',
],
[
'line' => 80,
'code' => ' throw new NotCallableException(\'Unsupported callable.\');',
],
],
],
],
'transaction' => [
'name' => 'http:https://127.0.0.1:8080/dump1',
'hash' => 'a78992af325ea2335d102726ad8bc323a8ffcb5e4a004df9633f988a24c6fd4c',
],
'handled' => true,
],
'transaction' =>
],
'duration' => 1.05,
],
[
'model' => 'error',
'timestamp' => 1714336189.048884,
'host' => [
'hostname' => 'ButschsterLpp',
'ip' => '127.0.1.1',
'os' => 'Linux',
],
'message' => 'Test exception',
'class' => 'Exception',
'file' => '/root/repos/spiral-apps/filters-bridge/app/src/Middleware/InspectorMiddleware.php',
'line' => 32,
'code' => 0,
'stack' => [
[
'name' => '/foo',
'hash' => '979ffbcecfcd3a72c1c4d536aa1fe85b3e996df1d7093755b9b4a1ded8e33b5c',
'timestamp' => 1701464039.650622,
'class' => 'App\\Middleware\\InspectorMiddleware',
'function' => 'process',
'args' =>
[
],
'type' => '->',
'file' => '/root/repos/spiral-apps/filters-bridge/app/src/Middleware/InspectorMiddleware.php',
'line' => 32,
'code' => [
[
'line' => 29,
'code' => ' $response = $this->inspector->addSegment(function ($segment) use ($handler, $request) {',
],
[
'line' => 30,
'code' => ' return $handler->handle($request);',
],
[
'line' => 31,
'code' => ' }, self::class);',
],
[
'line' => 32,
'code' => '',
],
[
'line' => 33,
'code' => ' $this->inspector->reportException(new \\Exception(\'Test exception\'));',
],
[
'line' => 34,
'code' => '',
],
[
'line' => 35,
'code' => ' $this->inspector->flush();',
],
[
'line' => 36,
'code' => '',
],
[
'line' => 37,
'code' => ' dump($this->inspector);',
],
[
'line' => 38,
'code' => '',
],
],
],
'start' => 0.2,
'timestamp' => 1701464039.650826,
'duration' => 0.01,
],
'transaction' => [
'name' => 'http:https://127.0.0.1:8080/blog/post/1',
'hash' => 'a78992af325ea2335d102726ad8bc323a8ffcb5e4a004df9633f988a24c6fd4c',
],
'handled' => true,
],
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Migration;

use Cycle\Migrations\Migration;

class OrmDefault4d821d8599782e856feb0c9b8b26b42f extends Migration
{
protected const DATABASE = 'default';

public function up(): void
{
$this->table('events')
->alterColumn('timestamp', 'string', ['nullable' => false, 'defaultValue' => null, 'size' => 25])
->update();
}

public function down(): void
{
$this->table('events')
->alterColumn('timestamp', 'decimal', ['nullable' => false, 'defaultValue' => null, 'precision' => 10, 'scale' => 5])
->update();
}
}
Loading
Loading