@@ -278,6 +278,13 @@ public IsolatedRuntimeV4(ITestOutputHelper output)
278278 [ Trait ( "RunOnWindows" , "True" ) ]
279279 public async Task SubmitsTraces ( )
280280 {
281+ // by default host logs are enabled e.g.,
282+ // DD_LOGS_DIRECT_SUBMISSION_AZURE_FUNCTIONS_HOST_ENABLED=true
283+ // but we do just want a lot of logging, so still bump up the level to VERBOSE
284+ SetEnvironmentVariable ( "DD_LOGS_DIRECT_SUBMISSION_MINIMUM_LEVEL" , "VERBOSE" ) ;
285+ var hostName = "integration_ilogger_az_tests" ;
286+ using var logsIntake = new MockLogsIntake ( ) ;
287+ EnableDirectLogSubmission ( logsIntake . Port , nameof ( IntegrationId . ILogger ) , hostName ) ;
281288 using var agent = EnvironmentHelper . GetMockAgent ( useTelemetry : true ) ;
282289 using ( await RunAzureFunctionAndWaitForExit ( agent , expectedExitCode : - 1 ) )
283290 {
@@ -286,10 +293,61 @@ public async Task SubmitsTraces()
286293 var filteredSpans = spans . Where ( s => ! s . Resource . Equals ( "Timer ExitApp" , StringComparison . OrdinalIgnoreCase ) ) . ToImmutableList ( ) ;
287294
288295 using var s = new AssertionScope ( ) ;
289-
290296 await AssertIsolatedSpans ( filteredSpans ) ;
291297
292298 filteredSpans . Count . Should ( ) . Be ( expectedSpanCount ) ;
299+
300+ var logs = logsIntake . Logs ;
301+
302+ // ~327 (ish) logs but we kill func.exe so some logs are lost
303+ // and since sometimes the batch of logs can be 100+ it can be a LOT of logs that we lose
304+ // so just check that we have more than the 13 that we get when host logs are disabled
305+ logs . Should ( ) . HaveCountGreaterThanOrEqualTo ( 200 ) ;
306+ }
307+ }
308+ }
309+
310+ // The reason why we have a separate application here is because we run into a Singleton locking issue when
311+ // we re-run the same function application in the same test session.
312+ // I couldn't find a way to reset the state between test runs, so the easiest solution was to
313+ // just create a separate function app.
314+ [ UsesVerify ]
315+ [ Collection ( nameof ( AzureFunctionsTestsCollection ) ) ]
316+ public class IsolatedRuntimeV4HostLogsDisabled : AzureFunctionsTests
317+ {
318+ public IsolatedRuntimeV4HostLogsDisabled ( ITestOutputHelper output )
319+ : base ( "AzureFunctions.V4Isolated.HostLogsDisabled" , output )
320+ {
321+ SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , "dotnet-isolated" ) ;
322+ SetEnvironmentVariable ( "FUNCTIONS_EXTENSION_VERSION" , "~4" ) ;
323+ }
324+
325+ [ SkippableFact ]
326+ [ Trait ( "Category" , "EndToEnd" ) ]
327+ [ Trait ( "Category" , "AzureFunctions" ) ]
328+ [ Trait ( "RunOnWindows" , "True" ) ]
329+ public async Task SubmitsTraces ( )
330+ {
331+ SetEnvironmentVariable ( "DD_LOGS_DIRECT_SUBMISSION_AZURE_FUNCTIONS_HOST_ENABLED" , "false" ) ;
332+ SetEnvironmentVariable ( "DD_LOGS_DIRECT_SUBMISSION_MINIMUM_LEVEL" , "VERBOSE" ) ;
333+ var hostName = "integration_ilogger_az_tests" ;
334+ using var logsIntake = new MockLogsIntake ( ) ;
335+ EnableDirectLogSubmission ( logsIntake . Port , nameof ( IntegrationId . ILogger ) , hostName ) ;
336+
337+ using var agent = EnvironmentHelper . GetMockAgent ( useTelemetry : true ) ;
338+ using ( await RunAzureFunctionAndWaitForExit ( agent , expectedExitCode : - 1 ) )
339+ {
340+ const int expectedSpanCount = 21 ;
341+ var spans = await agent . WaitForSpansAsync ( expectedSpanCount ) ;
342+
343+ var filteredSpans = spans . Where ( s => ! s . Resource . Equals ( "Timer ExitApp" , StringComparison . OrdinalIgnoreCase ) ) . ToImmutableList ( ) ;
344+
345+ await AssertIsolatedSpans ( filteredSpans , filename : $ "{ nameof ( AzureFunctionsTests ) } .Isolated.V4.HostLogsDisabled") ;
346+ filteredSpans . Count . Should ( ) . Be ( expectedSpanCount ) ;
347+
348+ var logs = logsIntake . Logs ;
349+ // we expect some logs still from the worker process
350+ logs . Should ( ) . HaveCount ( 13 ) ;
293351 }
294352 }
295353 }
@@ -325,6 +383,8 @@ public async Task SubmitsTraces()
325383 // value so they may be removed from being traced.
326384 var filteredSpans = FilterOutSocketsHttpHandler ( spans ) ;
327385
386+ filteredSpans = filteredSpans . Where ( s => ! s . Resource . Equals ( "Timer ExitApp" , StringComparison . OrdinalIgnoreCase ) ) . ToImmutableList ( ) ;
387+
328388 using var s = new AssertionScope ( ) ;
329389
330390 await AssertIsolatedSpans ( filteredSpans . ToImmutableList ( ) , $ "{ nameof ( AzureFunctionsTests ) } .Isolated.V4.AspNetCore") ;
0 commit comments