Skip to content

Commit f20fa77

Browse files
EzzioMoreiraxrmx
andauthored
refactor: opentelemetry-instrumentation-urllib (#3639)
Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent f9453b9 commit f20fa77

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def response_hook(span: Span, request: Request, response: HTTPResponse):
119119
)
120120
from opentelemetry.metrics import Histogram, Meter, get_meter
121121
from opentelemetry.propagate import inject
122+
from opentelemetry.semconv._incubating.attributes.http_attributes import (
123+
HTTP_URL,
124+
)
122125
from opentelemetry.semconv._incubating.metrics.http_metrics import (
123126
HTTP_CLIENT_REQUEST_BODY_SIZE,
124127
HTTP_CLIENT_RESPONSE_BODY_SIZE,
@@ -130,7 +133,6 @@ def response_hook(span: Span, request: Request, response: HTTPResponse):
130133
from opentelemetry.semconv.metrics.http_metrics import (
131134
HTTP_CLIENT_REQUEST_DURATION,
132135
)
133-
from opentelemetry.semconv.trace import SpanAttributes
134136
from opentelemetry.trace import Span, SpanKind, Tracer, get_tracer
135137
from opentelemetry.util.http import (
136138
ExcludeList,
@@ -325,7 +327,7 @@ def _instrumented_open_call(
325327
sem_conv_opt_in_mode=_StabilityMode.HTTP,
326328
)
327329

328-
duration_attrs_old[SpanAttributes.HTTP_URL] = url
330+
duration_attrs_old[HTTP_URL] = url
329331

330332
_record_histograms(
331333
histograms,

instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@
3838
)
3939
from opentelemetry.propagate import get_global_textmap, set_global_textmap
4040
from opentelemetry.sdk import resources
41+
from opentelemetry.semconv._incubating.attributes.http_attributes import (
42+
HTTP_METHOD,
43+
HTTP_STATUS_CODE,
44+
HTTP_URL,
45+
)
4146
from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
4247
from opentelemetry.semconv.attributes.http_attributes import (
4348
HTTP_REQUEST_METHOD,
4449
HTTP_RESPONSE_STATUS_CODE,
4550
)
4651
from opentelemetry.semconv.attributes.url_attributes import URL_FULL
47-
from opentelemetry.semconv.trace import SpanAttributes
4852
from opentelemetry.test.mock_textmap import MockTextMapPropagator
4953
from opentelemetry.test.test_base import TestBase
5054
from opentelemetry.trace import StatusCode
@@ -150,9 +154,9 @@ def test_basic(self):
150154
self.assertEqual(
151155
span.attributes,
152156
{
153-
SpanAttributes.HTTP_METHOD: "GET",
154-
SpanAttributes.HTTP_URL: self.URL,
155-
SpanAttributes.HTTP_STATUS_CODE: 200,
157+
HTTP_METHOD: "GET",
158+
HTTP_URL: self.URL,
159+
HTTP_STATUS_CODE: 200,
156160
},
157161
)
158162

@@ -198,9 +202,9 @@ def test_basic_both_semconv(self):
198202
self.assertEqual(
199203
span.attributes,
200204
{
201-
SpanAttributes.HTTP_METHOD: "GET",
202-
SpanAttributes.HTTP_URL: self.URL,
203-
SpanAttributes.HTTP_STATUS_CODE: 200,
205+
HTTP_METHOD: "GET",
206+
HTTP_URL: self.URL,
207+
HTTP_STATUS_CODE: 200,
204208
HTTP_REQUEST_METHOD: "GET",
205209
URL_FULL: self.URL,
206210
HTTP_RESPONSE_STATUS_CODE: 200,
@@ -260,9 +264,7 @@ def test_not_foundbasic(self):
260264

261265
span = self.assert_span()
262266

263-
self.assertEqual(
264-
span.attributes.get(SpanAttributes.HTTP_STATUS_CODE), 404
265-
)
267+
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)
266268

267269
self.assertIs(
268270
span.status.status_code,
@@ -310,9 +312,7 @@ def test_not_foundbasic_both_semconv(self):
310312

311313
span = self.assert_span()
312314

313-
self.assertEqual(
314-
span.attributes.get(SpanAttributes.HTTP_STATUS_CODE), 404
315-
)
315+
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)
316316
self.assertEqual(span.attributes.get(HTTP_RESPONSE_STATUS_CODE), 404)
317317

318318
self.assertIs(
@@ -337,8 +337,8 @@ def test_response_code_none(self):
337337
self.assertEqual(
338338
span.attributes,
339339
{
340-
SpanAttributes.HTTP_METHOD: "GET",
341-
SpanAttributes.HTTP_URL: self.URL,
340+
HTTP_METHOD: "GET",
341+
HTTP_URL: self.URL,
342342
},
343343
)
344344

@@ -455,9 +455,9 @@ def test_requests_exception_with_response(self, *_, **__):
455455
self.assertEqual(
456456
dict(span.attributes),
457457
{
458-
SpanAttributes.HTTP_METHOD: "GET",
459-
SpanAttributes.HTTP_URL: "http://mock/status/500",
460-
SpanAttributes.HTTP_STATUS_CODE: 500,
458+
HTTP_METHOD: "GET",
459+
HTTP_URL: "http://mock/status/500",
460+
HTTP_STATUS_CODE: 500,
461461
},
462462
)
463463
self.assertEqual(span.status.status_code, StatusCode.ERROR)
@@ -486,9 +486,9 @@ def test_requests_exception_with_response_both_semconv(self, *_, **__):
486486
self.assertEqual(
487487
dict(span.attributes),
488488
{
489-
SpanAttributes.HTTP_METHOD: "GET",
490-
SpanAttributes.HTTP_URL: "http://mock/status/500",
491-
SpanAttributes.HTTP_STATUS_CODE: 500,
489+
HTTP_METHOD: "GET",
490+
HTTP_URL: "http://mock/status/500",
491+
HTTP_STATUS_CODE: 500,
492492
HTTP_REQUEST_METHOD: "GET",
493493
URL_FULL: "http://mock/status/500",
494494
HTTP_RESPONSE_STATUS_CODE: 500,
@@ -520,7 +520,7 @@ def test_remove_sensitive_params(self):
520520

521521
span = self.assert_span()
522522
self.assertEqual(
523-
span.attributes[SpanAttributes.HTTP_URL],
523+
span.attributes[HTTP_URL],
524524
"http://REDACTED:REDACTED@mock/status/200",
525525
)
526526

0 commit comments

Comments
 (0)