Skip to content

disable xray at runtime #172

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

Open
ozgurakcali opened this issue Aug 30, 2019 · 3 comments
Open

disable xray at runtime #172

ozgurakcali opened this issue Aug 30, 2019 · 3 comments

Comments

@ozgurakcali
Copy link

On my django project, xray is configured to trace db queries.

In this use casem is it possible to disable / re-enable xray at runtime? What I want to do is,

from aws_xray_sdk import global_sdk_config

global_sdk_config.set_sdk_enabled(False) # Disable xray

## Do stuff with xray disabled

del os.environ['AWS_XRAY_SDK_ENABLED'] # Re-enable xray
global_sdk_config.set_sdk_enabled(True)

When I run the code like this, I still get error logs from xray (and my main problem is addressed here: #21 , but the suggested solution did not solve the issue for me)

And I could not understand from the docs whether
global_sdk_config.set_sdk_enabled(False)
would disable xray at runtime or if it was designed to disable xray before running an application.

@chanchiem
Copy link
Contributor

Hi,

As long as the environment variable AWS_XRAY_SDK_ENABLED is set, any call to global_sdk_config.set_sdk_enabled(xxx) will set enable or disable the SDK based on what's set in the env variable.

By disabling the SDK, the code path should never reach the emitter, which leads me to believe that you are hitting an edge case.

Are you making sure that the env variable AWS_XRAY_SDK_ENABLED is not set to True before you start executing stuff with xray disabled? What I would recommend doing is either deleting the environment variable on start up, or not have one set at all for your use case.

If this doesn't resolve your issue, can you also post a copy of what log errors you are seeing?

Thanks,
Chan Chiem Jeffery Saeteurn

@shogo82148
Copy link

I wonder this behavior of the SDK.

I expect that setting the the config from my program overrides the values from the environment values.
I think it is very common behavior.

For example, I can do it with botocore.

https://github.com/boto/botocore/blob/38845a7e0f2969edfd82ae6744e36f22e75e08eb/botocore/configprovider.py#L173-L174

In botocore most of our config chains follow the the precendence:
session_instance_variables, environment, config_file, default_value.

an example from the document of botocore.

https://github.com/boto/botocore/blob/38845a7e0f2969edfd82ae6744e36f22e75e08eb/botocore/session.py#L270-L291

        >>> # Assume logical name 'foo' maps to env var 'FOO'
        >>> os.environ['FOO'] = 'myvalue'
        >>> s.get_config_variable('foo')
        'myvalue'
        >>> s.set_config_variable('foo', 'othervalue')
        >>> s.get_config_variable('foo')
        'othervalue'

The config precedence of X-Ray-SDK is not match with botocore.
Is it X-Ray SDK's policy?

@chanchiem
Copy link
Contributor

chanchiem commented Jan 23, 2020

According to the documentation:

AWS_XRAY_SDK_ENABLED – When set to false, disables the SDK. By default, the SDK is enabled unless the environment variable is set to false.

When disabled, the global recorder automatically generates dummy segments and subsegments that are not sent to the daemon, and automatic patching is disabled. Middlewares are written as a wrapper over the global recorder. All segment and subsegment generation through the middleware also become dummy segment and dummy subsegments.

Set the value of AWS_XRAY_SDK_ENABLED through the environment variable or through direct interaction with the global_sdk_config object from the aws_xray_sdk library. Settings to the environment variable override these interactions.

The order of precedence is Env Variables > Programatic configuration. We can take this as a feature request to change the ordering, but this is added by design so that customers can override programmatic behaviors when they for example write test code.

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

No branches or pull requests

4 participants