From 3edfd6c08ed83f535eaa83449626c02743d7fc30 Mon Sep 17 00:00:00 2001 From: Steve McDougall Date: Thu, 10 Oct 2024 09:21:51 +0100 Subject: [PATCH] Adding an option to override URL while debugging --- config/treblle.php | 5 +++++ src/Middlewares/TreblleMiddleware.php | 2 +- src/Treblle.php | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config/treblle.php b/config/treblle.php index c89e461..f7af4cc 100644 --- a/config/treblle.php +++ b/config/treblle.php @@ -1,6 +1,11 @@ null, + /* * A valid Treblle API key. You can get started for FREE by visiting https://treblle.com/ */ diff --git a/src/Middlewares/TreblleMiddleware.php b/src/Middlewares/TreblleMiddleware.php index abf32bf..c420e14 100644 --- a/src/Middlewares/TreblleMiddleware.php +++ b/src/Middlewares/TreblleMiddleware.php @@ -67,7 +67,7 @@ public function terminate(Request $request, JsonResponse|Response|SymfonyRespons } Treblle::log( - endpoint: Endpoint::random(), + endpoint: config('treblle.endpoint', Endpoint::random()), data: $this->factory->make( request: $request, response: $response, diff --git a/src/Treblle.php b/src/Treblle.php index c6cb171..48c5d49 100644 --- a/src/Treblle.php +++ b/src/Treblle.php @@ -10,17 +10,18 @@ use Treblle\Utils\DataObjects\Data; use function in_array; +use function is_string; final class Treblle { - public const VERSION = '4.0.0'; + public const VERSION = '4.6.4'; /** * Send request and response payload to Treblle for processing. * * @throws ConfigurationException */ - public static function log(Endpoint $endpoint, Data $data, ?string $projectId = null): void + public static function log(string|Endpoint $endpoint, Data $data, ?string $projectId = null): void { $treblleConfig = (array) config('treblle'); @@ -44,7 +45,6 @@ public static function log(Endpoint $endpoint, Data $data, ?string $projectId = $apiKey = config('treblle.api_key'); $configProjectId = config('treblle.project_id'); - // Check if the API key has been set if (is_null($apiKey)) { throw ConfigurationException::noApiKey(); } @@ -61,12 +61,12 @@ public static function log(Endpoint $endpoint, Data $data, ?string $projectId = ] ); - $response = Http::withHeaders( + Http::withHeaders( headers: ['X-API-KEY' => $apiKey], )->withUserAgent( userAgent: 'Treblle\Laravel/'.self::VERSION, )->acceptJson()->asJson()->post( - url: $endpoint->value, + url: is_string($endpoint) ? $endpoint : $endpoint->value, data: $data, ); }