Skip to content

Commit

Permalink
Formatting changes for fixing lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh Goel committed Feb 17, 2022
1 parent 17807d4 commit e864f36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from urllib.parse import urlparse, urlunparse


OTEL_PYTHON_CAPTURE_REQUEST_HEADERS = 'OTEL_PYTHON_CAPTURE_REQUEST_HEADERS'
OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS = 'OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS'
OTEL_PYTHON_CAPTURE_REQUEST_HEADERS = "OTEL_PYTHON_CAPTURE_REQUEST_HEADERS"
OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS = "OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS"


class ExcludeList:
Expand Down Expand Up @@ -105,11 +105,15 @@ def remove_url_credentials(url: str) -> str:


def normalise_request_header_name(header):
return 'http.request.header.{key}'.format(key=header.lower().replace('-', '_'))
return "http.request.header.{key}".format(
key=header.lower().replace("-", "_")
)


def normalise_response_header_name(header):
return 'http.response.header.{key}'.format(key=header.lower().replace('-', '_'))
return "http.response.header.{key}".format(
key=header.lower().replace("-", "_")
)


def get_custom_headers(env_var):
Expand Down
30 changes: 18 additions & 12 deletions util/opentelemetry-util-http/tests/test_capture_custom_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
normalise_request_header_name,
normalise_response_header_name,
OTEL_PYTHON_CAPTURE_REQUEST_HEADERS,
OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS
OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS,
)


class TestCaptureCustomHeaders(TestBase):
@patch.dict(
"os.environ",
{
OTEL_PYTHON_CAPTURE_REQUEST_HEADERS: "User-Agent,Test-Header"
},
{OTEL_PYTHON_CAPTURE_REQUEST_HEADERS: "User-Agent,Test-Header"},
)
def test_get_custom_request_header(self):
custom_headers_to_capture = get_custom_headers(OTEL_PYTHON_CAPTURE_REQUEST_HEADERS)
assert custom_headers_to_capture == ['User-Agent', 'Test-Header']
custom_headers_to_capture = get_custom_headers(
OTEL_PYTHON_CAPTURE_REQUEST_HEADERS
)
assert custom_headers_to_capture == ["User-Agent", "Test-Header"]

@patch.dict(
"os.environ",
Expand All @@ -42,13 +42,19 @@ def test_get_custom_request_header(self):
},
)
def test_get_custom_response_header(self):
custom_headers_to_capture = get_custom_headers(OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS)
assert custom_headers_to_capture == ['content-type', 'content-length', 'test-header']
custom_headers_to_capture = get_custom_headers(
OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS
)
assert custom_headers_to_capture == [
"content-type",
"content-length",
"test-header",
]

def test_normalise_request_header_name(self):
key = normalise_request_header_name('Test-Header')
assert key == 'http.request.header.test_header'
key = normalise_request_header_name("Test-Header")
assert key == "http.request.header.test_header"

def test_normalise_response_header_name(self):
key = normalise_response_header_name('Test-Header')
assert key == 'http.response.header.test_header'
key = normalise_response_header_name("Test-Header")
assert key == "http.response.header.test_header"

0 comments on commit e864f36

Please sign in to comment.