File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - Respect the ` SENTRY_ENVIRONMENT ` environment variable to override the Laravel environment (#354 )
6+
57## 1.8.0
68
79- Add ` send_default_pii ` option by default to published config file (#340 )
Original file line number Diff line number Diff line change 77 // capture release as git sha
88 // 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')),
99
10+ // When left empty or `null` the Laravel environment will be used
11+ 'environment ' => env ('SENTRY_ENVIRONMENT ' ),
12+
1013 'breadcrumbs ' => [
1114 // Capture Laravel logs in breadcrumbs
1215 'logs ' => true ,
Original file line number Diff line number Diff line change @@ -114,13 +114,17 @@ protected function configureAndRegisterClient(): void
114114
115115 $ options = \array_merge (
116116 [
117- 'environment ' => $ this ->app ->environment (),
118117 'prefixes ' => [$ basePath ],
119118 'in_app_exclude ' => ["{$ basePath }/vendor " ],
120119 ],
121120 $ userConfig
122121 );
123122
123+ // When we get no environment from the (user) configuration we default to the Laravel environment
124+ if (empty ($ options ['environment ' ])) {
125+ $ options ['environment ' ] = $ this ->app ->environment ();
126+ }
127+
124128 $ clientBuilder = ClientBuilder::create ($ options );
125129
126130 // Set the Laravel SDK identifier and version
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Sentry ;
4+
5+ use Sentry \Laravel \Tests \SentryLaravelTestCase ;
6+
7+ class ServiceProviderWithEnvironmentFromConfigTest extends SentryLaravelTestCase
8+ {
9+ public function testSentryEnvironmentDefaultsToLaravelEnvironment ()
10+ {
11+ $ this ->assertEquals ('testing ' , app ()->environment ());
12+ }
13+
14+ public function testEmptySentryEnvironmentDefaultsToLaravelEnvironment ()
15+ {
16+ $ this ->resetApplicationWithConfig ([
17+ 'sentry.environment ' => '' ,
18+ ]);
19+
20+ $ this ->assertEquals ('testing ' , $ this ->getHubFromContainer ()->getClient ()->getOptions ()->getEnvironment ());
21+
22+ $ this ->resetApplicationWithConfig ([
23+ 'sentry.environment ' => null ,
24+ ]);
25+
26+ $ this ->assertEquals ('testing ' , $ this ->getHubFromContainer ()->getClient ()->getOptions ()->getEnvironment ());
27+ }
28+
29+ public function testSentryEnvironmentDefaultGetsOverriddenByConfig ()
30+ {
31+ $ this ->resetApplicationWithConfig ([
32+ 'sentry.environment ' => 'not_testing ' ,
33+ ]);
34+
35+ $ this ->assertEquals ('not_testing ' , $ this ->getHubFromContainer ()->getClient ()->getOptions ()->getEnvironment ());
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments