@@ -225,6 +225,103 @@ public void ActivityNameIsUsedByDefaultForRequestOperationName()
225
225
Assert . Equal ( "displayname" , telemetryItem . Tags [ ContextTagKeys . AiOperationName . ToString ( ) ] ) ;
226
226
}
227
227
228
+ [ Fact ]
229
+ public void AiLocationIpisSetAsHttpClientIpforHttpServerSpans ( )
230
+ {
231
+ using ActivitySource activitySource = new ActivitySource ( ActivitySourceName ) ;
232
+ using var activity = activitySource . StartActivity (
233
+ ActivityName ,
234
+ ActivityKind . Server ,
235
+ null ,
236
+ startTime : DateTime . UtcNow ) ;
237
+ var resource = CreateTestResource ( ) ;
238
+
239
+ activity . SetTag ( SemanticConventions . AttributeHttpClientIP , "127.0.0.1" ) ;
240
+
241
+ var monitorTags = AzureMonitorConverter . EnumerateActivityTags ( activity ) ;
242
+
243
+ var telemetryItem = TelemetryPartA . GetTelemetryItem ( activity , ref monitorTags , resource , null ) ;
244
+
245
+ Assert . Equal ( "127.0.0.1" , telemetryItem . Tags [ ContextTagKeys . AiLocationIp . ToString ( ) ] ) ;
246
+ }
247
+
248
+ [ Fact ]
249
+ public void AiLocationIpisSetAsNetPeerIpForServerSpans ( )
250
+ {
251
+ using ActivitySource activitySource = new ActivitySource ( ActivitySourceName ) ;
252
+ using var activity = activitySource . StartActivity (
253
+ ActivityName ,
254
+ ActivityKind . Server ,
255
+ null ,
256
+ startTime : DateTime . UtcNow ) ;
257
+ var resource = CreateTestResource ( ) ;
258
+
259
+ activity . SetTag ( SemanticConventions . AttributeNetPeerIp , "127.0.0.1" ) ;
260
+
261
+ var monitorTags = AzureMonitorConverter . EnumerateActivityTags ( activity ) ;
262
+
263
+ var telemetryItem = TelemetryPartA . GetTelemetryItem ( activity , ref monitorTags , resource , null ) ;
264
+
265
+ Assert . Equal ( "127.0.0.1" , telemetryItem . Tags [ ContextTagKeys . AiLocationIp . ToString ( ) ] ) ;
266
+ }
267
+
268
+ [ Fact ]
269
+ public void AiUserAgentisSetAsHttpUserAgent ( )
270
+ {
271
+ using ActivitySource activitySource = new ActivitySource ( ActivitySourceName ) ;
272
+ using var activity = activitySource . StartActivity (
273
+ ActivityName ,
274
+ ActivityKind . Server ,
275
+ null ,
276
+ startTime : DateTime . UtcNow ) ;
277
+ var resource = CreateTestResource ( ) ;
278
+
279
+ var userAgent = "Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 91.0.4472.101 Safari / 537.36" ;
280
+ activity . SetTag ( SemanticConventions . AttributeHttpUserAgent , userAgent ) ;
281
+
282
+ var monitorTags = AzureMonitorConverter . EnumerateActivityTags ( activity ) ;
283
+
284
+ var telemetryItem = TelemetryPartA . GetTelemetryItem ( activity , ref monitorTags , resource , null ) ;
285
+
286
+ Assert . Equal ( userAgent , telemetryItem . Tags [ "ai.user.userAgent" ] ) ;
287
+ }
288
+
289
+ [ Fact ]
290
+ public void AiLocationIpIsNullByDefault ( )
291
+ {
292
+ using ActivitySource activitySource = new ActivitySource ( ActivitySourceName ) ;
293
+ using var activity = activitySource . StartActivity (
294
+ ActivityName ,
295
+ ActivityKind . Server ,
296
+ null ,
297
+ startTime : DateTime . UtcNow ) ;
298
+ var resource = CreateTestResource ( ) ;
299
+
300
+ var monitorTags = AzureMonitorConverter . EnumerateActivityTags ( activity ) ;
301
+
302
+ var telemetryItem = TelemetryPartA . GetTelemetryItem ( activity , ref monitorTags , resource , null ) ;
303
+
304
+ Assert . Null ( telemetryItem . Tags [ ContextTagKeys . AiLocationIp . ToString ( ) ] ) ;
305
+ }
306
+
307
+ [ Fact ]
308
+ public void AiUserAgentIsNullByDefault ( )
309
+ {
310
+ using ActivitySource activitySource = new ActivitySource ( ActivitySourceName ) ;
311
+ using var activity = activitySource . StartActivity (
312
+ ActivityName ,
313
+ ActivityKind . Server ,
314
+ null ,
315
+ startTime : DateTime . UtcNow ) ;
316
+ var resource = CreateTestResource ( ) ;
317
+
318
+ var monitorTags = AzureMonitorConverter . EnumerateActivityTags ( activity ) ;
319
+
320
+ var telemetryItem = TelemetryPartA . GetTelemetryItem ( activity , ref monitorTags , resource , null ) ;
321
+
322
+ Assert . Null ( telemetryItem . Tags [ "ai.user.userAgent" ] ) ;
323
+ }
324
+
228
325
/// <summary>
229
326
/// If SERVICE.NAME is not defined, it will fall-back to "unknown_service".
230
327
/// (https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#semantic-attributes-with-sdk-provided-default-value).
0 commit comments