Skip to content

Commit

Permalink
Fixing some issues for mr Phil Sturgeon
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSteveKing committed Mar 1, 2024
1 parent 05a3954 commit 7269409
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
26 changes: 13 additions & 13 deletions src/Factories/DataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Throwable;
use Treblle\Utils\DataObjects\Data;
use Treblle\Utils\DataObjects\Error;
Expand All @@ -19,7 +20,6 @@
use Treblle\Utils\Http\Method;
use Treblle\Utils\Masking\FieldMasker;
use Treblle\Utils\Support\PHP;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

final class DataFactory
{
Expand All @@ -36,8 +36,8 @@ public function make(Request $request, JsonResponse|Response|SymfonyResponse $re

try {
$responseBody = $this->masker->mask(
(array)json_decode(
$response->content(),
(array) json_decode(
$response->getContent(),
true,
512,
JSON_THROW_ON_ERROR
Expand All @@ -47,7 +47,7 @@ public function make(Request $request, JsonResponse|Response|SymfonyResponse $re
$responseBody = '{}';
}

if (!empty($response->exception)) {
if (! empty($response->exception)) {
$errors[] = new Error(
'onException',
'UNHANDLED_EXCEPTION',
Expand All @@ -59,17 +59,17 @@ public function make(Request $request, JsonResponse|Response|SymfonyResponse $re

return new Data(
new Server(
strval($request->server('SERVER_ADDR')),
strval(config('app.timezone')),
strval($request->server('SERVER_SOFTWARE')),
strval($request->server('SERVER_SIGNATURE')),
strval($request->server('SERVER_PROTOCOL')),
(string) $request->server('SERVER_ADDR'),
(string) config('app.timezone'),
(string) $request->server('SERVER_SOFTWARE'),
(string) $request->server('SERVER_SIGNATURE'),
(string) $request->server('SERVER_PROTOCOL'),
new OS(
php_uname('s'),
php_uname('r'),
php_uname('m'),
),
strval($request->server('HTTP_ACCEPT_ENCODING')),
(string) $request->server('HTTP_ACCEPT_ENCODING'),
),
new Language(
'php',
Expand All @@ -83,7 +83,7 @@ public function make(Request $request, JsonResponse|Response|SymfonyResponse $re
),
new RequestObject(
Carbon::now('UTC')->format('Y-m-d H:i:s'),
strval($request->ip()),
(string) $request->ip(),
$request->fullUrl(),
strval($request->userAgent()),
Method::from(
Expand All @@ -109,8 +109,8 @@ public function make(Request $request, JsonResponse|Response|SymfonyResponse $re
fn ($item) => collect($item)->first(),
)->toArray(),
),
$response->status(),
strlen($response->content()),
$response->getStatusCode(),
strlen($response->getContent()),
$loadTime,
$responseBody,
),
Expand Down
21 changes: 11 additions & 10 deletions src/Middlewares/TreblleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ public function handle(Request $request, Closure $next, string $projectId = null
*/
public function terminate(Request $request, JsonResponse|Response|SymfonyResponse $response): void
{
dd($request);
Treblle::log(
endpoint: 'https://debug.treblle.com/',//Arr::random(Endpoint::cases()),
data: $this->factory->make(
request: $request,
response: $response,
loadTime: microtime(true) - self::$start,
),
projectId: self::$project ?? (string) config('treblle.project_id'),
);
if (!\in_array(config('app.env'), \explode('.', config('treblle.ignored_environments')), true)) {
Treblle::log(
endpoint: 'https://debug.treblle.com/',//Arr::random(Endpoint::cases()),
data: $this->factory->make(
request: $request,
response: $response,
loadTime: microtime(true) - self::$start,
),
projectId: self::$project ?? (string) config('treblle.project_id'),
);
}
}
}

0 comments on commit 7269409

Please sign in to comment.