|
15 | 15 | import unittest
|
16 | 16 | from http import HTTPStatus
|
17 | 17 |
|
| 18 | +from opentelemetry.context import ( |
| 19 | + _SUPPRESS_HTTP_INSTRUMENTATION_KEY, |
| 20 | + _SUPPRESS_INSTRUMENTATION_KEY, |
| 21 | + get_current, |
| 22 | + get_value, |
| 23 | +) |
18 | 24 | from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment
|
19 | 25 | from opentelemetry.instrumentation.utils import (
|
20 | 26 | _python_path_without_directory,
|
21 | 27 | http_status_to_status_code,
|
| 28 | + is_http_instrumentation_enabled, |
| 29 | + is_instrumentation_enabled, |
| 30 | + suppress_http_instrumentation, |
| 31 | + suppress_instrumentation, |
22 | 32 | )
|
23 | 33 | from opentelemetry.trace import StatusCode
|
24 | 34 |
|
@@ -186,3 +196,47 @@ def test_add_sql_comments_without_comments(self):
|
186 | 196 | )
|
187 | 197 |
|
188 | 198 | self.assertEqual(commented_sql_without_semicolon, "Select 1")
|
| 199 | + |
| 200 | + def test_is_instrumentation_enabled_by_default(self): |
| 201 | + self.assertTrue(is_instrumentation_enabled()) |
| 202 | + self.assertTrue(is_http_instrumentation_enabled()) |
| 203 | + |
| 204 | + def test_suppress_instrumentation(self): |
| 205 | + with suppress_instrumentation(): |
| 206 | + self.assertFalse(is_instrumentation_enabled()) |
| 207 | + self.assertFalse(is_http_instrumentation_enabled()) |
| 208 | + |
| 209 | + self.assertTrue(is_instrumentation_enabled()) |
| 210 | + self.assertTrue(is_http_instrumentation_enabled()) |
| 211 | + |
| 212 | + def test_suppress_http_instrumentation(self): |
| 213 | + with suppress_http_instrumentation(): |
| 214 | + self.assertFalse(is_http_instrumentation_enabled()) |
| 215 | + self.assertTrue(is_instrumentation_enabled()) |
| 216 | + |
| 217 | + self.assertTrue(is_instrumentation_enabled()) |
| 218 | + self.assertTrue(is_http_instrumentation_enabled()) |
| 219 | + |
| 220 | + def test_suppress_instrumentation_key(self): |
| 221 | + self.assertIsNone(get_value(_SUPPRESS_INSTRUMENTATION_KEY)) |
| 222 | + self.assertIsNone(get_value("suppress_instrumentation")) |
| 223 | + |
| 224 | + with suppress_instrumentation(): |
| 225 | + ctx = get_current() |
| 226 | + self.assertIn(_SUPPRESS_INSTRUMENTATION_KEY, ctx) |
| 227 | + self.assertIn("suppress_instrumentation", ctx) |
| 228 | + self.assertTrue(get_value(_SUPPRESS_INSTRUMENTATION_KEY)) |
| 229 | + self.assertTrue(get_value("suppress_instrumentation")) |
| 230 | + |
| 231 | + self.assertIsNone(get_value(_SUPPRESS_INSTRUMENTATION_KEY)) |
| 232 | + self.assertIsNone(get_value("suppress_instrumentation")) |
| 233 | + |
| 234 | + def test_suppress_http_instrumentation_key(self): |
| 235 | + self.assertIsNone(get_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY)) |
| 236 | + |
| 237 | + with suppress_http_instrumentation(): |
| 238 | + ctx = get_current() |
| 239 | + self.assertIn(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, ctx) |
| 240 | + self.assertTrue(get_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY)) |
| 241 | + |
| 242 | + self.assertIsNone(get_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY)) |
0 commit comments