|
27 | 27 | from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
|
28 | 28 | from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
29 | 29 | from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
|
| 30 | +from opentelemetry.instrumentation._semconv import ( |
| 31 | + _OTEL_SEMCONV_STABILITY_OPT_IN_KEY, |
| 32 | + _OpenTelemetrySemanticConventionStability, |
| 33 | +) |
30 | 34 | from opentelemetry.propagate import get_global_textmap, set_global_textmap
|
31 | 35 | from opentelemetry.sdk import resources
|
32 | 36 | from opentelemetry.semconv.trace import SpanAttributes
|
@@ -64,17 +68,30 @@ class RequestsIntegrationTestBase(abc.ABC):
|
64 | 68 | # pylint: disable=too-many-public-methods
|
65 | 69 |
|
66 | 70 | URL = "http://mock/status/200"
|
| 71 | + HOST = "mock/status" |
67 | 72 |
|
68 | 73 | # pylint: disable=invalid-name
|
69 | 74 | def setUp(self):
|
70 | 75 | super().setUp()
|
71 | 76 |
|
| 77 | + test_name = "" |
| 78 | + if hasattr(self, "_testMethodName"): |
| 79 | + test_name = self._testMethodName |
| 80 | + sem_conv_mode = "default" |
| 81 | + if "new_semconv" in test_name: |
| 82 | + sem_conv_mode = "http" |
| 83 | + elif "both_semconv" in test_name: |
| 84 | + sem_conv_mode = "http/dup" |
72 | 85 | self.env_patch = mock.patch.dict(
|
73 | 86 | "os.environ",
|
74 | 87 | {
|
75 |
| - "OTEL_PYTHON_REQUESTS_EXCLUDED_URLS": "http://localhost/env_excluded_arg/123,env_excluded_noarg" |
| 88 | + "OTEL_PYTHON_REQUESTS_EXCLUDED_URLS": "http://localhost/env_excluded_arg/123,env_excluded_noarg", |
| 89 | + _OTEL_SEMCONV_STABILITY_OPT_IN_KEY: sem_conv_mode, |
76 | 90 | },
|
77 | 91 | )
|
| 92 | + |
| 93 | + _OpenTelemetrySemanticConventionStability._initialized = False |
| 94 | + |
78 | 95 | self.env_patch.start()
|
79 | 96 |
|
80 | 97 | self.exclude_patch = mock.patch(
|
@@ -133,6 +150,34 @@ def test_basic(self):
|
133 | 150 | span, opentelemetry.instrumentation.requests
|
134 | 151 | )
|
135 | 152 |
|
| 153 | + |
| 154 | + # def test_basic_new_semconv(self): |
| 155 | + # print("here2") |
| 156 | + # result = self.perform_request(self.URL) |
| 157 | + # self.assertEqual(result.text, "Hello!") |
| 158 | + # span = self.assert_span() |
| 159 | + |
| 160 | + # self.assertIs(span.kind, trace.SpanKind.CLIENT) |
| 161 | + # self.assertEqual(span.name, "GET") |
| 162 | + |
| 163 | + # self.assertEqual( |
| 164 | + # span.attributes, |
| 165 | + # { |
| 166 | + # SpanAttributes.HTTP_REQUEST_METHOD: "GET", |
| 167 | + # SpanAttributes.HTTP_REQUEST_METHOD_ORIGINAL: "GET", |
| 168 | + # SpanAttributes.URL_FULL: self.URL, |
| 169 | + # SpanAttributes.HTTP_RESPONSE_STATUS_CODE: 200, |
| 170 | + # SpanAttributes.SERVER_ADDRESS: self.HOST, |
| 171 | + # }, |
| 172 | + # ) |
| 173 | + |
| 174 | + # self.assertIs(span.status.status_code, trace.StatusCode.UNSET) |
| 175 | + |
| 176 | + # self.assertEqualSpanInstrumentationInfo( |
| 177 | + # span, opentelemetry.instrumentation.requests |
| 178 | + # ) |
| 179 | + |
| 180 | + |
136 | 181 | def test_hooks(self):
|
137 | 182 | def request_hook(span, request_obj):
|
138 | 183 | span.update_name("name set from hook")
|
|
0 commit comments