Skip to content
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

Add ability to enable/disable the SDK (#26) #119

Merged
merged 8 commits into from
Feb 6, 2019
Prev Previous commit
Add ability to enable/disable the SDK (#26)
Revision 5

Changes:
    - Refactored sampler to use "from ... import ..." for the global sdk config module.
    - global sdk config logs and defaults to true instead of throwing an exception
    when an invalid parameter is passed into the method.
  • Loading branch information
chanchiem committed Feb 6, 2019
commit e443268574d7f28c7907ef8e4f8e5940ab7c243b
6 changes: 3 additions & 3 deletions aws_xray_sdk/core/sampling/sampler.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
from .target_poller import TargetPoller
from .connector import ServiceConnector
from .reservoir import ReservoirDecision
import aws_xray_sdk
from aws_xray_sdk import global_sdk_config

log = logging.getLogger(__name__)

@@ -38,7 +38,7 @@ def start(self):
Start rule poller and target poller once X-Ray daemon address
and context manager is in place.
"""
if not aws_xray_sdk.global_sdk_config.sdk_enabled():
if not global_sdk_config.sdk_enabled():
return

with self._lock:
@@ -55,7 +55,7 @@ def should_trace(self, sampling_req=None):
All optional arguments are extracted from incoming requests by
X-Ray middleware to perform path based sampling.
"""
if not aws_xray_sdk.global_sdk_config.sdk_enabled():
if not global_sdk_config.sdk_enabled():
return False

if not self._started:
12 changes: 3 additions & 9 deletions aws_xray_sdk/sdk_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import os
import logging


class InvalidParameterTypeException(Exception):
"""
Exception thrown when an invalid parameter is passed into SDKConfig.set_sdk_enabled.
"""
pass
log = logging.getLogger(__name__)


class SDKConfig(object):
@@ -59,6 +55,4 @@ def set_sdk_enabled(cls, value):
cls.__SDK_ENABLED = value
else:
cls.__SDK_ENABLED = True
raise InvalidParameterTypeException(
"Invalid parameter type passed into set_sdk_enabled(). Defaulting to True..."
)
log.warning("Invalid parameter type passed into set_sdk_enabled(). Defaulting to True...")
1 change: 0 additions & 1 deletion tests/test_recorder.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@
from aws_xray_sdk.core.models.dummy_entities import DummySegment, DummySubsegment

xray_recorder = get_new_stubbed_recorder()
XRAY_ENABLED_KEY = global_sdk_config.XRAY_ENABLED_KEY


@pytest.fixture(autouse=True)