Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an option to override URL while debugging #99

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading