Skip to content

Commit

Permalink
Implemented username and pw check on urllib
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryo Kather committed Jun 7, 2021
1 parent b2dd4b8 commit 2e8e14f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import functools
import types
from typing import Collection
import yarl
from urllib.request import ( # pylint: disable=no-name-in-module,import-error
OpenerDirector,
Request,
Expand Down Expand Up @@ -144,7 +145,7 @@ def _instrumented_open_call(

labels = {
SpanAttributes.HTTP_METHOD: method,
SpanAttributes.HTTP_URL: url,
SpanAttributes.HTTP_URL: str(yarl.URL(url).with_user(None)),
}

with tracer.start_as_current_span(
Expand All @@ -153,7 +154,7 @@ def _instrumented_open_call(
exception = None
if span.is_recording():
span.set_attribute(SpanAttributes.HTTP_METHOD, method)
span.set_attribute(SpanAttributes.HTTP_URL, url)
span.set_attribute(SpanAttributes.HTTP_URL, str(yarl.URL(url).with_user(None)))

headers = get_or_create_headers()
inject(headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ def test_requests_timeout_exception(self, *_, **__):
span = self.assert_span()
self.assertEqual(span.status.status_code, StatusCode.ERROR)

def test_credentials_url(self):
url = "http://username:password@httpbin.org/status/200"

with self.assertRaises(Exception):
self.perform_request(url)

span = self.assert_span()
print(span.attributes)
self.assertEqual(span.attributes[SpanAttributes.HTTP_URL], self.URL)

class TestRequestsIntegration(RequestsIntegrationTestBase, TestBase):
@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ commands_pre =

flask: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-flask[test]

urllib: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib[test]
urllib: pip install yarl {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib[test]

urllib3: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib3[test]

Expand Down

0 comments on commit 2e8e14f

Please sign in to comment.