Skip to content
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 @@ -117,6 +117,10 @@ def collect_request_attributes(environ):
if remote_host and remote_host != remote_addr:
result["net.peer.name"] = remote_host

user_agent = environ.get("HTTP_USER_AGENT")
if user_agent is not None and len(user_agent) > 0:
result["http.user_agent"] = user_agent

setifnotnone(result, "net.peer.port", environ.get("REMOTE_PORT"))
flavor = environ.get("SERVER_PROTOCOL", "")
if flavor.upper().startswith(_HTTP_VERSION_PREFIX):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ def test_request_attributes_with_full_request_uri(self):
expected.items(),
)

def test_http_user_agent_attribute(self):
self.environ["HTTP_USER_AGENT"] = "test-useragent"
expected = {"http.user_agent": "test-useragent"}
self.assertGreaterEqual(
otel_wsgi.collect_request_attributes(self.environ).items(),
expected.items(),
)

def test_response_attributes(self):
otel_wsgi.add_response_attributes(self.span, "404 Not Found", {})
expected = (
Expand Down