Skip to content

Commit cf9f93d

Browse files
committed
Add glob match to httplib ignore hostname.
1 parent 57898ce commit cf9f93d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

aws_xray_sdk/ext/httplib/patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import namedtuple
22
import sys
33
import wrapt
4-
4+
import fnmatch
55
import urllib3.connection
66

77
from aws_xray_sdk.core import xray_recorder
@@ -106,7 +106,7 @@ def _ignore_request(subclass, hostname, url):
106106
global _XRAY_IGNORE
107107
for rule in _XRAY_IGNORE:
108108
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
109+
host_match = fnmatch.fnmatch(hostname, rule.hostname) if rule.hostname is not None else True
110110
url_match = url in rule.urls if rule.urls is not None else True
111111
if url_match and host_match and subclass_match:
112112
return True

tests/ext/httplib/test_httplib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ def test_ignore_hostname():
163163
reset_ignored()
164164

165165

166+
def test_ignore_hostname_glob():
167+
from aws_xray_sdk.ext.httplib import add_ignored, reset_ignored
168+
path = '/status/200'
169+
url = 'https://{}{}'.format(BASE_URL, path)
170+
add_ignored(hostname='http*.org')
171+
_do_req(url, use_https=True)
172+
assert len(xray_recorder.current_segment().subsegments) == 0
173+
reset_ignored()
174+
175+
166176
def test_ignore_subclass():
167177
class TestClass(httplib.HTTPSConnection):
168178
pass

0 commit comments

Comments
 (0)