@@ -104,110 +104,161 @@ def test_create_telemetry_item(self, mock_ns_to_iso_str):
104
104
)
105
105
self .assertEqual (result , expected )
106
106
107
- # Unknown
107
+ # Unknown SDK Version Prefix
108
108
109
- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
109
+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
110
110
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
111
111
def test_get_sdk_version_prefix (self , mock_system , mock_getenv ):
112
112
result = _utils ._get_sdk_version_prefix ()
113
113
self .assertEqual (result , "uum_" )
114
114
115
- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
115
+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
116
116
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
117
117
def test_get_sdk_version_prefix_linux (self , mock_system , mock_getenv ):
118
118
result = _utils ._get_sdk_version_prefix ()
119
119
self .assertEqual (result , "ulm_" )
120
120
121
- @patch ("azure.monitor.opentelemetry.exporter._utils.isdir " , return_value = False )
121
+ @patch ("azure.monitor.opentelemetry.exporter._utils._is_attach_enabled " , return_value = False )
122
122
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
123
123
def test_get_sdk_version_prefix_windows (self , mock_system , mock_getenv ):
124
124
result = _utils ._get_sdk_version_prefix ()
125
125
self .assertEqual (result , "uwm_" )
126
126
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
128
146
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 )
130
148
@patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = False )
131
149
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
132
150
def test_get_sdk_version_prefix_app_service (self , mock_system , mock_getenv ):
133
151
result = _utils ._get_sdk_version_prefix ()
134
152
self .assertEqual (result , "aum_" )
135
153
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 )
137
155
@patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = False )
138
156
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
139
157
def test_get_sdk_version_prefix_app_service_linux (self , mock_system , mock_getenv ):
140
158
result = _utils ._get_sdk_version_prefix ()
141
159
self .assertEqual (result , "alm_" )
142
160
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 )
144
162
@patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = False )
145
163
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
146
164
def test_get_sdk_version_prefix_app_service_windows (self , mock_system , mock_getenv ):
147
165
result = _utils ._get_sdk_version_prefix ()
148
166
self .assertEqual (result , "awm_" )
149
167
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 )
151
169
@patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = True )
152
170
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
153
171
def test_get_sdk_version_prefix_app_service_attach (self , mock_system , mock_getenv ):
154
172
result = _utils ._get_sdk_version_prefix ()
155
173
self .assertEqual (result , "aui_" )
156
174
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 )
158
176
@patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = True )
159
177
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
160
178
def test_get_sdk_version_prefix_app_service_linux_attach (self , mock_system , mock_getenv ):
161
179
result = _utils ._get_sdk_version_prefix ()
162
180
self .assertEqual (result , "ali_" )
163
181
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 )
165
183
@patch ("azure.monitor.opentelemetry.exporter._utils.isdir" , return_value = True )
166
184
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
167
185
def test_get_sdk_version_prefix_app_service_windows_attach (self , mock_system , mock_getenv ):
168
186
result = _utils ._get_sdk_version_prefix ()
169
187
self .assertEqual (result , "awi_" )
170
188
171
- # Function
189
+ # Function SDK Version Prefix
172
190
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 )
175
193
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
176
194
def test_get_sdk_version_prefix_function (self , mock_system , mock_getenv ):
177
195
result = _utils ._get_sdk_version_prefix ()
178
196
self .assertEqual (result , "fum_" )
179
197
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 )
182
200
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
183
201
def test_get_sdk_version_prefix_function_linux (self , mock_system , mock_getenv ):
184
202
result = _utils ._get_sdk_version_prefix ()
185
203
self .assertEqual (result , "flm_" )
186
204
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 )
189
207
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
190
208
def test_get_sdk_version_prefix_function_windows (self , mock_system , mock_getenv ):
191
209
result = _utils ._get_sdk_version_prefix ()
192
210
self .assertEqual (result , "fwm_" )
193
211
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 )
196
214
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "" )
197
215
def test_get_sdk_version_prefix_function_attach (self , mock_system , mock_getenv ):
198
216
result = _utils ._get_sdk_version_prefix ()
199
217
self .assertEqual (result , "fui_" )
200
218
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 )
203
221
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Linux" )
204
222
def test_get_sdk_version_prefix_function_linux_attach (self , mock_system , mock_getenv ):
205
223
result = _utils ._get_sdk_version_prefix ()
206
224
self .assertEqual (result , "fli_" )
207
225
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 )
210
228
@patch ("azure.monitor.opentelemetry.exporter._utils.platform.system" , return_value = "Windows" )
211
229
def test_get_sdk_version_prefix_function_windows_attach (self , mock_system , mock_getenv ):
212
230
result = _utils ._get_sdk_version_prefix ()
213
231
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