Skip to content

Commit b942458

Browse files
committed
Add release & environment setting to test command
Fixes #560
1 parent 238424f commit b942458

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix incorrect `release` and `environment` values when using the `sentry:test` command
6+
57
## 2.12.0
68

79
- Add support for normalized route names when using [Laravel Lumen](https://lumen.laravel.com/docs/9.x) (#449)

src/Sentry/Laravel/Console/TestCommand.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Sentry\State\HubInterface;
1212
use Sentry\Tracing\SpanContext;
1313
use Sentry\Tracing\TransactionContext;
14+
use Throwable;
1415

1516
class TestCommand extends Command
1617
{
@@ -54,9 +55,20 @@ public function handle(): int
5455

5556
$dsn = $this->option('dsn');
5657

58+
$laravelClient = null;
59+
60+
try {
61+
$laravelClient = app(HubInterface::class)->getClient();
62+
} catch (Throwable $e) {
63+
// Ignore any errors related to getting the client from the Laravel container
64+
// These errors will surface later in the process but we should not crash here
65+
}
66+
5767
// If the DSN was not passed as option to the command we use the registered client to get the DSN from the Laravel config
5868
if ($dsn === null) {
59-
$dsnObject = app(HubInterface::class)->getClient()->getOptions()->getDsn();
69+
$dsnObject = $laravelClient === null
70+
? null
71+
: $laravelClient->getOptions()->getDsn();
6072

6173
if ($dsnObject !== null) {
6274
$dsn = (string)$dsnObject;
@@ -77,6 +89,8 @@ public function handle(): int
7789
try {
7890
$clientBuilder = ClientBuilder::create([
7991
'dsn' => $dsn,
92+
'release' => $laravelClient === null ? null : $laravelClient->getOptions()->getRelease(),
93+
'environment' => $laravelClient === null ? null : $laravelClient->getOptions()->getEnvironment(),
8094
'traces_sample_rate' => 1.0,
8195
]);
8296
} catch (Exception $e) {

0 commit comments

Comments
 (0)