|
22 | 22 |
|
23 | 23 | _XRAY_PROP = '_xray_prop'
|
24 | 24 | _XRay_Data = namedtuple('xray_data', ['method', 'host', 'url'])
|
| 25 | +_XRay_Ignore = namedtuple('xray_ignore', ['subclass', 'hostname', 'urls']) |
25 | 26 | # A flag indicates whether this module is X-Ray patched or not
|
26 | 27 | PATCH_FLAG = '__xray_patched'
|
| 28 | +# Calls that should be ignored |
| 29 | +_XRAY_IGNORE = set() |
| 30 | + |
| 31 | + |
| 32 | +def add_ignored(subclass=None, hostname=None, urls=None): |
| 33 | + global _XRAY_IGNORE |
| 34 | + if subclass is not None or hostname is not None or urls is not None: |
| 35 | + urls = urls if urls is None else tuple(urls) |
| 36 | + _XRAY_IGNORE.add(_XRay_Ignore(subclass=subclass, hostname=hostname, urls=urls)) |
| 37 | + |
| 38 | + |
| 39 | +def reset_ignored(): |
| 40 | + global _XRAY_IGNORE |
| 41 | + _XRAY_IGNORE.clear() |
| 42 | + _ignored_add_default() |
| 43 | + |
| 44 | + |
| 45 | +def _ignored_add_default(): |
| 46 | + # skip httplib tracing for SDK built-in centralized sampling pollers |
| 47 | + add_ignored(subclass='botocore.awsrequest.AWSHTTPConnection', urls=['/GetSamplingRules', '/SamplingTargets']) |
| 48 | + |
| 49 | + |
| 50 | +# make sure we have the default rules |
| 51 | +_ignored_add_default() |
27 | 52 |
|
28 | 53 |
|
29 | 54 | def http_response_processor(wrapped, instance, args, kwargs, return_value,
|
@@ -77,11 +102,21 @@ def http_send_request_processor(wrapped, instance, args, kwargs, return_value,
|
77 | 102 | subsegment.add_exception(exception, stack)
|
78 | 103 |
|
79 | 104 |
|
| 105 | +def _ignore_request(subclass, hostname, url): |
| 106 | + global _XRAY_IGNORE |
| 107 | + for rule in _XRAY_IGNORE: |
| 108 | + subclass_match = subclass == rule.subclass if rule.subclass is not None else True |
| 109 | + host_match = hostname == rule.hostname if rule.hostname is not None else True |
| 110 | + url_match = url in rule.urls if rule.urls is not None else True |
| 111 | + if url_match and host_match and subclass_match: |
| 112 | + return True |
| 113 | + return False |
| 114 | + |
| 115 | + |
80 | 116 | def _send_request(wrapped, instance, args, kwargs):
|
81 | 117 | def decompose_args(method, url, body, headers, encode_chunked=False):
|
82 |
| - # skip httplib tracing for SDK built-in centralized sampling pollers |
83 |
| - if (('/GetSamplingRules' in args or '/SamplingTargets' in args) and |
84 |
| - type(instance).__name__ == 'botocore.awsrequest.AWSHTTPConnection'): |
| 118 | + # skip any ignored requests |
| 119 | + if _ignore_request(type(instance).__name__, instance.host, url): |
85 | 120 | return wrapped(*args, **kwargs)
|
86 | 121 |
|
87 | 122 | # Only injects headers when the subsegment for the outgoing
|
|
0 commit comments