22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information
44
5+ using System . Diagnostics ;
56using System . IO . Abstractions . TestingHelpers ;
67using Amazon . S3 ;
78using Amazon . S3 . Model ;
1112using Elastic . Documentation . Configuration ;
1213using Elastic . Documentation . Configuration . Assembler ;
1314using Elastic . Documentation . Diagnostics ;
15+ using Elastic . Documentation . ServiceDefaults . Telemetry ;
1416using FakeItEasy ;
1517using FluentAssertions ;
1618using Microsoft . Extensions . Logging ;
19+ using OpenTelemetry ;
20+ using OpenTelemetry . Trace ;
1721
1822namespace Elastic . Assembler . IntegrationTests ;
1923
@@ -268,12 +272,20 @@ public async Task TestApply()
268272 {
269273 transferredFiles = fileSystem . Directory . GetFiles ( request . Directory , request . SearchPattern , request . SearchOption ) ;
270274 } ) ;
275+
276+ // Configure OpenTelemetry to capture telemetry
277+ var exportedActivities = new List < Activity > ( ) ;
278+ using var tracerProvider = Sdk . CreateTracerProviderBuilder ( )
279+ . AddSource ( TelemetryConstants . AssemblerSyncInstrumentationName )
280+ . AddInMemoryExporter ( exportedActivities )
281+ . Build ( ) ;
282+
271283 var applier = new AwsS3SyncApplyStrategy ( new LoggerFactory ( ) , moxS3Client , moxTransferUtility , "fake" , context , collector ) ;
272284
273285 // Act
274286 await applier . Apply ( plan , Cancel . None ) ;
275287
276- // Assert
288+ // Assert - File operations
277289 transferredFiles . Length . Should ( ) . Be ( 4 ) ; // 3 add requests + 1 update request
278290 transferredFiles . Should ( ) . NotContain ( "docs/skip.md" ) ;
279291
@@ -282,5 +294,18 @@ public async Task TestApply()
282294
283295 A . CallTo ( ( ) => moxTransferUtility . UploadDirectoryAsync ( A < TransferUtilityUploadDirectoryRequest > . _ , A < Cancel > . _ ) )
284296 . MustHaveHappenedOnceExactly ( ) ;
297+
298+ // Assert - Telemetry spans are created
299+ exportedActivities . Should ( ) . Contain ( a => a . DisplayName == "sync apply" ) ;
300+ exportedActivities . Should ( ) . Contain ( a => a . DisplayName == "upload files" ) ;
301+ exportedActivities . Should ( ) . Contain ( a => a . DisplayName == "delete files" ) ;
302+
303+ // Assert - Telemetry tags contain correct aggregate counts
304+ var syncActivity = exportedActivities . First ( a => a . DisplayName == "sync apply" ) ;
305+ var tagObjects = syncActivity . TagObjects . ToList ( ) ;
306+ tagObjects . Should ( ) . Contain ( t => t . Key == "docs.sync.files.added" && Convert . ToInt64 ( t . Value , System . Globalization . CultureInfo . InvariantCulture ) == 3 ) ;
307+ tagObjects . Should ( ) . Contain ( t => t . Key == "docs.sync.files.updated" && Convert . ToInt64 ( t . Value , System . Globalization . CultureInfo . InvariantCulture ) == 1 ) ;
308+ tagObjects . Should ( ) . Contain ( t => t . Key == "docs.sync.files.deleted" && Convert . ToInt64 ( t . Value , System . Globalization . CultureInfo . InvariantCulture ) == 1 ) ;
309+ tagObjects . Should ( ) . Contain ( t => t . Key == "docs.sync.files.total" && Convert . ToInt64 ( t . Value , System . Globalization . CultureInfo . InvariantCulture ) == 5 ) ;
285310 }
286311}
0 commit comments