Closed martinhellwagner closed 2 years ago
@martinhellwagner currently (2.0.1) the plugin uses App::env
, which should automatically solve this.
see: https://github.com/craftcms/cms/blob/main/src/helpers/App.php#L91
Additionally: Craft 4 has deprecated the ENVIRONMENT
env in favor of CRAFT_ENVIRONMENT
.
@roelvanhintum
Thanks for the clarification! Is it possible to use version 2.x
of the plugin with Craft 3 as well? We haven't yet upgraded the project to Craft 4.
@martinhellwagner not sure, but i think not. The upside is that the craft 3 version of the plugin does lean on the ‘CRAFT_ENVIRONMENT’ variable.
@roelvanhintum
Is there any way to make the 1.x
version of the plugin work when the CRAFT_ENVIRONMENT
variable is not correctly consumed?
@martinhellwagner not sure what you mean, isn’t this working? It should be just using the var as usual in craft 3. https://github.com/born05/craft-sentry/blob/master/src/Plugin.php#L64
@roelvanhintum
We're setting the variable like this in our web/index.php
file:
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
But in line 64 of the Plugin.php
file, this variable isn't available and can't be consumed, resulting in a failure of our pipeline (or every time a Sentry error should be reported).
Just to be sure, is the variable set before bootstrapping craft? And is it also set in the ‘craft’ file? Later versions of craft 3 suggest using a bootstrap.php, to make sure they are the same in both files.
@roelvanhintum
Acutally, it was not set in the craft
file. That seems to have been the issue. Thanks a lot for pointing that out! 👍🏼
In one of our projects, we have the problem that the
CRAFT_ENVIRONMENT
variable (even though correctly defined in theweb/index.php
file) is not correctly consumed by the plugin. This unfortunately breaks our build pipeline as well as each queue job that wants to report a Sentry error.I therefore propose an additional check in the file
Plugin.php
(line 64) in order to make sure that the right Craft Environment is consumed: