From 371e0c3a613a473b152d6db5c52c36a91ed232a6 Mon Sep 17 00:00:00 2001 From: Yousef Lamlum Date: Thu, 31 Jul 2025 18:33:15 +0100 Subject: [PATCH 1/4] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8719ee2..235b449 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dancryer/whoops-stackdriver", + "name": "gear4music/whoops-stackdriver", "description": "Provides a handler for Whoops that outputs a StackDriver ReportedErrorEvent.", "type": "library", "license": "BSD-2-Clause", @@ -29,4 +29,4 @@ "phpunit/phpunit": "^9.1.5", "symfony/var-dumper": "^5.1.0" } - } \ No newline at end of file + } From a503b8ba04db03ce484e26f869290742118c3fd9 Mon Sep 17 00:00:00 2001 From: Yousef Lamlum Date: Thu, 31 Jul 2025 18:56:54 +0100 Subject: [PATCH 2/4] Added the GCP trace id --- src/ExceptionFormatter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ExceptionFormatter.php b/src/ExceptionFormatter.php index 8bb7288..bee1968 100644 --- a/src/ExceptionFormatter.php +++ b/src/ExceptionFormatter.php @@ -36,9 +36,12 @@ public function toArray() : array 'serviceContext' => $this->serviceContext, 'context' => [], 'severity' => 'ERROR', - ]; + if (defined('GCP_TRACE_ID')) { + $rtn['logging.googleapis.com/trace'] = GCP_TRACE_ID; + } + // Set initial context: if ($this->throwable instanceof ExceptionWithContext) { $rtn['context'] = $this->throwable->getContext(); From 5e927cf069e9056140202ba7a1618f9c7e8816b8 Mon Sep 17 00:00:00 2001 From: Yousef Lamlum Date: Fri, 1 Aug 2025 15:52:59 +0100 Subject: [PATCH 3/4] Fix for missing HTTP_USER_AGENT --- src/ExceptionFormatter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ExceptionFormatter.php b/src/ExceptionFormatter.php index bee1968..f66afa7 100644 --- a/src/ExceptionFormatter.php +++ b/src/ExceptionFormatter.php @@ -63,10 +63,10 @@ public function toArray() : array // HTTP request specific context: if (php_sapi_name() !== 'cli') { // Add HTTP request details to the context array: - $rtn['context']['httpRequest']['method'] = $_SERVER['REQUEST_METHOD']; - $rtn['context']['httpRequest']['url'] = $_SERVER['REQUEST_URI']; - $rtn['context']['httpRequest']['userAgent'] = $_SERVER['HTTP_USER_AGENT']; - $rtn['context']['httpRequest']['remoteIp'] = $_SERVER['REMOTE_ADDR']; + $rtn['context']['httpRequest']['method'] = $_SERVER['REQUEST_METHOD'] ?? 'Unknown'; + $rtn['context']['httpRequest']['url'] = $_SERVER['REQUEST_URI'] ?? 'Unknown'; + $rtn['context']['httpRequest']['userAgent'] = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown'; + $rtn['context']['httpRequest']['remoteIp'] = $_SERVER['REMOTE_ADDR'] ?? 'Unknown'; // Add session details to the context array: if (PHP_SESSION_ACTIVE === session_status()) { From f9767037867453518349bd17ea08be9f1f34b248 Mon Sep 17 00:00:00 2001 From: Yousef Lamlum Date: Fri, 9 Jan 2026 13:10:28 +0000 Subject: [PATCH 4/4] feat(SC-191): Add full URL, referrer and HTTP status code in `httpRequest` context --- src/ExceptionFormatter.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ExceptionFormatter.php b/src/ExceptionFormatter.php index f66afa7..25da654 100644 --- a/src/ExceptionFormatter.php +++ b/src/ExceptionFormatter.php @@ -24,7 +24,7 @@ public function __construct(Throwable $throwable, array $serviceContext = []) } /** - * Create an approriately formatted log message for a Google Stackdriver Reported Error Event. + * Create an appropriately formatted log message for a Google Stackdriver Reported Error Event. * @link https://cloud.google.com/error-reporting/docs/formatting-error-messages#json_representation * @return array */ @@ -64,9 +64,17 @@ public function toArray() : array if (php_sapi_name() !== 'cli') { // Add HTTP request details to the context array: $rtn['context']['httpRequest']['method'] = $_SERVER['REQUEST_METHOD'] ?? 'Unknown'; - $rtn['context']['httpRequest']['url'] = $_SERVER['REQUEST_URI'] ?? 'Unknown'; + $rtn['context']['httpRequest']['url'] = sprintf( + '%s://%s%s', + isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http', + $_SERVER['HTTP_HOST'] ?? 'Unknown', + $_SERVER['REQUEST_URI'] ?? 'Unknown' + ); + $rtn['context']['httpRequest']['userAgent'] = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown'; $rtn['context']['httpRequest']['remoteIp'] = $_SERVER['REMOTE_ADDR'] ?? 'Unknown'; + $rtn['context']['httpRequest']['referrer'] = $_SERVER['HTTP_REFERER'] ?? 'Unknown'; + $rtn['context']['httpRequest']['responseStatusCode'] = $_SERVER['REDIRECT_STATUS'] ?? 0; // Add session details to the context array: if (PHP_SESSION_ACTIVE === session_status()) {