Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 10dc017

Browse files
author
Jonas Miederer
committed
check excluded tracing paths based on regex
1 parent d63d295 commit 10dc017

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

opencensus/trace/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def disable_tracing_url(url, excludelist_paths=None):
6464
url_path = url.split('/', 1)[1]
6565

6666
for path in excludelist_paths:
67-
if url_path.startswith(path):
67+
if re.match(path, url_path):
6868
return True
6969

7070
return False

tests/unit/trace/test_ext_utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,48 @@ def test_disable_tracing_url_explicit(self):
5858
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
5959
self.assertTrue(disable_tracing)
6060

61+
def test_disable_tracing_url_partial(self):
62+
url = 'http://127.0.0.1:8080/test_no_tracing'
63+
excludelist_paths = ['test']
64+
65+
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
66+
self.assertTrue(disable_tracing)
67+
68+
def test_disable_tracing_url_partial_regex_match(self):
69+
url = 'http://127.0.0.1:8080/test_no_tracing'
70+
excludelist_paths = ['^test']
71+
72+
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
73+
self.assertTrue(disable_tracing)
74+
75+
def test_disable_tracing_url_partial_regex_nomatch(self):
76+
url = 'http://127.0.0.1:8080/test_no_tracing'
77+
excludelist_paths = ['test$']
78+
79+
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
80+
self.assertFalse(disable_tracing)
81+
82+
def test_disable_tracing_url_root(self):
83+
url = 'http://127.0.0.1:8080/'
84+
excludelist_paths = ['']
85+
86+
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
87+
self.assertTrue(disable_tracing)
88+
89+
def test_disable_tracing_url_root_regex(self):
90+
url = 'http://127.0.0.1:8080/'
91+
excludelist_paths = ['^$']
92+
93+
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
94+
self.assertTrue(disable_tracing)
95+
96+
def test_disable_tracing_url_root_empty_exclude(self):
97+
url = 'http://127.0.0.1:8080/test_no_tracing'
98+
excludelist_paths = ['']
99+
100+
disable_tracing = utils.disable_tracing_url(url, excludelist_paths)
101+
self.assertTrue(disable_tracing)
102+
61103
def test_disable_tracing_hostname_default(self):
62104
url = '127.0.0.1:8080'
63105

0 commit comments

Comments
 (0)