Skip to content

Commit ae06e28

Browse files
authored
Merge pull request #128 from chanchiem/master
Update Readme: Disabling the SDK
2 parents d081441 + 451c95d commit ae06e28

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,34 @@ if xray_recorder.is_sampled():
191191
xray_recorder.put_metadata('mykey', metadata)
192192
```
193193

194+
### Disabling X-Ray
195+
Often times, it may be useful to be able to disable X-Ray for specific use cases, whether to stop X-Ray from sending traces at any moment, or to test code functionality that originally depended on X-Ray instrumented packages to begin segments prior to the code call. For example, if your application relied on an XRayMiddleware to instrument incoming web requests, and you have a method which begins subsegments based on the segment generated by that middleware, it would be useful to be able to disable X-Ray for your unit tests so that `SegmentNotFound` exceptions are not thrown when you need to test your method.
196+
197+
There are two ways to disable X-Ray, one is through environment variables, and the other is through the SDKConfig module.
198+
199+
**Disabling through the environment variable:**
200+
201+
Prior to running your application, make sure to have the environment variable `AWS_XRAY_SDK_ENABLED` set to `false`.
202+
203+
**Disabling through the SDKConfig module:**
204+
```
205+
from aws_xray_sdk import global_sdk_config
206+
207+
global_sdk_config.set_sdk_enabled(False)
208+
```
209+
210+
**Important Notes:**
211+
* Environment Variables always take precedence over the SDKConfig module when disabling/enabling. If your environment variable is set to `false` while your code calls `global_sdk_config.set_sdk_enabled(True)`, X-Ray will still be disabled.
212+
213+
* If you need to re-enable X-Ray again during runtime and acknowledge disabling/enabling through the SDKConfig module, you may run the following in your application:
214+
```
215+
import os
216+
from aws_xray_sdk import global_sdk_config
217+
218+
del os.environ['AWS_XRAY_SDK_ENABLED']
219+
global_sdk_config.set_sdk_enabled(True)
220+
```
221+
194222
### Trace AWS Lambda functions
195223

196224
```python

0 commit comments

Comments
 (0)