Skip to content

Commit 26c2844

Browse files
authored
add "*principal*" to list of sanitized field names (#1664)
* add "*principal*" to list of sanitized field names closes #1641 * update docs and changelog * revert masking
1 parent 8b88555 commit 26c2844

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ endif::[]
3737
===== Features
3838
* Add backend granularity data to SQL backends as well as Cassandra and pymongo {pull}1585[#1585], {pull}1639[#1639]
3939
* Add support for instrumenting the Elasticsearch 8 Python client {pull}1642[#1642]
40+
* Add `*principal*` to default `sanitize_field_names` configuration {pull}1664[#1664]
4041
* Add docs and better support for custom metrics, including in AWS Lambda {pull}1643[#1643]
4142
4243
[float]

docs/configuration.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ WARNING: We recommend always including the default set of validators if you cust
876876
"*credit*",
877877
"*card*",
878878
"*auth*",
879+
"*principal*",
879880
"set-cookie"]`
880881
|============
881882

elasticapm/conf/constants.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
import decimal
3232
import re
3333
from collections import namedtuple
34+
from typing import Pattern
3435

3536

36-
def _starmatch_to_regex(pattern):
37+
def _starmatch_to_regex(pattern: str) -> Pattern:
3738
"""
3839
This is a duplicate of starmatch_to_regex() in utils/__init__.py
3940
4041
Duplication to avoid circular imports
4142
"""
4243
options = re.DOTALL
43-
# check if we are case sensitive
44+
# check if we are case-sensitive
4445
if pattern.startswith("(?-i)"):
4546
pattern = pattern[5:]
4647
else:
@@ -98,6 +99,7 @@ def _starmatch_to_regex(pattern):
9899
"*credit*",
99100
"*card*",
100101
"*auth*",
102+
"*principal*",
101103
"set-cookie",
102104
]
103105

@@ -107,12 +109,7 @@ def _starmatch_to_regex(pattern):
107109
SUCCESS="success", FAILURE="failure", UNKNOWN="unknown"
108110
)
109111

110-
try:
111-
# Python 2
112-
LABEL_TYPES = (bool, int, long, float, decimal.Decimal)
113-
except NameError:
114-
# Python 3
115-
LABEL_TYPES = (bool, int, float, decimal.Decimal)
112+
LABEL_TYPES = (bool, int, float, decimal.Decimal)
116113

117114
TRACESTATE = namedtuple("TRACESTATE", ["SAMPLE_RATE"])(SAMPLE_RATE="s")
118115
TRACE_CONTINUATION_STRATEGY = namedtuple("TRACE_CONTINUATION_STRATEGY", ["CONTINUE", "RESTART", "RESTART_EXTERNAL"])(

elasticapm/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def read_pem_file(file_obj) -> bytes:
183183

184184
def starmatch_to_regex(pattern: str) -> Pattern:
185185
options = re.DOTALL
186-
# check if we are case sensitive
186+
# check if we are case-sensitive
187187
if pattern.startswith("(?-i)"):
188188
pattern = pattern[5:]
189189
else:

tests/processors/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def http_test_data():
6363
"authorization": "bearer xyz",
6464
"some-header": "some-secret-value",
6565
"cookie": "foo=bar; baz=foo",
66+
"Ms-Client-Principal-Id": "foo",
6667
},
6768
"cookies": {
6869
"foo": "bar",
@@ -85,6 +86,7 @@ def http_test_data():
8586
"authorization": "bearer xyz",
8687
"some-header": "some-secret-value",
8788
"cookie": "foo=bar; baz=foo",
89+
"Ms-Client-Principal-Id": "foo",
8890
},
8991
},
9092
}
@@ -296,6 +298,7 @@ def test_sanitize_http_headers(elasticapm_client, custom_header, http_test_data)
296298
"password": processors.MASK,
297299
"secret": processors.MASK,
298300
"authorization": processors.MASK,
301+
"Ms-Client-Principal-Id": processors.MASK,
299302
}
300303
expected.update(custom_header)
301304
assert result["context"]["request"]["headers"] == expected

0 commit comments

Comments
 (0)