@@ -104,110 +104,161 @@ def test_create_telemetry_item(self, mock_ns_to_iso_str):
104104 )
105105 self .assertEqual (result , expected )
106106
107- # Unknown
107+ # Unknown SDK Version Prefix
108108
109- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
109+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
110110 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
111111 def test_get_sdk_version_prefix (self , mock_system , mock_getenv ):
112112 result = _utils ._get_sdk_version_prefix ()
113113 self .assertEqual (result , "uum_" )
114114
115- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
115+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
116116 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
117117 def test_get_sdk_version_prefix_linux (self , mock_system , mock_getenv ):
118118 result = _utils ._get_sdk_version_prefix ()
119119 self .assertEqual (result , "ulm_" )
120120
121- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
121+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
122122 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
123123 def test_get_sdk_version_prefix_windows (self , mock_system , mock_getenv ):
124124 result = _utils ._get_sdk_version_prefix ()
125125 self .assertEqual (result , "uwm_" )
126126
127- # App Service
127+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled" , return_value = True )
128+ @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
129+ def test_get_sdk_version_prefix_attach (self , mock_system , mock_getenv ):
130+ result = _utils ._get_sdk_version_prefix ()
131+ self .assertEqual (result , "uui_" )
132+
133+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled" , return_value = True )
134+ @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
135+ def test_get_sdk_version_prefix_attach_linux (self , mock_system , mock_getenv ):
136+ result = _utils ._get_sdk_version_prefix ()
137+ self .assertEqual (result , "uli_" )
138+
139+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled" , return_value = True )
140+ @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
141+ def test_get_sdk_version_prefix_attach_windows (self , mock_system , mock_getenv ):
142+ result = _utils ._get_sdk_version_prefix ()
143+ self .assertEqual (result , "uwi_" )
144+
145+ # App Service SDK Version Prefix
128146
129- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
147+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME }, clear = True )
130148 @patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = False )
131149 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
132150 def test_get_sdk_version_prefix_app_service (self , mock_system , mock_getenv ):
133151 result = _utils ._get_sdk_version_prefix ()
134152 self .assertEqual (result , "aum_" )
135153
136- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
154+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME }, clear = True )
137155 @patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = False )
138156 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
139157 def test_get_sdk_version_prefix_app_service_linux (self , mock_system , mock_getenv ):
140158 result = _utils ._get_sdk_version_prefix ()
141159 self .assertEqual (result , "alm_" )
142160
143- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
161+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME }, clear = True )
144162 @patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = False )
145163 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
146164 def test_get_sdk_version_prefix_app_service_windows (self , mock_system , mock_getenv ):
147165 result = _utils ._get_sdk_version_prefix ()
148166 self .assertEqual (result , "awm_" )
149167
150- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
168+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME }, clear = True )
151169 @patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = True )
152170 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
153171 def test_get_sdk_version_prefix_app_service_attach (self , mock_system , mock_getenv ):
154172 result = _utils ._get_sdk_version_prefix ()
155173 self .assertEqual (result , "aui_" )
156174
157- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
175+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME }, clear = True )
158176 @patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = True )
159177 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
160178 def test_get_sdk_version_prefix_app_service_linux_attach (self , mock_system , mock_getenv ):
161179 result = _utils ._get_sdk_version_prefix ()
162180 self .assertEqual (result , "ali_" )
163181
164- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
182+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME }, clear = True )
165183 @patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = True )
166184 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
167185 def test_get_sdk_version_prefix_app_service_windows_attach (self , mock_system , mock_getenv ):
168186 result = _utils ._get_sdk_version_prefix ()
169187 self .assertEqual (result , "awi_" )
170188
171- # Function
189+ # Function SDK Version Prefix
172190
173- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME })
174- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
191+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME }, clear = True )
192+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
175193 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
176194 def test_get_sdk_version_prefix_function (self , mock_system , mock_getenv ):
177195 result = _utils ._get_sdk_version_prefix ()
178196 self .assertEqual (result , "fum_" )
179197
180- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME })
181- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
198+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME }, clear = True )
199+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
182200 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
183201 def test_get_sdk_version_prefix_function_linux (self , mock_system , mock_getenv ):
184202 result = _utils ._get_sdk_version_prefix ()
185203 self .assertEqual (result , "flm_" )
186204
187- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME })
188- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
205+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME }, clear = True )
206+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
189207 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
190208 def test_get_sdk_version_prefix_function_windows (self , mock_system , mock_getenv ):
191209 result = _utils ._get_sdk_version_prefix ()
192210 self .assertEqual (result , "fwm_" )
193211
194- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME })
195- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = True )
212+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME }, clear = True )
213+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = True )
196214 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
197215 def test_get_sdk_version_prefix_function_attach (self , mock_system , mock_getenv ):
198216 result = _utils ._get_sdk_version_prefix ()
199217 self .assertEqual (result , "fui_" )
200218
201- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME })
202- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = True )
219+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME }, clear = True )
220+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = True )
203221 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
204222 def test_get_sdk_version_prefix_function_linux_attach (self , mock_system , mock_getenv ):
205223 result = _utils ._get_sdk_version_prefix ()
206224 self .assertEqual (result , "fli_" )
207225
208- @patch ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME })
209- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = True )
226+ @patch . dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"FUNCTIONS_WORKER_RUNTIME" : TEST_WEBSITE_SITE_NAME }, clear = True )
227+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = True )
210228 @patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
211229 def test_get_sdk_version_prefix_function_windows_attach (self , mock_system , mock_getenv ):
212230 result = _utils ._get_sdk_version_prefix ()
213231 self .assertEqual (result , "fwi_" )
232+
233+ # Attach
234+
235+ @patch (
236+ "azure.monitor.opentelemetry.exporter._utils.isdir" ,
237+ return_value = True ,
238+ )
239+ @patch .dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
240+ def test_attach_enabled (self , mock_isdir ):
241+ self .assertEqual (
242+ _utils ._is_attach_enabled (), True
243+ )
244+
245+ @patch (
246+ "azure.monitor.opentelemetry.exporter._utils.isdir" ,
247+ return_value = False ,
248+ )
249+ @patch .dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {"WEBSITE_SITE_NAME" : TEST_WEBSITE_SITE_NAME })
250+ def test_attach_app_service_disabled (self , mock_isdir ):
251+ self .assertEqual (
252+ _utils ._is_attach_enabled (), False
253+ )
254+
255+ @patch (
256+ "azure.monitor.opentelemetry.exporter._utils.isdir" ,
257+ return_value = True ,
258+ )
259+ @patch .dict ("azure.monitor.opentelemetry.exporter._utils.environ" , {}, clear = True )
260+ def test_attach_off_app_service_with_agent (self , mock_isdir ):
261+ # This is not an expected scenario and just tests the default
262+ self .assertEqual (
263+ _utils ._is_attach_enabled (), False
264+ )
0 commit comments