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

feat: Added sentryMonitor macro support for specifying environments, updated CONTRIBUTING #816

Closed
wants to merge 3 commits into from

Conversation

Braunson
Copy link

@Braunson Braunson commented Dec 8, 2023

Feature

  • Added the new parameter to specify an array of environments that you would like the sentryMonitor() logic to run in
    • If nothing is specified, then the macro will run like normal
    • If one or more environments are specified and one matches it will run like normal
    • If one or more environments are specified and nothing matches it will run not run and return $this
  • Updated the contribution guide as there is no longer a Composer phpcs command. I did try running cs-fix/cs-check and there was a ton of changes (looks like mainly LF -> CRLF changes) but I didn't commit any of those changes.

References

@stayallive
Copy link
Collaborator

stayallive commented Dec 9, 2023

I'm not a big fan of using config('app.env') directly, we should probably read that from the app()->environment() (without using global functions).

I do think having the option to enable/disable this functionality on an environment basis is useful, however I'm wondering if there is a case where this needs to be controlled on a monitor level or that it could be a global configuration (to enable / disable scheduled task monitoring). Or maybe we could do with both, having a config option to disable scheduled task monitoring AND have a way to specify the environments on the ->sentryMonitor macro.

@cleptric WDYT?

Edit: I totally forget, but thanks for taking the time to start the discussion and take the time to make a PR!

@Braunson
Copy link
Author

Braunson commented Dec 9, 2023

Yeah I agree with about using app()->environment() instead, I didn't really like using config. I thought about defining the environments for all monitor calls in the config BUT my specific use case was to specify the environments for each scheduled command (instead of blanketing them all). Combining the two may be another option, having this defined in the sentry.php config, but also being able to override that directly in the sentryMonitor macro parameters.

I'm open to suggestions on changes.

@stayallive
Copy link
Collaborator

So I've changed a few things.

  • Renamed the new argument variable to be a little more clear
  • Remove the third test you added since it was basically the same as the other tests (they also don't provide a value for the arg) so not really needed
  • Get the environment from the container, the instanceof check is mostly there for static analyzers since it should always be an instance of that contract (even on Lumen) but safer this way if it isn't
  • Using detectEnvironment() to make the test pass, only way I could figure out how to update the environment and make the tests work (otherwise the environment is always testing)

@stayallive stayallive requested a review from cleptric December 21, 2023 18:04
Copy link
Collaborator

@stayallive stayallive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to create a PR!

@stayallive stayallive self-assigned this Dec 21, 2023
@cleptric
Copy link
Member

cleptric commented Dec 22, 2023

@Braunson I was told that the Crons Team is working on a new feature on the Sentry UI to ignore specific environments. So, we might not need to add this to the SDK in the end.

Edit: The feature was just shipped. You can hover over the environment on the Cron Monitors page (https://sentry.io/crons/) to mute or delete an environment.

image

@Braunson
Copy link
Author

@cleptric this still isn't ideal as when this feature is out of beta, I'd still not want certain environments reporting and taking a hit on the quota.

@cleptric
Copy link
Member

You won't be charged per environment. We can leave this open in the meantime, and I'll take another look next year.

@cleptric
Copy link
Member

We'll add a new before_send_check_in option. This will allow you to conditional disable sending check-ins. getsentry/sentry-php#1690

@cleptric
Copy link
Member

before_send_check_in was added to the PHP SDK in v4.5.0. Just update the Laravel SDK to v4.2.0, and you can start using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants