-
Notifications
You must be signed in to change notification settings - Fork 544
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import contextlib | ||
import os | ||
import json | ||
import subprocess | ||
|
@@ -1496,3 +1497,66 @@ def test_dropped_transaction(sentry_init, capture_record_lost_event_calls, test_ | |
def test_enable_tracing_deprecated(sentry_init, enable_tracing): | ||
with pytest.warns(DeprecationWarning): | ||
sentry_init(enable_tracing=enable_tracing) | ||
|
||
|
||
def make_options_transport_cls(): | ||
"""Make an options transport class that captures the options passed to it.""" | ||
# We need a unique class for each test so that the options are not | ||
# shared between tests. | ||
|
||
class OptionsTransport(Transport): | ||
"""Transport that captures the options passed to it.""" | ||
|
||
def __init__(self, options): | ||
super().__init__(options) | ||
type(self).options = options | ||
|
||
def capture_envelope(self, _): | ||
pass | ||
|
||
return OptionsTransport | ||
|
||
|
||
@contextlib.contextmanager | ||
def clear_env_var(name): | ||
"""Helper to clear the a given environment variable, | ||
and restore it to its original value on exit.""" | ||
old_value = os.environ.pop(name, None) | ||
|
||
try: | ||
yield | ||
finally: | ||
if old_value is not None: | ||
os.environ[name] = old_value | ||
elif name in os.environ: | ||
del os.environ[name] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("env_value", "arg_value", "expected_value"), | ||
[ | ||
(None, None, False), # default | ||
("0", None, False), # env var false | ||
("1", None, True), # env var true | ||
(None, False, False), # arg false | ||
(None, True, True), # arg true | ||
# Argument overrides environment variable | ||
("0", True, True), # env false, arg true | ||
("1", False, False), # env true, arg false | ||
szokeasaurusrex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
) | ||
def test_keep_alive(env_value, arg_value, expected_value): | ||
transport_cls = make_options_transport_cls() | ||
keep_alive_kwarg = {} if arg_value is None else {"keep_alive": arg_value} | ||
|
||
with clear_env_var("SENTRY_KEEP_ALIVE"): | ||
if env_value is not None: | ||
os.environ["SENTRY_KEEP_ALIVE"] = env_value | ||
|
||
sentry_sdk.init( | ||
dsn="http://[email protected]/123", | ||
transport=transport_cls, | ||
**keep_alive_kwarg, | ||
) | ||
|
||
assert transport_cls.options["keep_alive"] is expected_value |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.