File tree 2 files changed +12
-0
lines changed
instrumentation/opentelemetry-instrumentation-wsgi
src/opentelemetry/instrumentation/wsgi
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,10 @@ def collect_request_attributes(environ):
117
117
if remote_host and remote_host != remote_addr :
118
118
result ["net.peer.name" ] = remote_host
119
119
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
+
120
124
setifnotnone (result , "net.peer.port" , environ .get ("REMOTE_PORT" ))
121
125
flavor = environ .get ("SERVER_PROTOCOL" , "" )
122
126
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):
313
313
expected .items (),
314
314
)
315
315
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
+
316
324
def test_response_attributes (self ):
317
325
otel_wsgi .add_response_attributes (self .span , "404 Not Found" , {})
318
326
expected = (
You can’t perform that action at this time.
0 commit comments