|
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from unittest.mock import patch |
| 16 | + |
| 17 | +from opentelemetry.test.test_base import TestBase |
| 18 | +from opentelemetry.util.http import get_excluded_urls |
| 19 | + |
| 20 | + |
| 21 | +class TestGetExcludedUrls(TestBase): |
| 22 | + @patch.dict( |
| 23 | + "os.environ", |
| 24 | + { |
| 25 | + "OTEL_PYTHON_DJANGO_EXCLUDED_URLS": "excluded_arg/123,excluded_noarg" |
| 26 | + }, |
| 27 | + ) |
| 28 | + def test_config_from_instrumentation_env(self): |
| 29 | + exclude_list = get_excluded_urls("DJANGO") |
| 30 | + |
| 31 | + self.assertTrue(exclude_list.url_disabled("/excluded_arg/123")) |
| 32 | + self.assertTrue(exclude_list.url_disabled("/excluded_noarg")) |
| 33 | + self.assertFalse(exclude_list.url_disabled("/excluded_arg/125")) |
| 34 | + |
| 35 | + @patch.dict( |
| 36 | + "os.environ", |
| 37 | + {"OTEL_PYTHON_EXCLUDED_URLS": "excluded_arg/123,excluded_noarg"}, |
| 38 | + ) |
| 39 | + def test_config_from_generic_env(self): |
| 40 | + exclude_list = get_excluded_urls("DJANGO") |
| 41 | + |
| 42 | + self.assertTrue(exclude_list.url_disabled("/excluded_arg/123")) |
| 43 | + self.assertTrue(exclude_list.url_disabled("/excluded_noarg")) |
| 44 | + self.assertFalse(exclude_list.url_disabled("/excluded_arg/125")) |
| 45 | + |
| 46 | + @patch.dict( |
| 47 | + "os.environ", |
| 48 | + { |
| 49 | + "OTEL_PYTHON_DJANGO_EXCLUDED_URLS": "excluded_arg/123,excluded_noarg", |
| 50 | + "OTEL_PYTHON_EXCLUDED_URLS": "excluded_arg/125", |
| 51 | + }, |
| 52 | + ) |
| 53 | + def test_config_from_instrumentation_env_takes_precedence(self): |
| 54 | + exclude_list = get_excluded_urls("DJANGO") |
| 55 | + |
| 56 | + self.assertTrue(exclude_list.url_disabled("/excluded_arg/123")) |
| 57 | + self.assertTrue(exclude_list.url_disabled("/excluded_noarg")) |
| 58 | + self.assertFalse(exclude_list.url_disabled("/excluded_arg/125")) |
| 59 | + |
| 60 | + @patch.dict( |
| 61 | + "os.environ", |
| 62 | + { |
| 63 | + "OTEL_PYTHON_DJANGO_EXCLUDED_URLS": "", |
| 64 | + "OTEL_PYTHON_EXCLUDED_URLS": "excluded_arg/125", |
| 65 | + }, |
| 66 | + ) |
| 67 | + def test_config_from_instrumentation_env_empty(self): |
| 68 | + exclude_list = get_excluded_urls("DJANGO") |
| 69 | + |
| 70 | + self.assertFalse(exclude_list.url_disabled("/excluded_arg/123")) |
| 71 | + self.assertFalse(exclude_list.url_disabled("/excluded_noarg")) |
| 72 | + self.assertFalse(exclude_list.url_disabled("/excluded_arg/125")) |
0 commit comments