From 4cd279624f97f82e8609d5c5c74025e54bfa7f0e Mon Sep 17 00:00:00 2001 From: Samuel Melrose Date: Fri, 8 Nov 2024 11:27:35 +0000 Subject: [PATCH 1/2] fallback to default exception handler outside of serverless --- .../Foundation/Exceptions/Handler.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Foundation/Exceptions/Handler.php b/src/AffordableMobiles/GServerlessSupportLaravel/Foundation/Exceptions/Handler.php index ff4b407..06572cf 100644 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Foundation/Exceptions/Handler.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Foundation/Exceptions/Handler.php @@ -19,6 +19,12 @@ class Handler extends LaravelHandler */ protected function reportThrowable(\Throwable $e): void { + if (!is_g_serverless()) { + parent::reportThrowable($e); + + return; + } + $this->reportedExceptionMap[$e] = true; if (Reflector::isCallable($reportCallable = [$e, 'report']) From fb18eb1d1c7580b65a3645b5e3d52f49f75ab163 Mon Sep 17 00:00:00 2001 From: Samuel Melrose Date: Fri, 8 Nov 2024 11:27:46 +0000 Subject: [PATCH 2/2] php-cs-fixer --- composer.json | 3 ++- .../Auth/IdentityGroupUserProvider.php | 2 +- .../Auth/Token/Middleware/AuthTokenMiddleware.php | 2 +- .../Console/GServerlessViewCompileCommand.php | 2 +- .../Integration/ErrorReporting/Report.php | 6 +++--- .../Integration/JWT/Signer/IAMSigner.php | 2 +- .../Session/DatastoreSessionHandler.php | 6 +++--- .../Instrumentation/Datastore/GDS/GDSInstrumentation.php | 4 ++-- .../Trace/Instrumentation/Guzzle/GuzzleInstrumentation.php | 4 ++-- .../Trace/Instrumentation/Laravel/HttpInstrumentation.php | 2 +- 10 files changed, 17 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index aa84666..008d52c 100755 --- a/composer.json +++ b/composer.json @@ -60,7 +60,8 @@ }, "config": { "allow-plugins": { - "php-http/discovery": true + "php-http/discovery": true, + "tbachert/spi": true } } } diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Auth/IdentityGroupUserProvider.php b/src/AffordableMobiles/GServerlessSupportLaravel/Auth/IdentityGroupUserProvider.php index 49e0e8b..ac35f3b 100755 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Auth/IdentityGroupUserProvider.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Auth/IdentityGroupUserProvider.php @@ -76,7 +76,7 @@ protected function isGroupMember(string $identifier) return (new CloudIdentity($client))->groups_memberships->checkTransitiveMembership( 'groups/'.$this->group, [ - 'query' => sprintf("member_key_id == '%s'", $identifier), + 'query' => \sprintf("member_key_id == '%s'", $identifier), ], )->getHasMembership(); } catch (\Throwable $ex) { diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Auth/Token/Middleware/AuthTokenMiddleware.php b/src/AffordableMobiles/GServerlessSupportLaravel/Auth/Token/Middleware/AuthTokenMiddleware.php index 18de868..b6fc0e4 100755 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Auth/Token/Middleware/AuthTokenMiddleware.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Auth/Token/Middleware/AuthTokenMiddleware.php @@ -124,7 +124,7 @@ public static function factory(array $audienceMap = []): self $audienceSource = static function (UriInterface $request_uri) use ($audienceMap) { if (self::isCloudFunction($request_uri)) { - return sprintf( + return \sprintf( '%s://%s%s', $request_uri->getScheme(), $request_uri->getHost(), diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Console/GServerlessViewCompileCommand.php b/src/AffordableMobiles/GServerlessSupportLaravel/Console/GServerlessViewCompileCommand.php index 9ad2c38..093907d 100644 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Console/GServerlessViewCompileCommand.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Console/GServerlessViewCompileCommand.php @@ -90,7 +90,7 @@ public function handle(): int $filePath = $file->getPathname(); $fileRelativePath = FileViewFinder::getRelativePath(base_path(), $filePath); - if (!preg_match('/(.*)\\.blade\\.php$/', $filePath)) { + if (!preg_match('/(.*)\.blade\.php$/', $filePath)) { $this->info("Blade Compiler: \tSkipping view (".($g + 1).'/'.\count($files).') '.$fileRelativePath); continue; diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Integration/ErrorReporting/Report.php b/src/AffordableMobiles/GServerlessSupportLaravel/Integration/ErrorReporting/Report.php index c858cd6..91cbe2d 100755 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Integration/ErrorReporting/Report.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Integration/ErrorReporting/Report.php @@ -42,7 +42,7 @@ public static function init(?PsrLogger $psrLogger = null): void public static function exceptionHandler(\Throwable $ex, int $status_code = 500, array $context = [], string $level = LogLevel::ERROR): void { - $message = sprintf('PHP Notice: %s', (string) $ex); + $message = \sprintf('PHP Notice: %s', (string) $ex); if (self::$psrLogger) { $logContext = [ 'context' => array_merge($context, [ @@ -86,7 +86,7 @@ public static function errorHandler(int $level, string $message, string $file, i if (!($level & error_reporting())) { return true; } - $message = sprintf( + $message = \sprintf( '%s: %s in %s on line %d', self::getErrorPrefix($level), $message, @@ -139,7 +139,7 @@ public static function shutdownHandler(): void case E_PARSE: case E_COMPILE_ERROR: case E_CORE_ERROR: - $message = sprintf( + $message = \sprintf( '%s: %s in %s on line %d', self::getErrorPrefix($err['type']), $err['message'], diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Integration/JWT/Signer/IAMSigner.php b/src/AffordableMobiles/GServerlessSupportLaravel/Integration/JWT/Signer/IAMSigner.php index adbbfe2..8f10950 100644 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Integration/JWT/Signer/IAMSigner.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Integration/JWT/Signer/IAMSigner.php @@ -75,7 +75,7 @@ public function createHash($payload, Key $key) $service = new \Google_Service_IAMCredentials($client); - $keyID = sprintf('projects/-/serviceAccounts/%s', $key->contents()); + $keyID = \sprintf('projects/-/serviceAccounts/%s', $key->contents()); $requestBody = new \Google_Service_IAMCredentials_SignBlobRequest(); diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Session/DatastoreSessionHandler.php b/src/AffordableMobiles/GServerlessSupportLaravel/Session/DatastoreSessionHandler.php index f54ea18..e188719 100755 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Session/DatastoreSessionHandler.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Session/DatastoreSessionHandler.php @@ -63,7 +63,7 @@ public function read(string $id): false|string } } catch (Exception $e) { trigger_error( - sprintf('Datastore lookup failed: %s', $e->getMessage()), + \sprintf('Datastore lookup failed: %s', $e->getMessage()), E_USER_WARNING ); } @@ -88,7 +88,7 @@ public function write(string $id, string $data): bool (new ExponentialBackoff(6, [DatastoreFactory::class, 'shouldRetry']))->execute([$this->datastore, 'upsert'], [$entity]); } catch (Exception $e) { trigger_error( - sprintf('Datastore upsert failed: %s', $e->getMessage()), + \sprintf('Datastore upsert failed: %s', $e->getMessage()), E_USER_WARNING ); @@ -106,7 +106,7 @@ public function destroy(string $id): bool (new ExponentialBackoff(6, [DatastoreFactory::class, 'shouldRetry']))->execute([$this->datastore, 'delete'], [$key]); } catch (Exception $e) { trigger_error( - sprintf('Datastore delete failed: %s', $e->getMessage()), + \sprintf('Datastore delete failed: %s', $e->getMessage()), E_USER_WARNING ); diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Datastore/GDS/GDSInstrumentation.php b/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Datastore/GDS/GDSInstrumentation.php index e958550..96d8926 100644 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Datastore/GDS/GDSInstrumentation.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Datastore/GDS/GDSInstrumentation.php @@ -23,7 +23,7 @@ public static function register(CachedInstrumentation $instrumentation): void Gateway::class, 'execute', pre: static function (Gateway $client, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation): void { - SimpleSpan::pre($instrumentation, sprintf('GDS/execute/%s', $params[0] ?? 'unknown'), []); + SimpleSpan::pre($instrumentation, \sprintf('GDS/execute/%s', $params[0] ?? 'unknown'), []); }, post: static function (Gateway $client, array $params, mixed $returnValue, ?\Throwable $exception): void { SimpleSpan::post(); @@ -67,7 +67,7 @@ public static function register(CachedInstrumentation $instrumentation): void GatewayREST::class, 'executePostRequest', pre: static function (GatewayREST $client, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation): void { - SimpleSpan::pre($instrumentation, sprintf('GDS/execute/%s', $params[0] ?? 'unknown'), []); + SimpleSpan::pre($instrumentation, \sprintf('GDS/execute/%s', $params[0] ?? 'unknown'), []); }, post: static function (GatewayREST $client, array $params, mixed $returnValue, ?\Throwable $exception): void { SimpleSpan::post(); diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Guzzle/GuzzleInstrumentation.php b/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Guzzle/GuzzleInstrumentation.php index ee252e9..3b13538 100644 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Guzzle/GuzzleInstrumentation.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Guzzle/GuzzleInstrumentation.php @@ -64,7 +64,7 @@ public static function register(CachedInstrumentation $instrumentation): void foreach (array_filter(explode('|', env('TRACE_GUZZLE_HTTP_REQUEST_HEADERS', ''))) as $header) { if ($request->hasHeader($header)) { $spanBuilder->setAttribute( - sprintf('http.request.header.%s', strtolower($header)), + \sprintf('http.request.header.%s', strtolower($header)), $request->getHeader($header) ); } @@ -124,7 +124,7 @@ public static function register(CachedInstrumentation $instrumentation): void foreach (array_filter(explode('|', env('TRACE_GUZZLE_HTTP_RESPONSE_HEADERS', ''))) as $header) { if ($response->hasHeader($header)) { // @psalm-suppress ArgumentTypeCoercion - $span->setAttribute(sprintf('http.response.header.%s', strtolower($header)), $response->getHeader($header)); + $span->setAttribute(\sprintf('http.response.header.%s', strtolower($header)), $response->getHeader($header)); } } if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) { diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Laravel/HttpInstrumentation.php b/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Laravel/HttpInstrumentation.php index bff5128..5da8c3e 100644 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Laravel/HttpInstrumentation.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Trace/Instrumentation/Laravel/HttpInstrumentation.php @@ -31,7 +31,7 @@ public static function register(CachedInstrumentation $instrumentation): void /** @psalm-suppress ArgumentTypeCoercion */ $builder = $instrumentation->tracer() - ->spanBuilder(sprintf('%s', $request?->method() ?? 'unknown')) + ->spanBuilder(\sprintf('%s', $request?->method() ?? 'unknown')) ->setSpanKind(SpanKind::KIND_SERVER) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)