1616import requests
1717
1818from opentelemetry .instrumentation .requests import RequestsInstrumentor
19- from opentelemetry .instrumentation .requests .semconv import (
20- ATTR_USER_AGENT_SYNTHETIC_TYPE ,
21- USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT ,
22- USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST ,
19+ from opentelemetry .semconv ._incubating .attributes .user_agent_attributes import (
20+ USER_AGENT_SYNTHETIC_TYPE ,
21+ UserAgentSyntheticTypeValues ,
2322)
2423from opentelemetry .test .test_base import TestBase
2524
@@ -56,8 +55,8 @@ def test_user_agent_bot_googlebot(self):
5655
5756 span = self .assert_span ()
5857 self .assertEqual (
59- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
60- USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT ,
58+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
59+ UserAgentSyntheticTypeValues . BOT . value ,
6160 )
6261
6362 def test_user_agent_bot_bingbot (self ):
@@ -69,8 +68,8 @@ def test_user_agent_bot_bingbot(self):
6968
7069 span = self .assert_span ()
7170 self .assertEqual (
72- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
73- USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT ,
71+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
72+ UserAgentSyntheticTypeValues . BOT . value ,
7473 )
7574
7675 def test_user_agent_test_alwayson (self ):
@@ -80,8 +79,8 @@ def test_user_agent_test_alwayson(self):
8079
8180 span = self .assert_span ()
8281 self .assertEqual (
83- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
84- USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST ,
82+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
83+ UserAgentSyntheticTypeValues . TEST . value ,
8584 )
8685
8786 def test_user_agent_case_insensitive (self ):
@@ -91,8 +90,8 @@ def test_user_agent_case_insensitive(self):
9190
9291 span = self .assert_span ()
9392 self .assertEqual (
94- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
95- USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT ,
93+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
94+ UserAgentSyntheticTypeValues . BOT . value ,
9695 )
9796
9897 self .memory_exporter .clear ()
@@ -102,8 +101,8 @@ def test_user_agent_case_insensitive(self):
102101
103102 span = self .assert_span ()
104103 self .assertEqual (
105- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
106- USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST ,
104+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
105+ UserAgentSyntheticTypeValues . TEST . value ,
107106 )
108107
109108 def test_user_agent_normal_browser (self ):
@@ -114,22 +113,22 @@ def test_user_agent_normal_browser(self):
114113 requests .get (self .URL , headers = headers , timeout = 5 )
115114
116115 span = self .assert_span ()
117- self .assertNotIn (ATTR_USER_AGENT_SYNTHETIC_TYPE , span .attributes )
116+ self .assertNotIn (USER_AGENT_SYNTHETIC_TYPE , span .attributes )
118117
119118 def test_no_user_agent_header (self ):
120119 """Test that requests without user agent don't get synthetic type"""
121120 requests .get (self .URL , timeout = 5 )
122121
123122 span = self .assert_span ()
124- self .assertNotIn (ATTR_USER_AGENT_SYNTHETIC_TYPE , span .attributes )
123+ self .assertNotIn (USER_AGENT_SYNTHETIC_TYPE , span .attributes )
125124
126125 def test_empty_user_agent_header (self ):
127126 """Test that empty user agent doesn't get synthetic type"""
128127 headers = {"User-Agent" : "" }
129128 requests .get (self .URL , headers = headers , timeout = 5 )
130129
131130 span = self .assert_span ()
132- self .assertNotIn (ATTR_USER_AGENT_SYNTHETIC_TYPE , span .attributes )
131+ self .assertNotIn (USER_AGENT_SYNTHETIC_TYPE , span .attributes )
133132
134133 def test_user_agent_substring_match (self ):
135134 """Test that substrings are detected correctly"""
@@ -139,8 +138,8 @@ def test_user_agent_substring_match(self):
139138
140139 span = self .assert_span ()
141140 self .assertEqual (
142- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
143- USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT ,
141+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
142+ UserAgentSyntheticTypeValues . BOT . value ,
144143 )
145144
146145 self .memory_exporter .clear ()
@@ -151,8 +150,8 @@ def test_user_agent_substring_match(self):
151150
152151 span = self .assert_span ()
153152 self .assertEqual (
154- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
155- USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST ,
153+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
154+ UserAgentSyntheticTypeValues . TEST . value ,
156155 )
157156
158157 def test_user_agent_priority_alwayson_over_bot (self ):
@@ -163,6 +162,6 @@ def test_user_agent_priority_alwayson_over_bot(self):
163162 span = self .assert_span ()
164163 # alwayson should be checked first and return 'test'
165164 self .assertEqual (
166- span .attributes .get (ATTR_USER_AGENT_SYNTHETIC_TYPE ),
167- USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST ,
165+ span .attributes .get (USER_AGENT_SYNTHETIC_TYPE ),
166+ UserAgentSyntheticTypeValues . TEST . value ,
168167 )
0 commit comments