Skip to content

refactor: opentelemetry-instrumentation-urllib #3639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def response_hook(span: Span, request: Request, response: HTTPResponse):
)
from opentelemetry.metrics import Histogram, Meter, get_meter
from opentelemetry.propagate import inject
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_URL,
)
from opentelemetry.semconv._incubating.metrics.http_metrics import (
HTTP_CLIENT_REQUEST_BODY_SIZE,
HTTP_CLIENT_RESPONSE_BODY_SIZE,
Expand All @@ -130,7 +133,6 @@ def response_hook(span: Span, request: Request, response: HTTPResponse):
from opentelemetry.semconv.metrics.http_metrics import (
HTTP_CLIENT_REQUEST_DURATION,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import Span, SpanKind, Tracer, get_tracer
from opentelemetry.util.http import (
ExcludeList,
Expand Down Expand Up @@ -325,7 +327,7 @@ def _instrumented_open_call(
sem_conv_opt_in_mode=_StabilityMode.HTTP,
)

duration_attrs_old[SpanAttributes.HTTP_URL] = url
duration_attrs_old[HTTP_URL] = url

_record_histograms(
histograms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
)
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.sdk import resources
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_METHOD,
HTTP_STATUS_CODE,
HTTP_URL,
)
from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
from opentelemetry.semconv.attributes.http_attributes import (
HTTP_REQUEST_METHOD,
HTTP_RESPONSE_STATUS_CODE,
)
from opentelemetry.semconv.attributes.url_attributes import URL_FULL
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.mock_textmap import MockTextMapPropagator
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import StatusCode
Expand Down Expand Up @@ -150,9 +154,9 @@ def test_basic(self):
self.assertEqual(
span.attributes,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: self.URL,
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_METHOD: "GET",
HTTP_URL: self.URL,
HTTP_STATUS_CODE: 200,
},
)

Expand Down Expand Up @@ -198,9 +202,9 @@ def test_basic_both_semconv(self):
self.assertEqual(
span.attributes,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: self.URL,
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_METHOD: "GET",
HTTP_URL: self.URL,
HTTP_STATUS_CODE: 200,
HTTP_REQUEST_METHOD: "GET",
URL_FULL: self.URL,
HTTP_RESPONSE_STATUS_CODE: 200,
Expand Down Expand Up @@ -260,9 +264,7 @@ def test_not_foundbasic(self):

span = self.assert_span()

self.assertEqual(
span.attributes.get(SpanAttributes.HTTP_STATUS_CODE), 404
)
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)

self.assertIs(
span.status.status_code,
Expand Down Expand Up @@ -310,9 +312,7 @@ def test_not_foundbasic_both_semconv(self):

span = self.assert_span()

self.assertEqual(
span.attributes.get(SpanAttributes.HTTP_STATUS_CODE), 404
)
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)
self.assertEqual(span.attributes.get(HTTP_RESPONSE_STATUS_CODE), 404)

self.assertIs(
Expand All @@ -337,8 +337,8 @@ def test_response_code_none(self):
self.assertEqual(
span.attributes,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: self.URL,
HTTP_METHOD: "GET",
HTTP_URL: self.URL,
},
)

Expand Down Expand Up @@ -455,9 +455,9 @@ def test_requests_exception_with_response(self, *_, **__):
self.assertEqual(
dict(span.attributes),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://mock/status/500",
SpanAttributes.HTTP_STATUS_CODE: 500,
HTTP_METHOD: "GET",
HTTP_URL: "http://mock/status/500",
HTTP_STATUS_CODE: 500,
},
)
self.assertEqual(span.status.status_code, StatusCode.ERROR)
Expand Down Expand Up @@ -486,9 +486,9 @@ def test_requests_exception_with_response_both_semconv(self, *_, **__):
self.assertEqual(
dict(span.attributes),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://mock/status/500",
SpanAttributes.HTTP_STATUS_CODE: 500,
HTTP_METHOD: "GET",
HTTP_URL: "http://mock/status/500",
HTTP_STATUS_CODE: 500,
HTTP_REQUEST_METHOD: "GET",
URL_FULL: "http://mock/status/500",
HTTP_RESPONSE_STATUS_CODE: 500,
Expand Down Expand Up @@ -520,7 +520,7 @@ def test_remove_sensitive_params(self):

span = self.assert_span()
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
span.attributes[HTTP_URL],
"http://REDACTED:REDACTED@mock/status/200",
)

Expand Down