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

Allow current_environment to be set via an env variable #736

Merged
merged 1 commit into from
Aug 10, 2017
Merged

Allow current_environment to be set via an env variable #736

merged 1 commit into from
Aug 10, 2017

Conversation

tijmenb
Copy link
Contributor

@tijmenb tijmenb commented Aug 9, 2017

This commit allows developers to set a SENTRY_CURRENT_ENV variable to configure the current_environment setting.

It serves as a fix for this scenario:

We run our production/staging/integration environments with Rails env "production". To differentiate errors from the environments we set config.current_environment with an environment variable:

https://github.com/alphagov/content-tagger/blob/bac2e1903aaf6ac12b3a103490517355673648dd/config/initializers/sentry.rb#L1-L3

However, this doesn't work in all situations. For example, when you run a rake task that doesn't exist, an error will be reported to Sentry. Because the initialiser that sets the current_environment hasn't run (yet) Sentry will use the RAILS_ENV to determine the current env. This causes all errors to be reported as "production" instead of production/staging/integration.

This commit allows developers to set a `SENTRY_CURRENT_ENV` variable to
configure the `current_environment` setting.

It serves as a fix for this scenario:

We run our production/staging/integration environments with Rails env
"production". To differentiate errors from the environments we set
`config.current_environment` with an environment variable
(https://github.com/alphagov/content-tagger/blob/bac2e1903aaf6ac12b3a103
490517355673648dd/config/initializers/sentry.rb#L2).

However, this doesn't work in all situations. For example, when you run
a rake task that doesn't exist, an error will be reported to Sentry.
Because the initialiser that sets the `current_environment` hasn't run
(yet) Sentry will use the `RAILS_ENV` to determine the current env.
This causes all errors to be reported as production instead of
production/staging/integration.
@nateberkopec
Copy link
Contributor

Couldn't you also fix this by requiring the initializer at the top of your Rakefile?

@tijmenb
Copy link
Contributor Author

tijmenb commented Aug 10, 2017

Yep, that would also work in this case. However, we're migrating over 50 applications to Sentry, so for us this would be a not insignificant amount of work. Additionally this option would probably allow us to configure everything via the environment and skip the initialiser entirely, which makes adoption a lot easier for us.

@nateberkopec nateberkopec merged commit 6a946c4 into getsentry:master Aug 10, 2017
tijmenb added a commit to alphagov/govuk-puppet that referenced this pull request Aug 11, 2017
This sets the current environment for Sentry to the value currently
used for errbit, so either integration/staging/production
(getsentry/sentry-ruby#736).
tijmenb added a commit to alphagov/govuk-puppet that referenced this pull request Aug 15, 2017
This sets the current environment for Sentry to the value currently
used for errbit, so either integration/staging/production
(getsentry/sentry-ruby#736).
tijmenb added a commit to alphagov/govuk-puppet that referenced this pull request Aug 17, 2017
This sets the current environment for Sentry to the value currently
used for errbit, so either integration/staging/production
(getsentry/sentry-ruby#736).
tijmenb added a commit to alphagov/govuk-puppet that referenced this pull request Aug 21, 2017
This sets the current environment for Sentry to the value currently
used for errbit, so either integration/staging/production
(getsentry/sentry-ruby#736).
tijmenb added a commit to alphagov/govuk-puppet that referenced this pull request Aug 21, 2017
This sets the current environment for Sentry to the value currently
used for errbit, so either integration/staging/production
(getsentry/sentry-ruby#736).
tijmenb added a commit to alphagov/govuk_app_config that referenced this pull request Oct 11, 2017
Release commit:
getsentry/sentry-ruby@ef623824cb0a8a2f60be5fb7e
12f80454da54fd7

This release includes the PR to set the Sentry environment with
`SENTRY_CURRENT_ENV`, which means that Sentry will report the correct
env even when the configuration hasn't loaded yet
(getsentry/sentry-ruby#736). It simplifies our
local config.
tijmenb added a commit to alphagov/govuk_app_config that referenced this pull request Oct 11, 2017
Release commit:
getsentry/sentry-ruby@ef623824cb0a8a2f60be5fb7e
12f80454da54fd7

This release includes the PR to set the Sentry environment with
`SENTRY_CURRENT_ENV`, which means that Sentry will report the correct
env even when the configuration hasn't loaded yet
(getsentry/sentry-ruby#736). It simplifies our
local config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants