From 78e83eb04ef9ac4fd77e77960c503b9ac11be3de Mon Sep 17 00:00:00 2001 From: Steve McDougall Date: Wed, 8 Nov 2023 10:32:27 +0000 Subject: [PATCH 1/5] Removing Qodana from CI --- .github/workflows/tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a97b938..0177a20 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,8 +40,3 @@ jobs: - name: Execute the tests run: vendor/bin/phpunit --testdox - - - name: 'Qodana Scan' - uses: JetBrains/qodana-action@main - env: - QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} From 2b1b499ace5933bb22fb1d397008d2d1741adbc2 Mon Sep 17 00:00:00 2001 From: Steve McDougall Date: Wed, 8 Nov 2023 10:34:20 +0000 Subject: [PATCH 2/5] Adding Treblle Trace ID to requests --- src/Middlewares/TreblleMiddleware.php | 16 ++++++++- tests/Middleware/TreblleMiddlewareTest.php | 38 ++++++++++++++++------ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/Middlewares/TreblleMiddleware.php b/src/Middlewares/TreblleMiddleware.php index 29462e1..fcacb62 100644 --- a/src/Middlewares/TreblleMiddleware.php +++ b/src/Middlewares/TreblleMiddleware.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Treblle\Exceptions\ConfigurationException; use Treblle\Exceptions\TreblleApiException; @@ -44,7 +45,20 @@ public function handle(Request $request, Closure $next, string $projectId = null self::$start = microtime(true); self::$project = $projectId; - return $next($request); + if (! $request->headers->has('X-TREBLLE-TRACE-ID')) { + $request->headers->add([ + 'X-TREBLLE-TRACE-ID' => $id = Str::uuid(), + ]); + } + + /** @var SymfonyResponse $response */ + $response = $next($request); + + $response->headers->add([ + 'X-TREBLLE-TRACE-ID' => $request->headers->get('X-TREBLLE-TRACE-ID'), + ]); + + return $response; } /** diff --git a/tests/Middleware/TreblleMiddlewareTest.php b/tests/Middleware/TreblleMiddlewareTest.php index 8b02b5c..80fc680 100644 --- a/tests/Middleware/TreblleMiddlewareTest.php +++ b/tests/Middleware/TreblleMiddlewareTest.php @@ -11,21 +11,20 @@ final class TreblleMiddlewareTest extends TestCase { - /** - * @test - * @return void - */ + protected function newMiddleware(): TreblleMiddleware + { + return app()->make( + abstract: TreblleMiddleware::class, + ); + } + + /** @test */ public function it_returns_a_response(): void { $request = new Request(); $response = new Response(); - /** - * @var TreblleMiddleware $middleware - */ - $middleware = app()->make( - abstract: TreblleMiddleware::class, - ); + $middleware = $this->newMiddleware(); $middlewareResponse = $middleware->handle( request: $request, @@ -37,4 +36,23 @@ public function it_returns_a_response(): void actual: $middlewareResponse, ); } + + /** @test */ + public function it_adds_trace_id_to_response(): void + { + $request = new Request(); + $response = new Response(); + + $middleware = $this->newMiddleware(); + + $middlewareResponse = $middleware->handle( + request: $request, + next: fn () => $response, + ); + + $this->assertArrayHasKey( + key: 'x-treblle-trace-id', + array: $middlewareResponse->headers->all(), + ); + } } From 5a000b73c5498029a7578782aa759e5f668ce39f Mon Sep 17 00:00:00 2001 From: Steve McDougall Date: Wed, 8 Nov 2023 10:38:18 +0000 Subject: [PATCH 3/5] Adding PHP 8.2 to CI pipeline --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0177a20..afb49e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.1 ] + php: [ 8.1, 8.2 ] laravel: [ 9.*, 10.* ] exclude: - php: 8.1 From 20dfd531461969f9d84cb314bc39f6f30b20ffb0 Mon Sep 17 00:00:00 2001 From: Steve McDougall Date: Wed, 8 Nov 2023 10:39:27 +0000 Subject: [PATCH 4/5] Adding PHP 8.3 to CI pipeline --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index afb49e4..aed52d4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.1, 8.2 ] + php: [ 8.1, 8.2, 8.3 ] laravel: [ 9.*, 10.* ] exclude: - php: 8.1 From 5ac4b41c66f19de0d35c01aa347e53af7f09b775 Mon Sep 17 00:00:00 2001 From: Steve McDougall Date: Wed, 8 Nov 2023 10:41:01 +0000 Subject: [PATCH 5/5] Updating the checkout action to v3 to resolve node error issue --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aed52d4..978eb96 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout the code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2