mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 05:04:05 +08:00
@ -5,11 +5,11 @@
|
||||
# run arbitrary code.
|
||||
extension-pkg-whitelist=
|
||||
|
||||
# Add files or directories to the blacklist. They should be base names, not
|
||||
# Add files or directories to the denylist. They should be base names, not
|
||||
# paths.
|
||||
ignore=CVS,gen
|
||||
|
||||
# Add files or directories matching the regex patterns to the blacklist. The
|
||||
# Add files or directories matching the regex patterns to the denylist. The
|
||||
# regex matches against base names, not paths.
|
||||
ignore-patterns=
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
from ..utils.formats import flatten_dict
|
||||
|
||||
|
||||
BLACKLIST_ENDPOINT = ['kms', 'sts']
|
||||
BLACKLIST_ENDPOINT_TAGS = {
|
||||
DENYLIST_ENDPOINT = ['kms', 'sts']
|
||||
DENYLIST_ENDPOINT_TAGS = {
|
||||
's3': ['params.Body'],
|
||||
}
|
||||
|
||||
@ -18,8 +18,8 @@ def truncate_arg_value(value, max_len=1024):
|
||||
|
||||
|
||||
def add_span_arg_tags(span, endpoint_name, args, args_names, args_traced):
|
||||
if endpoint_name not in BLACKLIST_ENDPOINT:
|
||||
blacklisted = BLACKLIST_ENDPOINT_TAGS.get(endpoint_name, [])
|
||||
if endpoint_name not in DENYLIST_ENDPOINT:
|
||||
denylisted = DENYLIST_ENDPOINT_TAGS.get(endpoint_name, [])
|
||||
tags = dict(
|
||||
(name, value)
|
||||
for (name, value) in zip(args_names, args)
|
||||
@ -29,7 +29,7 @@ def add_span_arg_tags(span, endpoint_name, args, args_names, args_traced):
|
||||
tags = {
|
||||
k: truncate_arg_value(v)
|
||||
for k, v in tags.items()
|
||||
if k not in blacklisted
|
||||
if k not in denylisted
|
||||
}
|
||||
span.set_tags(tags)
|
||||
|
||||
|
@ -17,7 +17,7 @@ NORMALIZE_PATTERN = re.compile(r'([^a-z0-9_\-:/]){1}')
|
||||
def store_request_headers(headers, span, integration_config):
|
||||
"""
|
||||
Store request headers as a span's tags
|
||||
:param headers: All the request's http headers, will be filtered through the whitelist
|
||||
:param headers: All the request's http headers, will be filtered through the allowlist
|
||||
:type headers: dict or list
|
||||
:param span: The Span instance where tags will be stored
|
||||
:type span: ddtrace.Span
|
||||
@ -30,7 +30,7 @@ def store_request_headers(headers, span, integration_config):
|
||||
def store_response_headers(headers, span, integration_config):
|
||||
"""
|
||||
Store response headers as a span's tags
|
||||
:param headers: All the response's http headers, will be filtered through the whitelist
|
||||
:param headers: All the response's http headers, will be filtered through the allowlist
|
||||
:type headers: dict or list
|
||||
:param span: The Span instance where tags will be stored
|
||||
:type span: ddtrace.Span
|
||||
|
@ -86,15 +86,15 @@ class Config(object):
|
||||
else:
|
||||
self._config[integration] = IntegrationConfig(self, integration, settings)
|
||||
|
||||
def trace_headers(self, whitelist):
|
||||
def trace_headers(self, allowlist):
|
||||
"""
|
||||
Registers a set of headers to be traced at global level or integration level.
|
||||
:param whitelist: the case-insensitive list of traced headers
|
||||
:type whitelist: list of str or str
|
||||
:param allowlist: the case-insensitive list of traced headers
|
||||
:type allowlist: list of str or str
|
||||
:return: self
|
||||
:rtype: HttpConfig
|
||||
"""
|
||||
self._http.trace_headers(whitelist)
|
||||
self._http.trace_headers(allowlist)
|
||||
return self
|
||||
|
||||
def header_is_traced(self, header_name):
|
||||
|
@ -11,30 +11,30 @@ class HttpConfig(object):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._whitelist_headers = set()
|
||||
self._allowlist_headers = set()
|
||||
self.trace_query_string = None
|
||||
|
||||
@property
|
||||
def is_header_tracing_configured(self):
|
||||
return len(self._whitelist_headers) > 0
|
||||
return len(self._allowlist_headers) > 0
|
||||
|
||||
def trace_headers(self, whitelist):
|
||||
def trace_headers(self, allowlist):
|
||||
"""
|
||||
Registers a set of headers to be traced at global level or integration level.
|
||||
:param whitelist: the case-insensitive list of traced headers
|
||||
:type whitelist: list of str or str
|
||||
:param allowlist: the case-insensitive list of traced headers
|
||||
:type allowlist: list of str or str
|
||||
:return: self
|
||||
:rtype: HttpConfig
|
||||
"""
|
||||
if not whitelist:
|
||||
if not allowlist:
|
||||
return
|
||||
|
||||
whitelist = [whitelist] if isinstance(whitelist, str) else whitelist
|
||||
for whitelist_entry in whitelist:
|
||||
normalized_header_name = normalize_header_name(whitelist_entry)
|
||||
allowlist = [allowlist] if isinstance(allowlist, str) else allowlist
|
||||
for allowlist_entry in allowlist:
|
||||
normalized_header_name = normalize_header_name(allowlist_entry)
|
||||
if not normalized_header_name:
|
||||
continue
|
||||
self._whitelist_headers.add(normalized_header_name)
|
||||
self._allowlist_headers.add(normalized_header_name)
|
||||
|
||||
return self
|
||||
|
||||
@ -46,9 +46,9 @@ class HttpConfig(object):
|
||||
:rtype: bool
|
||||
"""
|
||||
normalized_header_name = normalize_header_name(header_name)
|
||||
log.debug('Checking header \'%s\' tracing in whitelist %s', normalized_header_name, self._whitelist_headers)
|
||||
return normalized_header_name in self._whitelist_headers
|
||||
log.debug('Checking header \'%s\' tracing in allowlist %s', normalized_header_name, self._allowlist_headers)
|
||||
return normalized_header_name in self._allowlist_headers
|
||||
|
||||
def __repr__(self):
|
||||
return '<{} traced_headers={} trace_query_string={}>'.format(
|
||||
self.__class__.__name__, self._whitelist_headers, self.trace_query_string)
|
||||
self.__class__.__name__, self._allowlist_headers, self.trace_query_string)
|
||||
|
@ -390,7 +390,7 @@ Examples::
|
||||
])
|
||||
|
||||
The following rules apply:
|
||||
- headers configuration is based on a whitelist. If a header does not appear in the whitelist, it won't be traced.
|
||||
- headers configuration is based on a allowlist. If a header does not appear in the allowlist, it won't be traced.
|
||||
- headers configuration is case-insensitive.
|
||||
- if you configure a specific integration, e.g. 'requests', then such configuration overrides the default global
|
||||
configuration, only for the specific integration.
|
||||
|
@ -117,7 +117,7 @@ class BotocoreTest(BaseTracerTestCase):
|
||||
self.assertEqual(spans[1].resource, 's3.putobject')
|
||||
self.assertEqual(spans[1].get_tag('params.Key'), stringify(params['Key']))
|
||||
self.assertEqual(spans[1].get_tag('params.Bucket'), stringify(params['Bucket']))
|
||||
# confirm blacklisted
|
||||
# confirm denylisted
|
||||
self.assertIsNone(spans[1].get_tag('params.Body'))
|
||||
|
||||
@mock_sqs
|
||||
|
@ -137,7 +137,7 @@ class TestHeaders(object):
|
||||
}, span, integration_config)
|
||||
assert span.get_tag('http.response.headers.content-type') == ' some;value '
|
||||
|
||||
def test_no_whitelist(self, span, integration_config):
|
||||
def test_no_allowlist(self, span, integration_config):
|
||||
"""
|
||||
:type span: Span
|
||||
:type integration_config: IntegrationConfig
|
||||
@ -147,7 +147,7 @@ class TestHeaders(object):
|
||||
}, span, integration_config)
|
||||
assert span.get_tag('http.response.headers.content-type') is None
|
||||
|
||||
def test_whitelist_exact(self, span, integration_config):
|
||||
def test_allowlist_exact(self, span, integration_config):
|
||||
"""
|
||||
:type span: Span
|
||||
:type integration_config: IntegrationConfig
|
||||
@ -158,7 +158,7 @@ class TestHeaders(object):
|
||||
}, span, integration_config)
|
||||
assert span.get_tag('http.response.headers.content-type') == 'some;value'
|
||||
|
||||
def test_whitelist_case_insensitive(self, span, integration_config):
|
||||
def test_allowlist_case_insensitive(self, span, integration_config):
|
||||
"""
|
||||
:type span: Span
|
||||
:type integration_config: IntegrationConfig
|
||||
|
@ -47,7 +47,7 @@ class TestHttpConfig(BaseTestCase):
|
||||
assert http_config.header_is_traced('some_header')
|
||||
assert not http_config.header_is_traced('some_other_header')
|
||||
|
||||
def test_trace_headers_whitelist_case_insensitive(self):
|
||||
def test_trace_headers_allowlist_case_insensitive(self):
|
||||
http_config = HttpConfig()
|
||||
http_config.trace_headers('some_header')
|
||||
assert http_config.header_is_traced('sOmE_hEaDeR')
|
||||
|
Reference in New Issue
Block a user