-
Notifications
You must be signed in to change notification settings - Fork 543
feat: Allow configuring keep_alive
via environment variable
#4366
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
base: master
Are you sure you want to change the base?
Conversation
This commit enables the `keep_alive` option to be set via the `SENTRY_KEEP_ALIVE` environment variable. When both the environment variable and the argument are provided, the argument takes precedence. Closes #4354
# Argument overrides environment variable | ||
("0", True, True), # env false, arg true | ||
("1", False, False), # env true, arg false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you all think this order of precedence is reasonable? Or, should we not guarantee any specific order of precedence (i.e. if both are set to different values, behavior is undefined)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion the env var should take precedence over the option set in the script (this way it allows the user to change the behavior by setting env vars, no matter was is set or not set in the script)
But if I look at our env var handling (SENTRY_ENVIRONMENT
et al), if an option is set in the script, the env vars are not looked at at all.
So your order is OK. Consistency trumps other concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the middle option would be to remove the tests asserting order and not provide any specific guarantee on precedence for now.
That way we could change the precedence later even in a minor release
What do you think @antonpirker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we have an order right now: Options set when calling init()
are overruling env vars.
And I think we can not change this in a minor release, because it can alter behavior for users that have a init option and an env var set.
the tests are good, because if we change the precedence by accident, the tests will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, then we stay with what we currently have
❌ 6 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -142,6 +142,11 @@ def _get_options(*args, **kwargs): | |||
) | |||
rv["socket_options"] = None | |||
|
|||
if rv["keep_alive"] is None: | |||
rv["keep_alive"] = ( | |||
env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE"), strict=True) or False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE"), strict=True) or False | |
env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE", "False"), strict=True) |
to be consistent with SENTRY_DEBUG handling in the same file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should make this change because env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE"), strict=True) or False
and env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE", "False"), strict=True)
are not equivalent.
For example, if SENTRY_KEEP_ALIVE
is set to an invalid value like "invalid"
, then the current code with or False
evaluates to False
, whereas your proposal would evaluate to None
. Since keep_alive
should have a boolean value, I think the current option is preferable.
If anything, I would consider changing the SENTRY_DEBUG
handling to match what I have implemented here (although that would need a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The important part is that all env vars are handled in the same way.
Its fine if you change the others, as long as all are behaving the same.
# Argument overrides environment variable | ||
("0", True, True), # env false, arg true | ||
("1", False, False), # env true, arg false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion the env var should take precedence over the option set in the script (this way it allows the user to change the behavior by setting env vars, no matter was is set or not set in the script)
But if I look at our env var handling (SENTRY_ENVIRONMENT
et al), if an option is set in the script, the env vars are not looked at at all.
So your order is OK. Consistency trumps other concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comments, otherwise looks good!
This commit enables the
keep_alive
option to be set via theSENTRY_KEEP_ALIVE
environment variable. When both the environment variable and the argument are provided, the argument takes precedence.Closes #4354