[IMP] sentry: configure through environment variables - #3724
Open
moylop260 wants to merge 1 commit into
Open
Conversation
Every option can now come from ODOO_SENTRY_*, named after the option it
carries: sentry_dsn is ODOO_SENTRY_DSN. That is the shape queue_job has
been using for ODOO_QUEUE_JOB_* for years.
Both sources stay supported and are merged per option, the environment
winning where the two disagree, so an existing [sentry] section keeps
working untouched.
A container has two reasons to prefer the environment. Odoo reads only
[options] from its configuration file and logs "unknown option ... in
the config file" for anything else it finds there, which is why these
options were moved out to a [sentry] section to begin with. And
odoo-bin -s rewrites that file out of Odoo's own options, dropping every
other section with it.
The ODOO_ prefix keeps these apart from the SENTRY_* variables
sentry-sdk reads on its own. SENTRY_DSN addresses whichever process the
library runs in, and it cannot serve here anyway: the dsn is always
passed explicitly, and sentry-sdk only falls back to the environment for
an option it receives as None.
Options that answer yes or no now go through to_bool. A configuration
file and an environment variable can only deliver a string, and
bool("False") is True, so sentry_enabled = False used to turn sentry on.
Contributor
|
Hi @barsi, @fernandahf, @versada, @naglis, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
sentry_*option can now be set through an environment variable namedafter it with an
ODOO_prefix —sentry_dsnisODOO_SENTRY_DSN— so aninstance can be configured without a configuration file at all.
This is the same technique and the same precedence
queue_jobhas been applyingto
ODOO_QUEUE_JOB_*for years,os.environ.get(...) or <section>.get(...):https://github.com/OCA/queue/blob/0046b8741c6820f5ca4357daa7ca2acf7e4548c9/queue_job/jobrunner/runner.py#L60-L65
Both sources stay supported and are merged per option, the environment winning
where the two disagree, so an existing
[sentry]section keeps workinguntouched.
Why
Since #3517 moved the options out of
[options]into their own[sentry]section, the file is quiet but it is still a file, and on a container it is the
awkward part of the deployment:
[options]from the configuration file and logsunknown option ... in the config filefor anything else it finds there.That warning is what the
[sentry]section exists to avoid:https://github.com/odoo/odoo/blob/1eb4fcdf08ddbc1341bdc8cb8129906722f54bdc/odoo/tools/config.py#L901-L918
odoo-bin -srewrites the configuration file out of Odoo's own options, whichdrops every other section and takes
[sentry]with it:https://github.com/odoo/odoo/blob/1eb4fcdf08ddbc1341bdc8cb8129906722f54bdc/odoo/tools/config.py#L936-L945
up writing the
sentry_*keys into[options], where this module no longerlooks for them. Sentry then never initializes, with nothing in the log to say
why.
Why not the
SENTRY_*variables sentry-sdk already readssentry-sdkdoes readSENTRY_DSN,SENTRY_ENVIRONMENT,SENTRY_RELEASEandSENTRY_DEBUGon its own, but only for an option it receives asNone:_get_optionsguards each fallback withif rv["<option>"] is None. Thismodule always passes
dsnexplicitly, and its default is"", soSENTRY_DSNis never consulted.
sentry_enabledhas no equivalent in the library at all, sonothing in the environment could switch the module on.
Keeping the
ODOO_prefix also leavesSENTRY_DSNmeaning what it meanseverywhere else — the DSN of whichever process the library runs in — instead of
quietly redirecting Odoo to it.
Boolean options
Options that answer yes or no now go through a
to_boolhelper. A configurationfile and an environment variable can only deliver a string, and
bool("False")is
True, sosentry_enabled = Falseused to turn Sentry on. A value leftempty is not read as "off": it carries no answer, so the default stands.
Tests
Added to
sentry/tests/test_client.py: the mapping from variable name to optionname,
to_boolover the strings both sources deliver, an instance configuredentirely from the environment with no section at all, the environment winning
over the file, the two sources merging per option,
SENTRY_DSNnot being readas ours, and
sentry_enabled = Falsereading as off from either source.