Skip to content

Commit

Permalink
Merge pull request #99 from Treblle/feature/endpoint-debugging
Browse files Browse the repository at this point in the history
Adding an option to override URL while debugging
  • Loading branch information
JustSteveKing authored Oct 10, 2024
2 parents d3969a7 + 3edfd6c commit edee5ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions config/treblle.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php

return [
/*
* An override while debugging.
*/
'url' => null,

/*
* A valid Treblle API key. You can get started for FREE by visiting https://treblle.com/
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/TreblleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/Treblle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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();
}
Expand All @@ -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,
);
}
Expand Down

0 comments on commit edee5ff

Please sign in to comment.