File tree Expand file tree Collapse file tree
instrumentation/opentelemetry-instrumentation-wsgi
src/opentelemetry/instrumentation/wsgi Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -117,6 +117,10 @@ def collect_request_attributes(environ):
117117 if remote_host and remote_host != remote_addr :
118118 result ["net.peer.name" ] = remote_host
119119
120+ user_agent = environ .get ("HTTP_USER_AGENT" )
121+ if user_agent is not None and len (user_agent ) > 0 :
122+ result ["http.user_agent" ] = user_agent
123+
120124 setifnotnone (result , "net.peer.port" , environ .get ("REMOTE_PORT" ))
121125 flavor = environ .get ("SERVER_PROTOCOL" , "" )
122126 if flavor .upper ().startswith (_HTTP_VERSION_PREFIX ):
Original file line number Diff line number Diff line change @@ -313,6 +313,14 @@ def test_request_attributes_with_full_request_uri(self):
313313 expected .items (),
314314 )
315315
316+ def test_http_user_agent_attribute (self ):
317+ self .environ ["HTTP_USER_AGENT" ] = "test-useragent"
318+ expected = {"http.user_agent" : "test-useragent" }
319+ self .assertGreaterEqual (
320+ otel_wsgi .collect_request_attributes (self .environ ).items (),
321+ expected .items (),
322+ )
323+
316324 def test_response_attributes (self ):
317325 otel_wsgi .add_response_attributes (self .span , "404 Not Found" , {})
318326 expected = (
You can’t perform that action at this time.
0 commit comments